Changeset: 9612b6c5098a for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/9612b6c5098a
Modified Files:
        geom/monetdb5/geod.c
        geom/monetdb5/geod.h
        geom/monetdb5/geom.c
        geom/monetdb5/geom.h
        geom/sql/40_geom.sql
Branch: geo-update
Log Message:

Added ST_Collect scalar version, previously only a aggregate predicate. Fixed 
the name of wkbGetCompatibleGeometries.


diffs (160 lines):

diff --git a/geom/monetdb5/geod.c b/geom/monetdb5/geod.c
--- a/geom/monetdb5/geod.c
+++ b/geom/monetdb5/geod.c
@@ -241,8 +241,8 @@ cartPointFromXYZ(double x, double y, dou
 }
 
 /* Converts Well-Known Bytes into Geos Geometries, if they are not NULL and 
have the same SRID (used for geographic functions) */
-static str
-wkbGetComplatibleGeometries(wkb **a, wkb **b, GEOSGeom *ga, GEOSGeom *gb)
+str
+wkbGetCompatibleGeometries(wkb **a, wkb **b, GEOSGeom *ga, GEOSGeom *gb)
 {
        str err = MAL_SUCCEED;
 
@@ -773,7 +773,7 @@ wkbDistanceGeographic(dbl *out, wkb **a,
 {
        str err = MAL_SUCCEED;
        GEOSGeom ga, gb;
-       err = wkbGetComplatibleGeometries(a, b, &ga, &gb);
+       err = wkbGetCompatibleGeometries(a, b, &ga, &gb);
        if (ga && gb) {
                (*out) = geoDistanceInternal(ga, gb, 0);
        }
@@ -793,7 +793,7 @@ wkbDWithinGeographic(bit *out, wkb **a, 
        str err = MAL_SUCCEED;
        GEOSGeom ga, gb;
        double distance;
-       err = wkbGetComplatibleGeometries(a, b, &ga, &gb);
+       err = wkbGetCompatibleGeometries(a, b, &ga, &gb);
        if (ga && gb) {
                distance = geoDistanceInternal(ga, gb, *d);
                (*out) = (distance <= (*d));
@@ -814,7 +814,7 @@ wkbIntersectsGeographic(bit *out, wkb **
        str err = MAL_SUCCEED;
        GEOSGeom ga, gb;
        double distance;
-       err = wkbGetComplatibleGeometries(a, b, &ga, &gb);
+       err = wkbGetCompatibleGeometries(a, b, &ga, &gb);
        if (ga && gb) {
                distance = geoDistanceInternal(ga, gb, 0);
                (*out) = (distance == 0);
@@ -917,7 +917,7 @@ wkbCoversGeographic(bit *out, wkb **a, w
 {
        str err = MAL_SUCCEED;
        GEOSGeom ga, gb;
-       err = wkbGetComplatibleGeometries(a, b, &ga, &gb);
+       err = wkbGetCompatibleGeometries(a, b, &ga, &gb);
        if (ga && gb)
                (*out) = geoCoversInternal(ga, gb);
 
diff --git a/geom/monetdb5/geod.h b/geom/monetdb5/geod.h
--- a/geom/monetdb5/geod.h
+++ b/geom/monetdb5/geod.h
@@ -26,7 +26,7 @@ typedef struct GeoLines
     BoundingBox* bbox;
 } GeoLines;
 
-//Geographic polygon 
+//Geographic polygon
 typedef struct GeoPolygon
 {
     GeoLines exteriorRing;
@@ -49,6 +49,8 @@ typedef struct CartPoint2D
     double y;
 } CartPoint2D;
 
+str wkbGetCompatibleGeometries(wkb **a, wkb **b, GEOSGeom *ga, GEOSGeom *gb);
+
 /* Geographic functions */
 str wkbCoversGeographic(bit* out, wkb** a, wkb** b);
 
@@ -63,8 +65,4 @@ str wkbIntersectsGeographic(bit* out, wk
 str wkbIntersectsGeographicSelect(bat* outid, const bat *bid , const bat *sid, 
wkb **wkb_const, bit *anti);
 str wkbIntersectsGeographicJoin(bat *lres_id, bat *rres_id, const bat *l_id, 
const bat *r_id, const bat *ls_id, const bat *rs_id, bit *nil_matches, lng 
*estimate, bit *anti);
 
-str wkbCollectAggr (wkb **out, const bat *bid);
-str wkbCollectAggrSubGrouped(bat *out, const bat *bid, const bat *gid, const 
bat *eid, const bit *skip_nils);
-str wkbCollectAggrSubGroupedCand(bat* outid, const bat* bid, const bat* gid, 
const bat* eid, const bat* sid, const bit* skip_nils);
-
 str geodeticEdgeBoundingBox(const CartPoint3D* p1, const CartPoint3D* p2, 
BoundingBox* mbox);
diff --git a/geom/monetdb5/geom.c b/geom/monetdb5/geom.c
--- a/geom/monetdb5/geom.c
+++ b/geom/monetdb5/geom.c
@@ -285,6 +285,37 @@ wkbCollectAggr (wkb **out, const bat *bi
        return msg;
 }
 
+str
+wkbCollect (wkb **out, wkb **a, wkb **b) {
+       str err = MAL_SUCCEED;
+       GEOSGeom ga, gb, collection;
+       GEOSGeom *collect = NULL;
+       int type_a, type_b;
+       int srid;
+
+       if ((err = wkbGetCompatibleGeometries(a, b, &ga, &gb)) != MAL_SUCCEED)
+               throw(MAL,"geom.Collect", "%s", err);
+       if ((collect = GDKmalloc(sizeof(GEOSGeom) * 2)) == NULL) {
+               throw(MAL, "geom.Collect", SQLSTATE(HY013) MAL_MALLOC_FAIL);
+       }
+
+       collect[0] = ga;
+       collect[1] = gb;
+       srid = GEOSGetSRID(ga);
+       type_a = GEOSGeomTypeId(ga);
+       type_b = GEOSGeomTypeId(gb);
+
+       if (type_a == type_b)
+               collection = 
GEOSGeom_createCollection(GEOSGeom_getCollectionType(type_a), collect, 
(unsigned int) 2);
+       else
+               collection = GEOSGeom_createCollection(GEOS_GEOMETRYCOLLECTION, 
collect, (unsigned int) 2);
+
+       if ((*out = geos2wkb(collection)) == NULL)
+               err = createException(MAL, "geom.Collect", SQLSTATE(38000) 
"Geos operation geos2wkb failed");
+       GEOSGeom_destroy(ga);
+       GEOSGeom_destroy(gb);
+       return err;
+}
 /**
  * Start of old geom module
  **/
@@ -5530,6 +5561,8 @@ static mel_func geom_init_funcs[] = {
 
  command("geom", "IntersectsMBR", mbrIntersects, false, "TODO", args(1,3, 
arg("",bit),arg("a",mbr),arg("b",mbr))),
 
+ command("geom", "Collect", wkbCollect, false, "TODO", args(1,3, 
arg("",wkb),arg("a",wkb),arg("b",wkb))),
+
  command("aggr", "Collect", wkbCollectAggr, false, "TODO", args(1, 2, arg("", 
wkb), batarg("val", wkb))),
  command("aggr", "subCollect", wkbCollectAggrSubGrouped, false, "TODO", 
args(1, 5, batarg("", wkb), batarg("val", wkb), batarg("g", oid), batarg("e", 
oid), arg("skip_nils", bit))),
  command("aggr", "subCollect", wkbCollectAggrSubGroupedCand, false, "TODO", 
args(1, 6, batarg("", wkb), batarg("val", wkb), batarg("g", oid), 
batargany("e", 1), batarg("g", oid), arg("skip_nils", bit))),
diff --git a/geom/monetdb5/geom.h b/geom/monetdb5/geom.h
--- a/geom/monetdb5/geom.h
+++ b/geom/monetdb5/geom.h
@@ -226,7 +226,12 @@ geom_export str wkbIntersectsSelectRTree
 geom_export str wkbDWithinJoinRTree(bat *lres_id, bat *rres_id, const bat 
*l_id, const bat *r_id, const bat *ls_id, const bat *rs_id, double *distance, 
bit *nil_matches, lng *estimate);
 geom_export str wkbDWithinSelectRTree(bat* outid, const bat *bid , const bat 
*sid, wkb **wkb_const, double *distance, bit *anti);
 
-str wkbDWithinJoinNoIndex(bat *lres_id, bat *rres_id, const bat *l_id, const 
bat *r_id, const bat *ls_id, const bat *rs_id, double *distance, bit 
*nil_matches, lng *estimate);
-str wkbDWithinSelectNoIndex(bat* outid, const bat *bid , const bat *sid, wkb 
**wkb_const, double *distance, bit *anti);
+geom_export str wkbDWithinJoinNoIndex(bat *lres_id, bat *rres_id, const bat 
*l_id, const bat *r_id, const bat *ls_id, const bat *rs_id, double *distance, 
bit *nil_matches, lng *estimate);
+geom_export str wkbDWithinSelectNoIndex(bat* outid, const bat *bid , const bat 
*sid, wkb **wkb_const, double *distance, bit *anti);
 
 geom_export str mbrIntersects(bit* out, mbr** mbr1, mbr** mbr2);
+
+geom_export str wkbCollectAggr (wkb **out, const bat *bid);
+geom_export str wkbCollectAggrSubGrouped(bat *out, const bat *bid, const bat 
*gid, const bat *eid, const bit *skip_nils);
+geom_export str wkbCollectAggrSubGroupedCand(bat* outid, const bat* bid, const 
bat* gid, const bat* eid, const bat* sid, const bit* skip_nils);
+geom_export str wkbCollect (wkb **out, wkb **a, wkb **b);
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
@@ -550,7 +550,7 @@ GRANT EXECUTE ON FUNCTION ST_Length2D(Ge
 --CREATE FUNCTION ST_Buffer(geog Geography, radius double) RETURNS Geometry 
EXTERNAL NAME geom."Buffer";
 --CREATE FUNCTION ST_BuildArea RETURNS EXTERNAL NAME
 --collect is the same to union. POstGIS just has a more efficient 
implementation for it compared to union
-CREATE FUNCTION ST_Collect(geom1 Geometry, geom2 Geometry) RETURNS Geometry 
EXTERNAL NAME geom."Union";
+CREATE FUNCTION ST_Collect(geom1 Geometry, geom2 Geometry) RETURNS Geometry 
EXTERNAL NAME geom."Collect";
 GRANT EXECUTE ON FUNCTION ST_Collect(Geometry, Geometry) TO PUBLIC;
 --CREATE FUNCTION ST_ConcaveHull RETURNS EXTERNAL NAME
 CREATE FUNCTION ST_DelaunayTriangles(geom Geometry, tolerance double, flags 
integer) RETURNS Geometry EXTERNAL NAME geom."DelaunayTriangles";
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to