Changeset: 9d288c36d901 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=9d288c36d901
Modified Files:
geom/monetdb5/geom.h
geom/monetdb5/geom.mal
geom/monetdb5/geomBulk.c
Branch: sfcgal
Log Message:
Fix bug in the ST_Translate bulk version. Add bulk version for Centroid and
Intersects
diffs (199 lines):
diff --git a/geom/monetdb5/geom.h b/geom/monetdb5/geom.h
--- a/geom/monetdb5/geom.h
+++ b/geom/monetdb5/geom.h
@@ -144,6 +144,7 @@ geom_export str wkbBoundary_bat(bat *inB
geom_export str wkbEquals(bit*, wkb**, wkb**);
geom_export str wkbDisjoint(bit*, wkb**, wkb**);
geom_export str wkbIntersects(bit*, wkb**, wkb**);
+geom_export str wkbIntersects_bat(bat *outBAT_id, bat *aBAT_id, bat *bBAT_id);
geom_export str wkbTouches(bit*, wkb**, wkb**);
geom_export str wkbCrosses(bit*, wkb**, wkb**);
geom_export str wkbWithin(bit*, wkb**, wkb**);
@@ -204,6 +205,7 @@ geom_export str wkbIsValidDetail(char**
geom_export str wkbArea(dbl *out, wkb **a);
geom_export str wkbArea_bat(bat *inBAT_id, bat *outBAT_id);
geom_export str wkbCentroid(wkb **out, wkb **geom);
+geom_export str wkbCentroid_bat(bat *outBAT_id, bat *inBAT_id);
geom_export str wkbDistance(dbl *out, wkb **a, wkb **b);
geom_export str wkbLength(dbl *out, wkb **a);
geom_export str wkbConvexHull(wkb **out, wkb **geom);
diff --git a/geom/monetdb5/geom.mal b/geom/monetdb5/geom.mal
--- a/geom/monetdb5/geom.mal
+++ b/geom/monetdb5/geom.mal
@@ -362,6 +362,10 @@ command Contains(a:wkb, x:dbl, y:dbl) :b
address wkbContains_point
comment "Returns true if the Geometry a 'spatially contains' Geometry b";
+command Contains(a:wkb, px:bat[:oid,:dbl], py:bat[:oid,:dbl]) :bat[:oid,:bit]
+address wkbContains_point_bat
+comment "Returns true if the Geometry-BAT a 'spatially contains' Geometry-B b";
+
command Translate3D(g:wkb, dx:dbl, dy:dbl, dz:dbl) :wkb address wkbTranslate
comment "Moves all points of the geometry by dx, dy, dz";
@@ -376,11 +380,6 @@ function Translate(g:wkb, dx:dbl, dy:dbl
return x;
end Translate;
-command Contains(a:wkb, px:bat[:oid,:dbl], py:bat[:oid,:dbl]) :bat[:oid,:bit]
-address wkbContains_point_bat
-comment "Returns true if the Geometry-BAT a 'spatially contains' Geometry-B b";
-
-
command PointsNum(w:wkb, check:int) :int address wkbNumPoints
comment "The number of points in the Geometry. If check=1, the geometry should
be a linestring";
function NumPoints(w:wkb) :int;
@@ -758,6 +757,9 @@ command Distance(a:bat[:oid,:wkb], b:bat
command Distance(a:wkb, b:bat[:oid,:wkb]) :bat[:oid,:dbl] address
wkbDistance_geom_bat;
command Distance(a:bat[:oid,:wkb], b:wkb) :bat[:oid,:dbl] address
wkbDistance_bat_geom;
+command Centroid(w:bat[:oid,:wkb]) :bat[:oid,:wkb] address wkbCentroid_bat
+comment "Computes the geometric center of a geometry, or equivalently, the
center of mass of the geometry as a POINT.";
+
command Contains(a:bat[:oid,:wkb], b:bat[:oid,:wkb]) :bat[:oid,:bit] address
wkbContains_bat;
command Contains(a:wkb, b:bat[:oid,:wkb]) :bat[:oid,:bit] address
wkbContains_geom_bat;
command Contains(a:bat[:oid,:wkb], b:wkb) :bat[:oid,:bit] address
wkbContains_bat_geom;
@@ -826,6 +828,8 @@ end YMaxFromMBR;
command Area(:bat[:oid,:wkb]) :bat[:oid,:dbl] address wkbArea_bat
comment "Returns the area of the surface if it is a polygon or multi-polygon";
+command Intersects(a:bat[:oid,:wkb], b:bat[:oid,:wkb]) :bat[:oid,:bit] address
wkbIntersects_bat
+comment "Returns true if these Geometries 'spatially intersect in 2D'";
module calc;
diff --git a/geom/monetdb5/geomBulk.c b/geom/monetdb5/geomBulk.c
--- a/geom/monetdb5/geomBulk.c
+++ b/geom/monetdb5/geomBulk.c
@@ -344,6 +344,11 @@ wkbBoundary_bat(bat *outBAT_id, bat *inB
return WKBtoWKB_bat(outBAT_id, inBAT_id, wkbBoundary,
"batgeom.wkbBoundary");
}
+str
+wkbCentroid_bat(bat *outBAT_id, bat *inBAT_id)
+{
+ return WKBtoWKB_bat(outBAT_id, inBAT_id, wkbCentroid,
"batgeom.wkbCentroid");
+}
/**************************************************************************************/
/*************************** IN: wkb - OUT: wkb - FLAG:int
****************************/
@@ -501,6 +506,85 @@ wkbIsValid_bat(bat *outBAT_id, bat *inBA
return WKBtoBIT_bat(outBAT_id, inBAT_id, wkbIsValid,
"batgeom.wkbIsValid");
}
+/***************************************************************************/
+/*************************** IN: wkb wkb - OUT: bit
****************************/
+/***************************************************************************/
+
+static str
+WKBWKBtoBIT_bat(bat *outBAT_id, bat *aBAT_id, bat *bBAT_id, str (*func) (bit
*, wkb **, wkb **), const char *name)
+{
+ BAT *outBAT = NULL, *aBAT = NULL, *bBAT = NULL;
+ BUN p = 0, q = 0;
+ BATiter aBAT_iter, bBAT_iter;
+ str msg = MAL_SUCCEED;
+ static struct timeval start, stop;
+ unsigned long long t;
+
+ //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(0); // Explicitly disable dynamic teams
+ omp_set_num_threads(1);
+ q = BUNlast(aBAT);
+ fprintf(stdout, "%d %d\n", p, q);
+ gettimeofday(&start, NULL);
+ //BATloop(inBAT, p, q) { //iterate over all valid elements
+ #pragma omp parallel for
+ for (p = 0; p < q; p++) {
+ str err = NULL;
+ wkb *aWKB = NULL, *bWKB = NULL;
+ bit out;
+
+ aWKB = (wkb *) BUNtail(aBAT_iter, p);
+ bWKB = (wkb *) BUNtail(bBAT_iter, p);
+ if ((err = (*func) (&out, &aWKB, &bWKB)) != MAL_SUCCEED) {
+ msg = err;
+ #pragma omp cancelregion
+ }
+ BUNappend(outBAT, &out, TRUE); //add the result to the new BAT
+ }
+ gettimeofday(&stop, NULL);
+ t = 1000 * (stop.tv_sec - start.tv_sec) + (stop.tv_usec - start.tv_usec) /
1000;
+ fprintf(stdout, "%llu ms\n", t);
+
+ if (msg != MAL_SUCCEED) {
+ BBPunfix(aBAT->batCacheid);
+ BBPunfix(bBAT->batCacheid);
+ BBPunfix(outBAT->batCacheid);
+ return msg;
+ }
+
+ //set the number of elements in the outBAT
+ //BATsetcount(outBAT, BATcount(inBAT));
+ BBPunfix(aBAT->batCacheid);
+ BBPunfix(bBAT->batCacheid);
+ BBPkeepref(*outBAT_id = outBAT->batCacheid);
+
+ return MAL_SUCCEED;
+}
+
+str
+wkbIntersects_bat(bat *outBAT_id, bat *aBAT_id, bat *bBAT_id)
+{
+ return WKBWKBtoBIT_bat(outBAT_id, aBAT_id, bBAT_id, wkbIntersects,
"batgeom.wkbIntersects");
+}
/***************************************************************************/
/*************************** IN: wkb - OUT: int ****************************/
@@ -730,25 +814,25 @@ WKBtoWKBxyzDBL_bat(bat *outBAT_id, bat *
str err = NULL;
wkb *inWKB = NULL;
wkb *outSingle;
- double *x = NULL, *y = NULL, *z = NULL;
+ double x, y, z;
inWKB = (wkb *) BUNtail(inBAT_iter, p);
if (*inXBAT_id != bat_nil)
- x = (double *) BUNtail(inXBAT_iter, p);
+ x = *(double *) BUNtail(inXBAT_iter, p);
else
- *x = *dx;
+ x = *dx;
if (*inYBAT_id != bat_nil)
- y = (double *) BUNtail(inYBAT_iter, p);
+ y = *(double *) BUNtail(inYBAT_iter, p);
else
- *y = *dy;
+ y = *dy;
if (*inZBAT_id != bat_nil)
- z = (double *) BUNtail(inZBAT_iter, p);
+ z = *(double *) BUNtail(inZBAT_iter, p);
else
- *z = *dz;
+ z = *dz;
- if ((err = (*func) (&outSingle, &inWKB, x, y, z)) != MAL_SUCCEED) {
+ if ((err = (*func) (&outSingle, &inWKB, &x, &y, &z)) != MAL_SUCCEED) {
BBPunfix(inBAT->batCacheid);
if (*inXBAT_id != bat_nil)
BBPunfix(inXBAT->batCacheid);
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list