Changeset: 99425c223078 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=99425c223078
Modified Files:
geom/monetdb5/geom.c
geom/monetdb5/geom.h
geom/monetdb5/geom.mal
geom/sql/40_geom.sql
Branch: sfcgal
Log Message:
Filter join for Contains(geom, geom). Create a generic function for filter
joins WKB WKB in and BIT out.
diffs (227 lines):
diff --git a/geom/monetdb5/geom.c b/geom/monetdb5/geom.c
--- a/geom/monetdb5/geom.c
+++ b/geom/monetdb5/geom.c
@@ -7810,8 +7810,13 @@ wkbPatchToGeom_bat(wkb **res, wkb **geom
return MAL_SUCCEED;
}
+
+/***************************************************************************/
+/************************ IN: wkb wkb - OUT: bit ***************************/
+/***************************************************************************/
+
static str
-Intersectssubjoin_intern(bat *lres, bat *rres, bat *lid, bat *rid)
+WKBWKBtoBITsubjoin_intern(bat *lres, bat *rres, bat *lid, bat *rid, char
(*func) (const GEOSGeometry *, const GEOSGeometry *), const char *name)
{
BAT *xl, *xr, *bl, *br;
oid lo, ro;
@@ -7822,20 +7827,24 @@ Intersectssubjoin_intern(bat *lres, bat
mbr **rMBRs = NULL;
int *rSRIDs = NULL;
str msg = NULL;
+#ifdef GEOMBULK_DEBUG
+ static struct timeval start, stop;
+ unsigned long long t;
+#endif
if( (bl= BATdescriptor(*lid)) == NULL )
- throw(MAL, "algebra.instersects", RUNTIME_OBJECT_MISSING);
+ throw(MAL, name, RUNTIME_OBJECT_MISSING);
if( (br= BATdescriptor(*rid)) == NULL ){
BBPunfix(*lid);
- throw(MAL, "algebra.instersects", RUNTIME_OBJECT_MISSING);
+ throw(MAL, name, RUNTIME_OBJECT_MISSING);
}
xl = COLnew(0, TYPE_oid, 0, TRANSIENT);
if ( xl == NULL){
BBPunfix(*lid);
BBPunfix(*rid);
- throw(MAL, "algebra.instersects", MAL_MALLOC_FAIL);
+ throw(MAL, name, MAL_MALLOC_FAIL);
}
xr = COLnew(0, TYPE_oid, 0, TRANSIENT);
@@ -7843,7 +7852,7 @@ Intersectssubjoin_intern(bat *lres, bat
BBPunfix(*lid);
BBPunfix(*rid);
BBPunfix(xl->batCacheid);
- throw(MAL, "algebra.instersects", MAL_MALLOC_FAIL);
+ throw(MAL, name, MAL_MALLOC_FAIL);
}
/*iterator over the BATs*/
@@ -7862,7 +7871,7 @@ Intersectssubjoin_intern(bat *lres, bat
BBPunfix(*rid);
BBPunfix(xl->batCacheid);
BBPunfix(xr->batCacheid);
- throw(MAL, "algebra.instersects", "wkb2geos failed");
+ throw(MAL, name, "wkb2geos failed");
}
rMBRs[pr] = mbrFromGeos(rGeometries[pr]);
if (rMBRs[pr] == NULL || mbr_isnil(rMBRs[pr])) {
@@ -7876,7 +7885,7 @@ Intersectssubjoin_intern(bat *lres, bat
BBPunfix(*rid);
BBPunfix(xl->batCacheid);
BBPunfix(xr->batCacheid);
- throw(MAL, "algebra.instersects", "Failed to create mbrFromGeos");
+ throw(MAL, name, "Failed to create mbrFromGeos");
}
rSRIDs[pr] = GEOSGetSRID(rGeometries[pr]);
}
@@ -7890,6 +7899,7 @@ Intersectssubjoin_intern(bat *lres, bat
mbr *lMBR = NULL;
GEOSGeom lGeometry = NULL;
ro = br->hseqbase;
+ int lSRID = 0;
lWKB = (wkb *) BUNtail(lBAT_iter, pl);
lGeometry = wkb2geos(lWKB);
@@ -7904,7 +7914,7 @@ Intersectssubjoin_intern(bat *lres, bat
BBPunfix(*rid);
BBPunfix(xl->batCacheid);
BBPunfix(xr->batCacheid);
- throw(MAL, "algebra.instersects", "wkb2geos failed");
+ throw(MAL, name, "wkb2geos failed");
}
lMBR = mbrFromGeos(lGeometry);
@@ -7919,33 +7929,47 @@ Intersectssubjoin_intern(bat *lres, bat
BBPunfix(*rid);
BBPunfix(xl->batCacheid);
BBPunfix(xr->batCacheid);
- throw(MAL, "algebra.instersects", "mbrFromGeos failed");
+ throw(MAL, name, "mbrFromGeos failed");
}
-
+ lSRID = GEOSGetSRID(lGeometry);
+
+#ifdef GEOMBULK_DEBUG
+ fprintf(stdout, "%s %d %d %d\n", name, pl, ql, BATcount(br));
+ gettimeofday(&start, NULL);
+#endif
for (j = 0; j < BATcount(br); j++, ro++) {
bit out = 0;
mbr *rMBR = NULL;
GEOSGeom rGeometry = rGeometries[j];
if (!lGeometry ||!rGeometry) {
- msg = createException(MAL, "geom.Intersects", "One of the
geometries is NULL");
+ msg = createException(MAL, name, "One of the geometries is
NULL");
break;
}
//if (GEOSGetSRID(lGeometry) != GEOSGetSRID(rGeometry)) {
- if (GEOSGetSRID(lGeometry) != rSRIDs[j]) {
- msg = createException(MAL, "geom.Intersects", "Geometries of
different SRID");
+ //if (GEOSGetSRID(lGeometry) != rSRIDs[j]) {
+ if (lSRID != rSRIDs[j]) {
+ msg = createException(MAL, name, "Geometries of different
SRID");
break;
}
+ /*
err = mbrOverlaps(&out, &lMBR, &rMBRs[j]);
if (err != MAL_SUCCEED) {
msg = err;
break;
} else if (out) {
+ */
+ rMBR = rMBRs[j];
+ if ((out = !((rMBR)->ymax < (lMBR)->ymin ||
+ (rMBR)->ymin > (lMBR)->ymax ||
+ (rMBR)->xmax < (lMBR)->xmin ||
+ (rMBR)->xmin > (lMBR)->xmax))) {
out = 0;
- if ((out = GEOSIntersects(lGeometry, rGeometry)) == 2){
- msg = createException(MAL, "geom.Intersects",
"GEOSIntersects failed");
+ //if ((out = GEOSIntersects(lGeometry, rGeometry)) == 2){
+ if ((out = (*func)(lGeometry, rGeometry)) == 2){
+ msg = createException(MAL, name, "GEOSIntersects failed");
break;
}
if (out) {
@@ -7953,7 +7977,7 @@ Intersectssubjoin_intern(bat *lres, bat
BUNappend(xr, &ro, FALSE);
}
}
- GDKfree(rMBR);
+ //GDKfree(rMBR);
}
if (msg) {
@@ -7976,6 +8000,12 @@ Intersectssubjoin_intern(bat *lres, bat
GEOSGeom_destroy(lGeometry);
GDKfree(lMBR);
lo++;
+
+#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
}
if (rGeometries) {
@@ -8008,7 +8038,17 @@ Intersectssubjoin(bat *lres, bat *rres,
(void)sr;
(void)nil_matches;
(void)estimate;
- return Intersectssubjoin_intern(lres, rres, lid, rid);
+ return WKBWKBtoBITsubjoin_intern(lres, rres, lid, rid, GEOSIntersects,
"geom.Intersects");
+}
+
+str
+Containssubjoin(bat *lres, bat *rres, bat *lid, bat *rid, bat *sl, bat *sr,
bit *nil_matches, lng *estimate)
+{
+ (void)sl;
+ (void)sr;
+ (void)nil_matches;
+ (void)estimate;
+ return WKBWKBtoBITsubjoin_intern(lres, rres, lid, rid, GEOSContains,
"geom.Contains");
}
static str
diff --git a/geom/monetdb5/geom.h b/geom/monetdb5/geom.h
--- a/geom/monetdb5/geom.h
+++ b/geom/monetdb5/geom.h
@@ -38,9 +38,9 @@
#define geom_export extern
#endif
-//#define GEOMBULK_DEBUG 1
-#define OPENCL_DYNAMIC 0
-#define OPENCL_THREADS 1
+#define GEOMBULK_DEBUG 1
+#define OPENCL_DYNAMIC 1
+#define OPENCL_THREADS 8
#define BATrmprops(b) \
b->tsorted = b->trevsorted = 0; \
@@ -376,3 +376,4 @@ geom_export str Intersectssubjoin(bat *l
geom_export str IntersectsXYZsubjoin(bat *lres, bat *rres, bat *lid, bat *xid,
bat *yid, bat *zid, int *srid, bat *sl, bat *sr, bit *nil_matches, lng
*estimate);
geom_export str DWithinsubjoin(bat *lres, bat *rres, bat *lid, bat *rid,
double *dist, bat *sl, bat *sr, bit *nil_matches, lng *estimate);
geom_export str DWithinXYZsubjoin(bat *lres, bat *rres, bat *lid, bat *xid,
bat *yid, bat *zid, int *srid, double *dist, bat *sl, bat *sr, bit
*nil_matches, lng *estimate);
+geom_export str Containssubjoin(bat *lres, bat *rres, bat *lid, bat *rid, bat
*sl, bat *sr, bit *nil_matches, lng *estimate);
diff --git a/geom/monetdb5/geom.mal b/geom/monetdb5/geom.mal
--- a/geom/monetdb5/geom.mal
+++ b/geom/monetdb5/geom.mal
@@ -1053,3 +1053,8 @@ comment "Returns the geometry pairs are
command geom.DWithinsubjoin(l:bat[:wkb], x:bat[:dbl], y:bat[:dbl],
z:bat[:dbl], srid:int, dist:dbl, sl:bat[:oid], sr:bat[:oid], nil_matches:bit,
estimate:lng) (lr:bat[:oid],sr:bat[:oid])
address DWithinXYZsubjoin
comment "Returns the geometry pairs are withing distance dist";
+
+command geom.Containssubjoin(l:bat[:wkb], r:bat[:wkb], sl:bat[:oid],
sr:bat[:oid], nil_matches:bit, estimate:lng) (lr:bat[:oid],rr:bat[:oid])
+address Containssubjoin
+comment "Returns true if and only if no points of B lie in the exterior of A,
and at least one point of the interior of B lies in the interior of A.";
+
diff --git a/geom/sql/40_geom.sql b/geom/sql/40_geom.sql
--- a/geom/sql/40_geom.sql
+++ b/geom/sql/40_geom.sql
@@ -4477,3 +4477,4 @@ CREATE filter function Intersects(geom1
CREATE filter function Intersects(geom1 Geometry, x double, y double, z
double, srid int) external name geom."Intersects";
CREATE filter function DWithin(geom1 Geometry, geom2 Geometry, dist double)
external name geom."DWithin";
CREATE filter function DWithin(geom1 Geometry, x double, y double, z double,
srid int, dist double) external name geom."DWithin";
+CREATE filter function Contains(geom1 Geometry, geom2 Geometry) EXTERNAL NAME
geom."Contains";
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list