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

ST_Boundary bulk version (I mistakenly considered it to exist in previous 
commit)


diffs (truncated from 517 to 300 lines):

diff --git a/geom/monetdb5/geom.h b/geom/monetdb5/geom.h
--- a/geom/monetdb5/geom.h
+++ b/geom/monetdb5/geom.h
@@ -134,7 +134,8 @@ geom_export str wkbIsEmpty(bit*, wkb**);
 geom_export str wkbIsSimple(bit*, wkb**);
 //Is3D
 //IsMeasured
-geom_export str wkbBoundary(wkb**, wkb**);
+geom_export str wkbBoundary(wkb **outWKB, wkb **inWKB);
+geom_export str wkbBoundary_bat(bat *inBAT_id, bat *outBAT_id);
 
 
 /* Methods for testing spatial relatioships between geometris (OGC) */
diff --git a/geom/monetdb5/geom.mal b/geom/monetdb5/geom.mal
--- a/geom/monetdb5/geom.mal
+++ b/geom/monetdb5/geom.mal
@@ -504,6 +504,8 @@ function AsEWKT(w:bat[:oid,:wkb]) :bat[:
        return x;
 end AsEWKT;
 
+command Boundary(w:bat[:oid,:wkb]) :bat[:oid,:wkb] address wkbBoundary_bat
+comment "Returns the closure of the combinatorial boundary of the input 
geometries";
 
 command pbsmIndexCreate(x:bat[:oid,:dbl], y:bat[:oid,:dbl], xmin:dbl, 
ymin:dbl, xmax:dbl, ymax:dbl) :bat[:oid,:int] address pbsmIndexCreate_bat;
 command geom.pbsmIndexLoad() address pbsmIndexLoad_bat;
diff --git a/geom/monetdb5/geomBulk.c b/geom/monetdb5/geomBulk.c
--- a/geom/monetdb5/geomBulk.c
+++ b/geom/monetdb5/geomBulk.c
@@ -23,6 +23,65 @@
 
 #include "geom.h"
 
+/*******************************/
+/********** One input **********/
+/*******************************/
+
+str geom_2_geom_bat(int* outBAT_id, int* inBAT_id, int* columnType, int* 
columnSRID) {
+       BAT *outBAT = NULL, *inBAT = NULL;
+       wkb *inWKB = NULL, *outWKB = NULL;
+       BUN p =0, q =0;
+       BATiter inBAT_iter;
+
+       //get the descriptor of the BAT
+       if ((inBAT = BATdescriptor(*inBAT_id)) == NULL) {
+               throw(MAL, "batcalc.wkb", RUNTIME_OBJECT_MISSING);
+       }
+       
+       if ( inBAT->htype != TYPE_void ) { //header type of  BAT not void
+               BBPreleaseref(inBAT->batCacheid);
+               throw(MAL, "batcalc.wkb", "the arguments must have dense and 
aligned heads");
+       }
+
+       //create a new BAT
+       if ((outBAT = BATnew(TYPE_void, ATOMindex("wkb"), BATcount(inBAT), 
TRANSIENT)) == NULL) {
+               BBPreleaseref(inBAT->batCacheid);
+               throw(MAL, "batcalc.wkb", MAL_MALLOC_FAIL);
+       }
+       //set the first idx of the new BAT equal to that of the input BAT
+       BATseqbase(outBAT, inBAT->hseqbase);
+
+       //iterator over the BAT 
+       inBAT_iter = bat_iterator(inBAT);
+       //for (i = 0; i < BATcount(inBAT); i++) { 
+       BATloop(inBAT, p, q) { //iterate over all valid elements
+               str err = NULL;
+
+               //if for used --> inWKB = (wkb *) BUNtail(inBATi, i + 
BUNfirst(inBAT));
+               inWKB = (wkb*) BUNtail(inBAT_iter, p);
+               if ((err = geom_2_geom(&outWKB, &inWKB, columnType, 
columnSRID)) != MAL_SUCCEED) { //check type
+                       str msg;
+                       BBPreleaseref(inBAT->batCacheid);
+                       BBPreleaseref(outBAT->batCacheid);
+                       msg = createException(MAL, "batcalc.wkb", "%s", err);
+                       GDKfree(err);
+                       return msg;
+               }
+               BUNappend(outBAT,outWKB,TRUE); //add the point to the new BAT
+               GDKfree(outWKB);
+               outWKB = NULL;
+       }
+
+       //set some properties of the new BAT
+       BATsetcount(outBAT, BATcount(inBAT));
+       BATsettrivprop(outBAT);
+       BATderiveProps(outBAT,FALSE);
+       BBPreleaseref(inBAT->batCacheid);
+       BBPkeepref(*outBAT_id = outBAT->batCacheid);
+       return MAL_SUCCEED;
+
+}
+
 /*create textual representation of the wkb */
 str wkbAsText_bat(bat *outBAT_id, bat *inBAT_id, int* withSRID) {
        BAT *outBAT = NULL, *inBAT = NULL;
@@ -78,62 +137,231 @@ str wkbAsText_bat(bat *outBAT_id, bat *i
        return MAL_SUCCEED;
 }
 
-
-str geom_2_geom_bat(int* outBAT_id, int* inBAT_id, int* columnType, int* 
columnSRID) {
+str wkbBoundary_bat(bat *outBAT_id, bat *inBAT_id) {
        BAT *outBAT = NULL, *inBAT = NULL;
-       wkb *inWKB = NULL, *outWKB = NULL;
+       wkb *inWKB = NULL;
        BUN p =0, q =0;
        BATiter inBAT_iter;
 
        //get the descriptor of the BAT
        if ((inBAT = BATdescriptor(*inBAT_id)) == NULL) {
-               throw(MAL, "batcalc.wkb", RUNTIME_OBJECT_MISSING);
+               throw(MAL, "batgeom.wkbBoundary", RUNTIME_OBJECT_MISSING);
        }
        
        if ( inBAT->htype != TYPE_void ) { //header type of  BAT not void
                BBPreleaseref(inBAT->batCacheid);
-               throw(MAL, "batcalc.wkb", "the arguments must have dense and 
aligned heads");
+               throw(MAL, "batgeom.wkbBoundary", "The arguments must have 
dense and aligned heads");
        }
 
-       //create a new BAT
+       //create a new for the output BAT
        if ((outBAT = BATnew(TYPE_void, ATOMindex("wkb"), BATcount(inBAT), 
TRANSIENT)) == NULL) {
                BBPreleaseref(inBAT->batCacheid);
-               throw(MAL, "batcalc.wkb", MAL_MALLOC_FAIL);
+               throw(MAL, "batgeom.wkbBoundary", MAL_MALLOC_FAIL);
        }
        //set the first idx of the new BAT equal to that of the input BAT
        BATseqbase(outBAT, inBAT->hseqbase);
 
-       //iterator over the BAT 
+       //iterator over the input BAT   
        inBAT_iter = bat_iterator(inBAT);
-       //for (i = 0; i < BATcount(inBAT); i++) { 
        BATloop(inBAT, p, q) { //iterate over all valid elements
                str err = NULL;
+               wkb* outSingle;
 
-               //if for used --> inWKB = (wkb *) BUNtail(inBATi, i + 
BUNfirst(inBAT));
                inWKB = (wkb*) BUNtail(inBAT_iter, p);
-               if ((err = geom_2_geom(&outWKB, &inWKB, columnType, 
columnSRID)) != MAL_SUCCEED) { //check type
+               if ((err = wkbBoundary(&outSingle, &inWKB)) != MAL_SUCCEED) {
+                       str msg = createException(MAL, "batgeom.wkbBoundary", 
"%s", err);
+                       GDKfree(err);
+
+                       BBPreleaseref(inBAT->batCacheid);
+                       BBPreleaseref(outBAT->batCacheid);
+                       
+                       return msg;
+               }
+               BUNappend(outBAT,outSingle,TRUE); //add the point to the new BAT
+               GDKfree(outSingle);
+               outSingle = NULL;
+       }
+
+       //set the number of elements in the outBAT
+       BATsetcount(outBAT, BATcount(inBAT));
+       
+       BBPreleaseref(inBAT->batCacheid);
+       BBPkeepref(*outBAT_id = outBAT->batCacheid);
+       
+       return MAL_SUCCEED;
+}
+
+
+
+/*******************************/
+/********* Two inputs **********/
+/*******************************/
+
+str wkbContains_bat(int* outBAT_id, bat *aBAT_id, bat *bBAT_id) {
+       BAT *outBAT = NULL, *aBAT = NULL, *bBAT = NULL;
+       BATiter aBAT_iter, bBAT_iter;
+       BUN i=0;
+       str ret = MAL_SUCCEED;
+
+       //get the BATs
+       if ( (aBAT = BATdescriptor(*aBAT_id)) == NULL || (bBAT = 
BATdescriptor(*bBAT_id)) == NULL ) {
+               ret = createException(MAL, "batgeom.Contains", "Problem 
retrieving BATs");
+               goto clean;
+       }
+
+       //check if the BATs are dense and aligned
+       if( !BAThdense(aBAT) || !BAThdense(bBAT) ) {
+               ret = createException(MAL, "batgeom.Contains", "BATs must have 
dense heads");
+               goto clean;
+       }
+       if( aBAT->hseqbase != bBAT->hseqbase || BATcount(aBAT) != 
BATcount(bBAT) ) {
+               ret = createException(MAL, "batgeom.Contains", "BATs must be 
aligned");
+               goto clean;
+       }
+
+       //create a new BAT for the output
+       if ((outBAT = BATnew(TYPE_void, ATOMindex("bit"), BATcount(aBAT), 
TRANSIENT)) == NULL) {
+               ret = createException(MAL, "batgeom.Contains", "Error creating 
new BAT");
+               goto clean;
+       }
+
+       //set the first idx of the output BAT equal to that of the aBAT
+       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;
+               bit outBIT;
+
+               wkb *aWKB = (wkb*) BUNtail(aBAT_iter, i + BUNfirst(aBAT));
+               wkb *bWKB = (wkb*) BUNtail(bBAT_iter, i + BUNfirst(bBAT));
+
+               if ((err = wkbContains(&outBIT, &aWKB, &bWKB)) != MAL_SUCCEED) {
+                       BBPreleaseref(outBAT->batCacheid);      
+
+                       ret = createException(MAL, "batgeom.Contains", "%s", 
err);
+                       GDKfree(err);
+                       
+                       goto clean;
+               }
+               BUNappend(outBAT,&outBIT,TRUE); //add the result to the outBAT
+       }
+
+       BBPkeepref(*outBAT_id = outBAT->batCacheid);
+
+clean:
+       if(aBAT)
+               BBPreleaseref(aBAT->batCacheid);
+       if(bBAT)
+               BBPreleaseref(bBAT->batCacheid);
+               
+       return ret;
+}
+
+str wkbContains_geom_bat(int* outBAT_id, wkb** geomWKB, int* inBAT_id) {
+       BAT *outBAT = NULL, *inBAT = NULL;
+       BATiter inBAT_iter;
+       BUN p=0, q=0;
+
+       //get the descriptor of the BAT
+       if ((inBAT = BATdescriptor(*inBAT_id)) == NULL) {
+               return createException(MAL, "batgeom.Contains", "Problem 
retrieving BAT");
+       }
+       
+       if ( !BAThdense(inBAT) ) {
+               BBPreleaseref(inBAT->batCacheid);
+               return createException(MAL, "batgeom.Contains", "The BAT must 
have dense head");
+       }
+
+       //create a new BAT for the output
+       if ((outBAT = BATnew(TYPE_void, ATOMindex("bit"), BATcount(inBAT), 
TRANSIENT)) == NULL) {
+               BBPreleaseref(inBAT->batCacheid);
+               return createException(MAL, "batgeom.Contains", "Error creating 
new BAT");
+       }
+       
+       //set the first idx of the output BAT equal to that of the aBAT
+       BATseqbase(outBAT, inBAT->hseqbase);
+
+       //iterator over the BATs        
+       inBAT_iter = bat_iterator(inBAT);
+       BATloop(inBAT, p, q) { 
+               str err = NULL;
+               bit outBIT;
+
+               wkb *inWKB = (wkb*) BUNtail(inBAT_iter, p);
+
+               if ((err = wkbContains(&outBIT, geomWKB, &inWKB)) != 
MAL_SUCCEED) {
                        str msg;
                        BBPreleaseref(inBAT->batCacheid);
                        BBPreleaseref(outBAT->batCacheid);
-                       msg = createException(MAL, "batcalc.wkb", "%s", err);
+                       msg = createException(MAL, "batgeom.Contains", "%s", 
err);
                        GDKfree(err);
                        return msg;
                }
-               BUNappend(outBAT,outWKB,TRUE); //add the point to the new BAT
-               GDKfree(outWKB);
-               outWKB = NULL;
+               BUNappend(outBAT,&outBIT,TRUE); //add the result to the outBAT
        }
 
-       //set some properties of the new BAT
-       BATsetcount(outBAT, BATcount(inBAT));
-       BATsettrivprop(outBAT);
-       BATderiveProps(outBAT,FALSE);
        BBPreleaseref(inBAT->batCacheid);
        BBPkeepref(*outBAT_id = outBAT->batCacheid);
+       
        return MAL_SUCCEED;
 
 }
 
+str wkbContains_bat_geom(int* outBAT_id, int* inBAT_id, wkb** geomWKB) {
+       BAT *outBAT = NULL, *inBAT = NULL;
+       BATiter inBAT_iter;
+       BUN p=0, q=0;
+
+       //get the descriptor of the BAT
+       if ((inBAT = BATdescriptor(*inBAT_id)) == NULL) {
+               return createException(MAL, "batgeom.Contains", "Problem 
retrieving BAT");
+       }
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to