Changeset: 3a4b9b4ea5ec for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=3a4b9b4ea5ec
Modified Files:
        geom/monetdb5/geom.h
        geom/monetdb5/geom.mal
        geom/monetdb5/geomBulk.c
Branch: sfcgal
Log Message:

Intersection bulk operator with candidate list


diffs (146 lines):

diff --git a/geom/monetdb5/geom.h b/geom/monetdb5/geom.h
--- a/geom/monetdb5/geom.h
+++ b/geom/monetdb5/geom.h
@@ -208,6 +208,7 @@ geom_export str wkbLength(dbl *out, wkb 
 geom_export str wkbConvexHull(wkb **out, wkb **geom);
 geom_export str wkbIntersection(wkb **out, wkb **a, wkb **b);
 geom_export str wkbIntersection_bat(bat *outBAT_id, bat *aBAT_id, bat 
*bBAT_id);
+geom_export str wkbIntersection_bat_s(bat *outBAT_id, bat *aBAT_id, bat 
*bBAT_id, bat *saBAT_id, bat *sbBAT_id);
 geom_export str wkbUnion(wkb **out, wkb **a, wkb **b);
 geom_export str wkbUnionAggr(wkb** outWKB, bat* inBAT_id);
 geom_export str wkbDifference(wkb **out, wkb **a, wkb **b);
diff --git a/geom/monetdb5/geom.mal b/geom/monetdb5/geom.mal
--- a/geom/monetdb5/geom.mal
+++ b/geom/monetdb5/geom.mal
@@ -820,9 +820,16 @@ module batgeom;
 command asX3D(geom:bat[:oid,:wkb], maxDecDigits:int, options:int) 
:bat[:oid,:str] address wkbAsX3D_bat
 comment "Returns a Geometry in X3D xml node element format: 
ISO-IEC-19776-1.2-X3DEncodings-XML";
 
+#Bulk functions
+module batgeom;
+
 command Intersection(a:bat[:oid,:wkb], b:bat[:oid,:wkb]) :bat[:oid,:wkb] 
address wkbIntersection_bat
 comment "Returns a geometry that represents the point set intersection of the 
Geometries a, b";
 
+command Intersection(a:bat[:oid,:wkb], b:bat[:oid,:wkb], sa:bat[:oid], 
sb:bat[:oid]) :bat[:oid,:wkb] address wkbIntersection_bat_s
+comment "Returns a geometry that represents the point set intersection of the 
Geometries a, b";
+
+
 #Filter functions and joins
 
 command geom.Intersectssubjoin(l:bat[:oid,:wkb], r:bat[:oid,:wkb], 
sl:bat[:oid], sr:bat[:oid], nil_matches:bit, estimate:lng) 
(lr:bat[:oid],rr:bat[:oid])
diff --git a/geom/monetdb5/geomBulk.c b/geom/monetdb5/geomBulk.c
--- a/geom/monetdb5/geomBulk.c
+++ b/geom/monetdb5/geomBulk.c
@@ -1653,3 +1653,111 @@ wkbIntersection_bat(bat *outBAT_id, bat 
        return MAL_SUCCEED;
 }
 
+/*Bulk version with candidates lists*/
+str
+wkbIntersection_bat_s(bat *outBAT_id, bat *aBAT_id, bat *bBAT_id, bat 
*saBAT_id, bat *sbBAT_id)
+{
+       BAT *outBAT = NULL, *aBAT = NULL, *bBAT = NULL, *saBAT = NULL, *sbBAT = 
NULL;
+       BATiter aBAT_iter, bBAT_iter, saBAT_iter, sbBAT_iter;
+    uint32_t i = 0;
+
+       //get the descriptors of the input BATs
+       if ((aBAT = BATdescriptor(*aBAT_id)) == NULL) {
+               throw(MAL, "batgeom.Intersection", "Problem retrieving BAT");
+       }
+
+       if (!BAThdense(aBAT)) {
+               BBPunfix(aBAT->batCacheid);
+               throw(MAL, "batgeom.Intersection", "The BAT must have dense 
head");
+       }
+
+       if ((bBAT = BATdescriptor(*bBAT_id)) == NULL) {
+               BBPunfix(aBAT->batCacheid);
+               throw(MAL, "batgeom.Intersection", "Problem retrieving BAT");
+       }
+
+       if (!BAThdense(bBAT)) {
+               BBPunfix(aBAT->batCacheid);
+               BBPunfix(bBAT->batCacheid);
+               throw(MAL, "batgeom.Intersection", "The BAT must have dense 
head");
+       }
+
+    if (BATcount(aBAT) != BATcount(bBAT)) {
+               BBPunfix(aBAT->batCacheid);
+               BBPunfix(bBAT->batCacheid);
+               throw(MAL, "batgeom.Intersection", "The BATs should be 
aligned");
+    }
+   
+    if (BATcount(aBAT) != BATcount(bBAT)) {
+               BBPunfix(aBAT->batCacheid);
+               BBPunfix(bBAT->batCacheid);
+               throw(MAL, "batgeom.Intersection", "The BATs should be 
aligned");
+    }
+
+    //Get descriptors of the candidate list BATs
+       if ((saBAT = BATdescriptor(*saBAT_id)) == NULL) {
+               BBPunfix(aBAT->batCacheid);
+               BBPunfix(bBAT->batCacheid);
+               throw(MAL, "batgeom.Intersection", "Problem retrieving BAT");
+       }
+
+       if ((sbBAT = BATdescriptor(*sbBAT_id)) == NULL) {
+               BBPunfix(aBAT->batCacheid);
+               BBPunfix(bBAT->batCacheid);
+               BBPunfix(saBAT->batCacheid);
+               throw(MAL, "batgeom.Intersection", "Problem retrieving BAT");
+       }
+    
+       //create a new BAT for the output
+       if ((outBAT = BATnew(TYPE_void, ATOMindex("wkb"), BATcount(aBAT), 
TRANSIENT)) == NULL) {
+               BBPunfix(aBAT->batCacheid);
+               BBPunfix(bBAT->batCacheid);
+               BBPunfix(saBAT->batCacheid);
+               BBPunfix(sbBAT->batCacheid);
+               throw(MAL, "batgeom.Intersection", "Error creating new BAT");
+       }
+
+       //set the first idx of the output BAT equal to that of the input BAT
+       BATseqbase(outBAT, aBAT->hseqbase);
+
+       //iterator over the BATs
+       aBAT_iter = bat_iterator(aBAT);
+       bBAT_iter = bat_iterator(bBAT);
+       saBAT_iter = bat_iterator(saBAT);
+       sbBAT_iter = bat_iterator(sbBAT);
+
+       for (i = BUNfirst(saBAT); i < BATcount(saBAT); i++) {
+               str err = NULL;
+        oid aOID = 0, bOID = 0;
+               wkb *aWKB = NULL, *bWKB = NULL, *outWKB = NULL;
+
+               aOID = *(oid *) BUNtail(saBAT_iter, i + BUNfirst(saBAT));
+               bOID = *(oid *) BUNtail(sbBAT_iter, i + BUNfirst(sbBAT));
+
+               aWKB = (wkb *) BUNtail(aBAT_iter, aOID);
+               bWKB = (wkb *) BUNtail(bBAT_iter, bOID);
+
+               if ((err = wkbIntersection(&outWKB, &aWKB, &bWKB)) != 
MAL_SUCCEED) {    //set SRID
+                       BBPunfix(aBAT->batCacheid);
+                       BBPunfix(bBAT->batCacheid);
+                       BBPunfix(saBAT->batCacheid);
+                       BBPunfix(sbBAT->batCacheid);
+                       BBPunfix(outBAT->batCacheid);
+                       return err;
+               }
+
+        BUNappend(outBAT, outWKB, TRUE);       //add the point to the new BAT
+        GDKfree(outWKB);
+        outWKB = NULL;
+       }
+
+       BBPunfix(aBAT->batCacheid);
+       BBPunfix(bBAT->batCacheid);
+       BBPunfix(saBAT->batCacheid);
+       BBPunfix(sbBAT->batCacheid);
+
+       BBPkeepref(*outBAT_id = outBAT->batCacheid);
+
+       return MAL_SUCCEED;
+}
+
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to