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

Bulk version of XMin, XMax, YMin, YMax


diffs (154 lines):

diff --git a/geom/monetdb5/geom.c b/geom/monetdb5/geom.c
--- a/geom/monetdb5/geom.c
+++ b/geom/monetdb5/geom.c
@@ -207,8 +207,12 @@ geom_export str mbrEqual(bit *out, mbr *
 geom_export str mbrEqual_wkb(bit *out, wkb **geom1WKB, wkb **geom2WKB);
 geom_export str mbrDistance(double *out, mbr **b1, mbr **b2);
 geom_export str mbrDistance_wkb(double *out, wkb **geom1WKB, wkb **geom2WKB);
+
 geom_export str wkbCoordinateFromWKB(dbl*, wkb**, int*);
+geom_export str wkbCoordinateFromWKB_bat(int *outBAT_id, int *inBAT_id, int* 
coordinateIdx);
+
 geom_export str wkbCoordinateFromMBR(dbl*, mbr**, int*);
+geom_export str wkbCoordinateFromMBR_bat(int *outBAT_id, int *inBAT_id, int* 
coordinateIdx);
 
 /** convert degrees to radians */
 static void degrees2radians(double *x, double *y, double *z) {
@@ -3522,12 +3526,65 @@ str wkbCoordinateFromMBR(dbl* coordinate
                        *coordinateValue = (*geomMBR)->ymax;
                        break;
                default:
-                       throw(MAL, "wkb.coordinateFromMBR", "Unrecognised 
coordinateIdx: %d\n", *coordinateIdx);
+                       throw(MAL, "geom.coordinateFromMBR", "Unrecognised 
coordinateIdx: %d\n", *coordinateIdx);
        }
 
        return MAL_SUCCEED;
 }
 
+str wkbCoordinateFromMBR_bat(int *outBAT_id, int *inBAT_id, int* 
coordinateIdx) {
+       BAT *outBAT = NULL, *inBAT = NULL;
+       mbr *inMBR = NULL;
+       double outDbl = 0.0;
+       BUN p =0, q =0;
+       BATiter inBAT_iter;
+
+       //get the descriptor of the BAT
+       if ((inBAT = BATdescriptor(*inBAT_id)) == NULL) {
+               throw(MAL, "batgeom.coordinateFromMBR", RUNTIME_OBJECT_MISSING);
+       }
+       
+       if ( inBAT->htype != TYPE_void ) { //header type of  BAT not void
+               BBPreleaseref(inBAT->batCacheid);
+               throw(MAL, "batgeom.coordinateFromMBR", "the arguments must 
have dense and aligned heads");
+       }
+
+       //create a new BAT for the output
+       if ((outBAT = BATnew(TYPE_void, ATOMindex("dbl"), BATcount(inBAT), 
TRANSIENT)) == NULL) {
+               BBPreleaseref(inBAT->batCacheid);
+               throw(MAL, "batgeom.coordinateFromMBR", 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);
+       BATloop(inBAT, p, q) { //iterate over all valid elements
+               str err = NULL;
+
+               inMBR = (mbr*) BUNtail(inBAT_iter, p);
+               if ((err = wkbCoordinateFromMBR(&outDbl, &inMBR, 
coordinateIdx)) != MAL_SUCCEED) {
+                       str msg;
+                       BBPreleaseref(inBAT->batCacheid);
+                       BBPreleaseref(outBAT->batCacheid);
+                       msg = createException(MAL, "batgeom.coordinateFromMBR", 
"%s", err);
+                       GDKfree(err);
+                       return msg;
+               }
+               BUNappend(outBAT,&outDbl,TRUE);
+       }
+
+       //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 wkbCoordinateFromWKB(dbl* coordinateValue, wkb** geomWKB, int* 
coordinateIdx) {
        mbr* geomMBR;
        str ret = MAL_SUCCEED ; 
@@ -3541,6 +3598,23 @@ str wkbCoordinateFromWKB(dbl* coordinate
        return ret;
 }
 
+str wkbCoordinateFromWKB_bat(int *outBAT_id, int *inBAT_id, int* 
coordinateIdx) {
+       str err = NULL;
+       int inBAT_mbr_id = 0; //the id of the bat with the mbrs
+
+       if((err = wkbMBR_bat(&inBAT_mbr_id, inBAT_id)) != MAL_SUCCEED) {
+               str msg;
+               msg = createException(MAL, "batgeom.coordinateFromMBR", "%s", 
err);
+               GDKfree(err);
+               return msg;
+
+       }
+
+       //call the bulk version of wkbCoordinateFromMBR
+       return wkbCoordinateFromMBR_bat(outBAT_id, &inBAT_mbr_id, 
coordinateIdx);
+}
+
+
 
 geom_export BUN mbrHASH(mbr *atom);
 geom_export int mbrCOMP(mbr *l, mbr *r);
diff --git a/geom/monetdb5/geom.mal b/geom/monetdb5/geom.mal
--- a/geom/monetdb5/geom.mal
+++ b/geom/monetdb5/geom.mal
@@ -402,6 +402,43 @@ command Contains(a:bat[:oid,:wkb], b:bat
 command mbr(:bat[:oid,:wkb]) :bat[:oid,:mbr] address wkbMBR_bat
 comment "Creates the mbr for the given wkb.";
 
+command coordinateFromWKB(:bat[:oid,:wkb], :int) :bat[:oid,:dbl] address 
wkbCoordinateFromWKB_bat
+comment "returns xmin (=1), ymin (=2), xmax (=3) or ymax(=4) of the provided 
geometry";
+command coordinateFromMBR(:bat[:oid,:mbr], :int) :bat[:oid,:dbl] address 
wkbCoordinateFromMBR_bat
+comment "returns xmin (=1), ymin (=2), xmax (=3) or ymax(=4) of the provided 
mbr";
+
+function XMinFromWKB(g:bat[:oid,:wkb]) :bat[:oid,:dbl];
+       x := coordinateFromWKB(g, 1);
+       return x;
+end XMinFromWKB;
+function YMinFromWKB(g:bat[:oid,:wkb]) :bat[:oid,:dbl];
+       x := coordinateFromWKB(g, 2);
+       return x;
+end YMinFromWKB;
+function XMaxFromWKB(g:bat[:oid,:wkb]) :bat[:oid,:dbl];
+       x := coordinateFromWKB(g, 3);
+       return x;
+end XMaxFromWKB;
+function YMaxFromWKB(g:bat[:oid,:wkb]) :bat[:oid,:dbl];
+       x := coordinateFromWKB(g, 4);
+       return x;
+end YMaxFromWKB;
+function XMinFromMBR(b:bat[:oid,:mbr]) :bat[:oid,:dbl];
+       x := coordinateFromMBR(b, 1);
+       return x;
+end XMinFromMBR;
+function YMinFromMBR(b:bat[:oid,:mbr]) :bat[:oid,:dbl];
+       x := coordinateFromMBR(b, 2);
+       return x;
+end YMinFromMBR;
+function XMaxFromMBR(b:bat[:oid,:mbr]) :bat[:oid,:dbl];
+       x := coordinateFromMBR(b, 3);
+       return x;
+end XMaxFromMBR;
+function YMaxFromMBR(b:bat[:oid,:mbr]) :bat[:oid,:dbl];
+       x := coordinateFromMBR(b, 4);
+       return x;
+end YMaxFromMBR;
 
 
 
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to