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

subselect for Intersects and Within. We have extended the generic function for 
the bulk version of func(geom, geom) to receive a BAT on the left or a value.


diffs (156 lines):

diff --git a/geom/monetdb5/geom.h b/geom/monetdb5/geom.h
--- a/geom/monetdb5/geom.h
+++ b/geom/monetdb5/geom.h
@@ -156,12 +156,12 @@ geom_export str wkbEquals(bit*, wkb**, w
 geom_export str wkbDisjoint(bit*, wkb**, wkb**);
 geom_export str wkbIntersects(bit*, wkb**, wkb**);
 geom_export str wkbIntersectsXYZ(bit*, wkb**, dbl*, dbl*, dbl*, int*);
-geom_export str wkbIntersects_bat(bat *outBAT_id, bat *aBAT_id, bat *bBAT_id);
+geom_export str wkbIntersects_bat(bat *outBAT_id, bat *aBAT_id, bat *bBAT_id, 
wkb **b);
 geom_export str wkbIntersectsXYZ_bat(bat *outBAT_id, bat *inBAT_id, bat 
*inXBAT_id, double *dx, bat *inYBAT_id, double *dy, bat *inZBAT_id, double *dz, 
int* srid);
 geom_export str wkbTouches(bit*, wkb**, wkb**);
 geom_export str wkbCrosses(bit*, wkb**, wkb**);
 geom_export str wkbWithin(bit*, wkb**, wkb**);
-geom_export str wkbWithin_bat(bat *outBAT_id, bat *aBAT_id, bat *bBAT_id);
+geom_export str wkbWithin_bat(bat *outBAT_id, bat *aBAT_id, bat *bBAT_id, wkb 
**b);
 geom_export str wkbContains(bit*, wkb**, wkb**);
 geom_export str wkbContainsXYZ(bit *out, wkb **a, dbl *px, dbl *py, dbl *pz, 
int *srid);
 geom_export str wkbOverlaps(bit*, wkb**, wkb**);
diff --git a/geom/monetdb5/geom.mal b/geom/monetdb5/geom.mal
--- a/geom/monetdb5/geom.mal
+++ b/geom/monetdb5/geom.mal
@@ -771,9 +771,19 @@ function Translate(g:bat[:wkb], dx:dbl, 
        return x;
 end Translate;
 
-command Within(a:bat[:wkb], b:bat[:wkb]) :bat[:bit] address wkbWithin_bat
+command WithinWKB(a:bat[:wkb], b:bat[:wkb], w:wkb) :bat[:bit] address 
wkbWithin_bat
 comment "Returns TRUE if the geometry A is completely inside geometry B";
 
+function Within(a:bat[:wkb], b:bat[:wkb]) :bat[:bit];
+    res := WithinWKB(a, b, 0:dbl);
+    return res;
+end Within;
+
+function Withinsubselect(a:bat[:wkb], b:wkb) :bat[:bit];
+    res := WithinWKB(a, nil:bat, b);
+    return res;
+end Withinsubselect;
+
 command DWithin(a:bat[:wkb], b:bat[:wkb], dst:dbl) :bat[:bit] address 
wkbDWithin_bat
 comment "Returns true if the two geometries are within the specifies distance 
from each other";
 
@@ -966,9 +976,19 @@ end YMaxFromMBR;
 command Area(:bat[:wkb]) :bat[:dbl] address wkbArea_bat
 comment "Returns the area of the surface if it is a polygon or multi-polygon";
 
-command Intersects(a:bat[:wkb], b:bat[:wkb]) :bat[:bit] address 
wkbIntersects_bat
+command IntersectsWKB(a:bat[:wkb], b:bat[:wkb], w:wkb) :bat[:bit] address 
wkbIntersects_bat
 comment "Returns true if these Geometries 'spatially intersect in 2D'";
 
+function Intersects(a:bat[:wkb], b:bat[:wkb]) :bat[:bit];
+    res := wkbIntersectsWKB(a, b, 0:dbl);
+    return res;
+end Intersects;
+
+function Intersects(a:bat[:wkb], w:wkb) :bat[:bit];
+    res := wkbIntersectsWKB(a, nil:bat, w);
+    return res;
+end Intersects;
+
 command Intersects3D(g:bat[:wkb], dxBAT:bat[:dbl], dx:dbl, dyBAT:bat[:dbl], 
dy:dbl, dzBAT:bat[:dbl], dz:dbl, srid:int) :bat[:bit] address 
wkbIntersectsXYZ_bat
 comment "Returns true if these Geometries 'spatially intersect in 2D'";
 
@@ -1007,6 +1027,11 @@ function Intersects(g:bat[:wkb], dxBAT:b
        return x;
 end Intersects;
 
+function Intersectssubselect(g:bat[:wkb], dx:dbl, dy:dbl, dz:dbl, srid:int) 
:bat[:bit];
+       x := Intersects3D(g, nil:bat, dx, nil:bat, dy, nil:bat, dz, srid);
+       return x;
+end Intersectssubselect;
+
 module calc;
 
 command mbr(v:str) :mbr address mbrFromString;
diff --git a/geom/monetdb5/geomBulk.c b/geom/monetdb5/geomBulk.c
--- a/geom/monetdb5/geomBulk.c
+++ b/geom/monetdb5/geomBulk.c
@@ -814,7 +814,7 @@ wkbIsValid_bat(bat *outBAT_id, bat *inBA
 /***************************************************************************/
 
 static str
-WKBWKBtoBIT_bat(bat *outBAT_id, bat *aBAT_id, bat *bBAT_id, str (*func) (bit 
*, wkb **, wkb **), const char *name)
+WKBWKBtoBIT_bat(bat *outBAT_id, bat *aBAT_id, bat *bBAT_id, wkb **b, str 
(*func) (bit *, wkb **, wkb **), const char *name)
 {
        BAT *outBAT = NULL, *aBAT = NULL, *bBAT = NULL;
        BUN p = 0, q = 0;
@@ -830,7 +830,7 @@ WKBWKBtoBIT_bat(bat *outBAT_id, bat *aBA
        if ((aBAT = BATdescriptor(*aBAT_id)) == NULL) {
                throw(MAL, name, RUNTIME_OBJECT_MISSING);
        }
-       if ((bBAT = BATdescriptor(*bBAT_id)) == NULL) {
+       if ((*bBAT_id != bat_nil) && (bBAT = BATdescriptor(*bBAT_id)) == NULL) {
                BBPunfix(aBAT->batCacheid);
                throw(MAL, name, RUNTIME_OBJECT_MISSING);
        }
@@ -838,13 +838,15 @@ WKBWKBtoBIT_bat(bat *outBAT_id, bat *aBA
        //create a new for the output BAT
        if ((outBAT = COLnew(aBAT->hseqbase, ATOMindex("bit"), BATcount(aBAT), 
TRANSIENT)) == NULL) {
                BBPunfix(aBAT->batCacheid);
-               BBPunfix(bBAT->batCacheid);
+        if (*bBAT_id != bat_nil)
+               BBPunfix(bBAT->batCacheid);
                throw(MAL, name, MAL_MALLOC_FAIL);
        }
 
        //iterator over the input BAT
        aBAT_iter = bat_iterator(aBAT);
-       bBAT_iter = bat_iterator(bBAT);
+    if (*bBAT_id != bat_nil)
+           bBAT_iter = bat_iterator(bBAT);
 
     omp_set_dynamic(OPENCL_DYNAMIC);     // Explicitly disable dynamic teams
     omp_set_num_threads(OPENCL_THREADS);
@@ -865,7 +867,10 @@ WKBWKBtoBIT_bat(bat *outBAT_id, bat *aBA
             continue;
 
         aWKB = (wkb *) BUNtail(aBAT_iter, p);
-        bWKB = (wkb *) BUNtail(bBAT_iter, p);
+        if (*bBAT_id != bat_nil)
+            bWKB = (wkb *) BUNtail(bBAT_iter, p);
+        else
+            bWKB = *b;
         //if ((err = (*func) (&out, &aWKB, &bWKB)) != MAL_SUCCEED) {
         if ((err = (*func) (&outs[p], &aWKB, &bWKB)) != MAL_SUCCEED) {
             msg = err;
@@ -881,7 +886,8 @@ WKBWKBtoBIT_bat(bat *outBAT_id, bat *aBA
 #endif
 
     BBPunfix(aBAT->batCacheid);
-    BBPunfix(bBAT->batCacheid);
+    if (*bBAT_id != bat_nil)
+        BBPunfix(bBAT->batCacheid);
 
     if (msg != MAL_SUCCEED) {
         BBPunfix(outBAT->batCacheid);
@@ -897,15 +903,15 @@ WKBWKBtoBIT_bat(bat *outBAT_id, bat *aBA
 }
 
 str
-wkbIntersects_bat(bat *outBAT_id, bat *aBAT_id, bat *bBAT_id)
+wkbIntersects_bat(bat *outBAT_id, bat *aBAT_id, bat *bBAT_id, wkb **b)
 {
-       return WKBWKBtoBIT_bat(outBAT_id, aBAT_id, bBAT_id, wkbIntersects, 
"batgeom.wkbIntersects");
+       return WKBWKBtoBIT_bat(outBAT_id, aBAT_id, bBAT_id, b, wkbIntersects, 
"batgeom.wkbIntersects");
 }
 
 str
-wkbWithin_bat(bat *outBAT_id, bat *aBAT_id, bat *bBAT_id)
+wkbWithin_bat(bat *outBAT_id, bat *aBAT_id, bat *bBAT_id, wkb **b)
 {
-       return WKBWKBtoBIT_bat(outBAT_id, aBAT_id, bBAT_id, wkbWithin, 
"batgeom.wkbWithin");
+       return WKBWKBtoBIT_bat(outBAT_id, aBAT_id, bBAT_id, b, wkbWithin, 
"batgeom.wkbWithin");
 }
 
 /***************************************************************************/
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to