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

Bulk version for Intersections


diffs (118 lines):

diff --git a/geom/monetdb5/geom.c b/geom/monetdb5/geom.c
--- a/geom/monetdb5/geom.c
+++ b/geom/monetdb5/geom.c
@@ -6613,8 +6613,6 @@ Intersectssubjoin_intern(bat *lres, bat 
        rBAT_iter = bat_iterator(br);
     lo =  BUNfirst(bl);
 
-    printf ("BATcount %d %d\n", (int) BATcount(bl), (int) BATcount(br));
-
     /*Get the Geometry for the inner BAT*/
     rGeometries = (GEOSGeom*) GDKmalloc(sizeof(GEOSGeom) * BATcount(br));
     ro = BUNfirst(br);
diff --git a/geom/monetdb5/geom.h b/geom/monetdb5/geom.h
--- a/geom/monetdb5/geom.h
+++ b/geom/monetdb5/geom.h
@@ -207,6 +207,7 @@ geom_export str wkbDistance(dbl *out, wk
 geom_export str wkbLength(dbl *out, wkb **a);
 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 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,6 +820,9 @@ 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";
 
+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";
+
 #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
@@ -1578,3 +1578,78 @@ wkbAsX3D_bat(bat *outBAT_id, bat *inBAT_
        return MAL_SUCCEED;
 }
 
+str
+wkbIntersection_bat(bat *outBAT_id, bat *aBAT_id, bat *bBAT_id)
+{
+       BAT *outBAT = NULL, *aBAT = NULL, *bBAT = NULL;
+       BATiter aBAT_iter, bBAT_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");
+    }
+    
+       //create a new BAT for the output
+       if ((outBAT = BATnew(TYPE_void, ATOMindex("wkb"), BATcount(aBAT), 
TRANSIENT)) == NULL) {
+               BBPunfix(aBAT->batCacheid);
+               BBPunfix(bBAT->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);
+
+       for (i = BUNfirst(aBAT); i < BATcount(aBAT); i++) {
+               str err = NULL;
+               wkb *aWKB = NULL, *bWKB = NULL, *outWKB = NULL;
+
+               aWKB = (wkb *) BUNtail(aBAT_iter, i + BUNfirst(aBAT));
+               bWKB = (wkb *) BUNtail(bBAT_iter, i + BUNfirst(bBAT));
+
+               if ((err = wkbIntersection(&outWKB, &aWKB, &bWKB)) != 
MAL_SUCCEED) {    //set SRID
+                       BBPunfix(aBAT->batCacheid);
+                       BBPunfix(bBAT->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);
+
+       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