Changeset: dfa2d41fc2f7 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=dfa2d41fc2f7
Modified Files:
geom/monetdb5/geom.c
geom/monetdb5/geom.h
geom/monetdb5/geom.mal
geom/sql/40_geom.sql
Branch: sfcgal
Log Message:
Add an extension to ST_DUMP. The parentpolygon id can be passed as argument.
Like this through a self-join it is possible to unnest the geom structure,
equivalent to ST_Dump().geom of PostGIS
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
@@ -1663,12 +1663,12 @@ dumpGeometriesGeometry(BAT *idBAT, BAT *
}
}
-str
-wkbDump(bat *idBAT_id, bat *geomBAT_id, wkb **geomWKB)
-{
- BAT *idBAT = NULL, *geomBAT = NULL;
+static str
+wkbDump_(bat *parentBAT_id, bat *idBAT_id, bat *geomBAT_id, wkb **geomWKB, int
*parent)
+{
+ BAT *idBAT = NULL, *geomBAT = NULL, *parentBAT = NULL;
GEOSGeom geosGeometry;
- unsigned int geometriesNum;
+ unsigned int geometriesNum, i;
str err;
if (wkb_isnil(*geomWKB)) {
@@ -1676,21 +1676,35 @@ wkbDump(bat *idBAT_id, bat *geomBAT_id,
//create new empty BAT for the output
if ((idBAT = BATnew(TYPE_void, TYPE_str, 0, TRANSIENT)) ==
NULL) {
*idBAT_id = bat_nil;
- throw(MAL, "geom.DumpPoints", "Error creating new BAT");
+ throw(MAL, "geom.Dump", "Error creating new BAT");
}
if ((geomBAT = BATnew(TYPE_void, ATOMindex("wkb"), 0,
TRANSIENT)) == NULL) {
BBPunfix(idBAT->batCacheid);
*geomBAT_id = bat_nil;
- throw(MAL, "geom.DumpPoints", "Error creating new BAT");
+ throw(MAL, "geom.Dump", "Error creating new BAT");
}
+ if (parent) {
+ if ((parentBAT = BATnew(TYPE_void, ATOMindex("int"), 0,
TRANSIENT)) == NULL) {
+ BBPunfix(idBAT->batCacheid);
+ BBPunfix(geomBAT->batCacheid);
+ *parentBAT_id = bat_nil;
+ throw(MAL, "geom.Dump", "Error creating new BAT");
+ }
+ }
+
BATseqbase(idBAT, 0);
BBPkeepref(*idBAT_id = idBAT->batCacheid);
BATseqbase(geomBAT, 0);
BBPkeepref(*geomBAT_id = geomBAT->batCacheid);
+ if (parent) {
+ BATseqbase(parentBAT, 0);
+ BBPkeepref(*parentBAT_id = parentBAT->batCacheid);
+ }
+
return MAL_SUCCEED;
}
@@ -1710,17 +1724,52 @@ wkbDump(bat *idBAT_id, bat *geomBAT_id,
}
BATseqbase(geomBAT, 0);
+ if (parent) {
+ if ((parentBAT = BATnew(TYPE_void, ATOMindex("int"), geometriesNum,
TRANSIENT)) == NULL) {
+ BBPunfix(idBAT->batCacheid);
+ BBPunfix(geomBAT->batCacheid);
+ throw(MAL, "geom.Dump", "Error creating new BAT");
+ }
+ BATseqbase(parentBAT, 0);
+ /*Get the tail and add parentID geometriesNum types*/
+ for (i = 0; i < geometriesNum; i++) {
+ if (BUNappend(parentBAT, parent, TRUE) != GDK_SUCCEED) {
+ err = createException(MAL, "geom.Dump", "BUNappend failed");
+ BBPunfix(idBAT->batCacheid);
+ BBPunfix(geomBAT->batCacheid);
+ if (parent)
+ BBPunfix(parentBAT->batCacheid);
+ return err;
+ }
+ }
+ }
+
if ((err = dumpGeometriesGeometry(idBAT, geomBAT, geosGeometry, "")) !=
MAL_SUCCEED) {
BBPunfix(idBAT->batCacheid);
BBPunfix(geomBAT->batCacheid);
+ if (parent)
+ BBPunfix(parentBAT->batCacheid);
return err;
}
BBPkeepref(*idBAT_id = idBAT->batCacheid);
BBPkeepref(*geomBAT_id = geomBAT->batCacheid);
+ if (parent)
+ BBPkeepref(*parentBAT_id = parentBAT->batCacheid);
+
return MAL_SUCCEED;
}
+str
+wkbDump(bat *idBAT_id, bat *geomBAT_id, wkb **geomWKB) {
+ return wkbDump_(NULL, idBAT_id, geomBAT_id, geomWKB, NULL);
+}
+
+str
+wkbDumpP(bat *parentBAT_id, bat *idBAT_id, bat *geomBAT_id, wkb **geomWKB, int
*parent) {
+ return wkbDump_(parentBAT_id, idBAT_id, geomBAT_id, geomWKB, parent);
+}
+
static str
dumpPointsPoint(BAT *idBAT, BAT *geomBAT, const GEOSGeometry *geosGeometry,
unsigned int *lvl, const char *path)
{
diff --git a/geom/monetdb5/geom.h b/geom/monetdb5/geom.h
--- a/geom/monetdb5/geom.h
+++ b/geom/monetdb5/geom.h
@@ -14,6 +14,7 @@
#include "libgeom.h"
#include <mal.h>
+#include <mal_interpreter.h>
#include <mal_atom.h>
#include <mal_exception.h>
#include <mal_client.h>
@@ -229,6 +230,7 @@ geom_export str wkbForceDim(wkb**, wkb**
geom_export str wkbSegmentize(wkb**, wkb**, dbl*);
geom_export str wkbDump(bat* idBAT_id, bat* geomBAT_id, wkb**);
+geom_export str wkbDumpP(bat* partentBAT_id, bat* idBAT_id, bat* geomBAT_id,
wkb**, int* parent);
geom_export str wkbDumpPoints(bat* idBAT_id, bat* geomBAT_id, wkb**);
geom_export str wkbPolygonize(wkb **res, wkb **geom);
geom_export str wkbSimplifyPreserveTopology(wkb **res, wkb **geom, float
*tolerance);
diff --git a/geom/monetdb5/geom.mal b/geom/monetdb5/geom.mal
--- a/geom/monetdb5/geom.mal
+++ b/geom/monetdb5/geom.mal
@@ -336,6 +336,8 @@ command DelaunayTriangles(a:wkb, toleran
comment "Returns a Delaunay triangulation, flag=0 => collection of polygons,
flag=1 => multilinestring";
command Dump(a:wkb) (id:bat[:oid, :str], geom:bat[:oid, :wkb]) address wkbDump
comment "Gets a MultiPolygon and returns the Polygons in it";
+command DumpP(a:wkb, p:int) (parent:bat[:oid, :int], id:bat[:oid, :str],
geom:bat[:oid, :wkb]) address wkbDumpP
+comment "Gets a MultiPolygon and returns the Polygons in it";
command DumpPoints(a:wkb) (id:bat[:oid, :str], geom:bat[:oid, :wkb]) address
wkbDumpPoints
comment "Gets a Geometry and returns the Points in it";
command Polygonize(a:wkb) :wkb address wkbPolygonize
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
@@ -4365,6 +4365,7 @@ CREATE AGGREGATE ST_Collect(geom Geometr
--CREATE FUNCTION ST_ConcaveHull RETURNS EXTERNAL NAME
CREATE FUNCTION ST_DelaunayTriangles(geom Geometry, tolerance double, flags
integer) RETURNS Geometry EXTERNAL NAME geom."DelaunayTriangles";
CREATE FUNCTION ST_Dump(geom Geometry) RETURNS TABLE(id string, polygonWKB
Geometry) EXTERNAL NAME geom."Dump";
+CREATE FUNCTION ST_Dump(geom Geometry, parent int) RETURNS TABLE(parent int,
id string, polygonWKB Geometry) EXTERNAL NAME geom."DumpP";
CREATE FUNCTION ST_DumpPoints(geom Geometry) RETURNS TABLE(path string, pointG
Geometry) EXTERNAL NAME geom."DumpPoints";
--CREATE FUNCTION ST_DumpRings RETURNS EXTERNAL NAME
--CREATE FUNCTION ST_FlipCoordinates RETURNS EXTERNAL NAME
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list