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

Buld version for DWithin


diffs (125 lines):

diff --git a/geom/monetdb5/geom.h b/geom/monetdb5/geom.h
--- a/geom/monetdb5/geom.h
+++ b/geom/monetdb5/geom.h
@@ -162,6 +162,7 @@ geom_export str wkbRelate(bit*, wkb**, w
 geom_export str wkbCovers(bit *out, wkb **geomWKB_a, wkb **geomWKB_b);
 geom_export str wkbCoveredBy(bit *out, wkb **geomWKB_a, wkb **geomWKB_b);
 geom_export str wkbDWithin(bit*, wkb**, wkb**, dbl*);
+geom_export str wkbDWithin_bat(bat *outBAT_id, bat *aBAT_id, bat *bBAT_id, 
dbl*);
 
 //LocateAlong
 //LocateBetween
diff --git a/geom/monetdb5/geom.mal b/geom/monetdb5/geom.mal
--- a/geom/monetdb5/geom.mal
+++ b/geom/monetdb5/geom.mal
@@ -754,6 +754,9 @@ function Translate(g:bat[:wkb], dxBAT:ba
        return x;
 end Translate;
 
+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";
+
 command GeometryN(w:bat[:wkb], n:int) :bat[:wkb] address wkbGeometryN_bat
 comment "Returns the 1-based Nth geometry if the geometry is a 
GEOMETRYCOLLECTION, (MULTI)POINT, (MULTI)LINESTRING, MULTICURVE or 
(MULTI)POLYGON. Otherwise, return NULL";
 command NumGeometries(w:bat[:wkb]) :bat[:int] address wkbNumGeometries_bat
diff --git a/geom/monetdb5/geomBulk.c b/geom/monetdb5/geomBulk.c
--- a/geom/monetdb5/geomBulk.c
+++ b/geom/monetdb5/geomBulk.c
@@ -885,6 +885,97 @@ wkbIntersects_bat(bat *outBAT_id, bat *a
 }
 
 /***************************************************************************/
+/******************* IN: wkb wkb - OUT: bit - flag: dbl ********************/
+/***************************************************************************/
+
+static str
+WKBWKBtoBITflagDBL_bat(bat *outBAT_id, bat *aBAT_id, bat *bBAT_id, double 
*flag, str (*func) (bit *, wkb **, wkb **, dbl*), const char *name)
+{
+       BAT *outBAT = NULL, *aBAT = NULL, *bBAT = NULL;
+       BUN p = 0, q = 0;
+       BATiter aBAT_iter, bBAT_iter;
+       str msg = MAL_SUCCEED;
+#ifdef GEOMBULK_DEBUG
+    static struct timeval start, stop;
+    unsigned long long t;
+#endif
+    bit *outs = NULL;
+
+       //get the descriptor of the BAT
+       if ((aBAT = BATdescriptor(*aBAT_id)) == NULL) {
+               throw(MAL, name, RUNTIME_OBJECT_MISSING);
+       }
+       if ((bBAT = BATdescriptor(*bBAT_id)) == NULL) {
+               BBPunfix(aBAT->batCacheid);
+               throw(MAL, name, RUNTIME_OBJECT_MISSING);
+       }
+
+       //create a new for the output BAT
+       if ((outBAT = COLnew(aBAT->hseqbase, ATOMindex("bit"), BATcount(aBAT), 
TRANSIENT)) == NULL) {
+               BBPunfix(aBAT->batCacheid);
+               BBPunfix(bBAT->batCacheid);
+               throw(MAL, name, MAL_MALLOC_FAIL);
+       }
+
+       //iterator over the input BAT
+       aBAT_iter = bat_iterator(aBAT);
+       bBAT_iter = bat_iterator(bBAT);
+
+    omp_set_dynamic(OPENCL_DYNAMIC);     // Explicitly disable dynamic teams
+    omp_set_num_threads(OPENCL_THREADS);
+
+    q = BUNlast(aBAT);
+#ifdef GEOMBULK_DEBUG
+    fprintf(stdout, "%s %d %d\n", name, p, q);
+    gettimeofday(&start, NULL);
+#endif
+       outs = (bit *) Tloc(outBAT, 0);
+       //BATloop(inBAT, p, q) {        //iterate over all valid elements
+    #pragma omp parallel for
+    for (p = 0; p < q; p++) {
+        wkb *aWKB = NULL, *bWKB = NULL;
+        //bit out;
+        str err = NULL;
+
+        aWKB = (wkb *) BUNtail(aBAT_iter, p);
+        bWKB = (wkb *) BUNtail(bBAT_iter, p);
+        //if ((err = (*func) (&out, &aWKB, &bWKB)) != MAL_SUCCEED) {
+        if ((err = (*func) (&outs[p], &aWKB, &bWKB, flag)) != MAL_SUCCEED) {
+            msg = err;
+            #pragma omp cancelregion
+        }
+        //outs[p] = out;
+        //BUNappend(outBAT, &out, TRUE);       //add the result to the new BAT
+    }
+#ifdef GEOMBULK_DEBUG
+    gettimeofday(&stop, NULL);
+    t = 1000 * (stop.tv_sec - start.tv_sec) + (stop.tv_usec - start.tv_usec) / 
1000;
+    fprintf(stdout, "%s %llu ms\n", name, t);
+#endif
+
+    BBPunfix(aBAT->batCacheid);
+    BBPunfix(bBAT->batCacheid);
+
+    if (msg != MAL_SUCCEED) {
+        BBPunfix(outBAT->batCacheid);
+        return msg;
+    }
+
+    BATsetcount(outBAT, q);
+    BATrmprops(outBAT)
+    BATsettrivprop(outBAT);
+       BBPkeepref(*outBAT_id = outBAT->batCacheid);
+
+       return MAL_SUCCEED;
+}
+
+str
+wkbDWithin_bat(bat *outBAT_id, bat *aBAT_id, bat *bBAT_id, double *distance)
+{
+       return WKBWKBtoBITflagDBL_bat(outBAT_id, aBAT_id, bBAT_id, distance, 
wkbDWithin, "batgeom.wkbDWithin");
+}
+
+/***************************************************************************/
 /************************ IN: wkb wkb - OUT: wkb ***************************/
 /***************************************************************************/
 
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to