Changeset: 985c1560326c for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=985c1560326c
Modified Files:
        geom/monetdb5/geom.c
        geom/monetdb5/geom.h
        geom/monetdb5/geom.mal
        geom/sql/40_geom.sql
Branch: sfcgal
Log Message:

ST_DumpRings


diffs (172 lines):

diff --git a/geom/monetdb5/geom.c b/geom/monetdb5/geom.c
--- a/geom/monetdb5/geom.c
+++ b/geom/monetdb5/geom.c
@@ -2084,6 +2084,124 @@ wkbDumpPointsP(bat *parentBAT_id, bat *i
 }
 
 static str
+wkbDumpRings_(bat *parentBAT_id, bat *geomBAT_id, wkb **geomWKB, int *parent)
+{
+       BAT *geomBAT = NULL, *parentBAT = NULL;
+       GEOSGeom geosGeometry;
+    const GEOSGeometry *ring;
+    wkb *geom;
+       unsigned int numInteriorRings, i;
+       str err;
+
+       if (wkb_isnil(*geomWKB)) {
+
+               //create new empty BAT for the output
+               if ((geomBAT = COLnew(0, ATOMindex("wkb"), 0, TRANSIENT)) == 
NULL) {
+                       *geomBAT_id = bat_nil;
+                       throw(MAL, "geom.DumpRings", "Error creating new BAT");
+               }
+
+        if (parent) {
+            if ((parentBAT = COLnew(0, ATOMindex("int"), 0, TRANSIENT)) == 
NULL) {
+                BBPunfix(geomBAT->batCacheid);
+                *parentBAT_id = bat_nil;
+                throw(MAL, "geom.DumpRings", "Error creating new BAT");
+            }
+        }
+
+               BBPkeepref(*geomBAT_id = geomBAT->batCacheid);
+        if (parent) {
+               BBPkeepref(*parentBAT_id = parentBAT->batCacheid);
+        }
+
+               return MAL_SUCCEED;
+       }
+
+    geosGeometry = wkb2geos(*geomWKB);
+       ring = GEOSGetExteriorRing(geosGeometry);
+       if(!ring) {
+        BBPunfix(geomBAT->batCacheid);
+        if (parent)
+            BBPunfix(parentBAT->batCacheid);
+               return createException(MAL, 
"geom.DumpRings","GEOSGetExteriorRing failed");
+       }
+    if((geom = geos2wkb(ring)) != NULL) {
+        BBPunfix(geomBAT->batCacheid);
+        if (parent)
+            BBPunfix(parentBAT->batCacheid);
+        return createException(MAL, "geom.DumpRings","geos2wkb failed");
+    }
+    if (BUNappend(geomBAT, geom, TRUE) != GDK_SUCCEED) {
+        BBPunfix(geomBAT->batCacheid);
+        if (parent)
+            BBPunfix(parentBAT->batCacheid);
+        return createException(MAL, "geom.DumpRings","BUNappend failed");
+    }
+
+       //check the interior rings
+       if ((numInteriorRings = GEOSGetNumInteriorRings(geosGeometry) == -1)) {
+        BBPunfix(geomBAT->batCacheid);
+        if (parent)
+            BBPunfix(parentBAT->batCacheid);
+               return createException(MAL, 
"geom.DumpRings","GEOSGetNumInteriorRings failed");
+    }
+
+       for(i=0; i<numInteriorRings; i++) {
+               ring = GEOSGetInteriorRingN(geosGeometry, i);
+        if (ring == NULL) {
+            BBPunfix(geomBAT->batCacheid);
+            if (parent)
+                BBPunfix(parentBAT->batCacheid);
+               return createException(MAL, 
"geom.DumpRings","GEOSGetInteriorRingN failed");
+        }
+        
+        if((geom = geos2wkb(ring)) != NULL) {
+            BBPunfix(geomBAT->batCacheid);
+            if (parent)
+                BBPunfix(parentBAT->batCacheid);
+               return createException(MAL, "geom.DumpRings","geos2wkb failed");
+        }
+        if (BUNappend(geomBAT, geom, TRUE) != GDK_SUCCEED) {
+            BBPunfix(geomBAT->batCacheid);
+            if (parent)
+                BBPunfix(parentBAT->batCacheid);
+               return createException(MAL, "geom.DumpRings","BUNappend 
failed");
+        }
+       }
+
+    if (parent) {
+        if ((parentBAT = COLnew(0, ATOMindex("int"), numInteriorRings+1, 
TRANSIENT)) == NULL) {
+            BBPunfix(geomBAT->batCacheid);
+            throw(MAL, "geom.DumpRings", "Error creating new BAT");
+        }
+        /*Get the tail and add parentID geometriesNum types*/
+        for (i = 0; i < numInteriorRings+1; i++) {
+            if (BUNappend(parentBAT, parent, TRUE) != GDK_SUCCEED) {
+                err = createException(MAL, "geom.DumpRings", "BUNappend 
failed");
+                BBPunfix(geomBAT->batCacheid);
+                if (parent)
+                    BBPunfix(parentBAT->batCacheid);
+                return err;
+            }
+        }
+    }
+
+       GEOSGeom_destroy(geosGeometry);
+       BBPkeepref(*geomBAT_id = geomBAT->batCacheid);
+    if (parent)
+           BBPkeepref(*parentBAT_id = parentBAT->batCacheid);
+
+       return MAL_SUCCEED;
+}
+
+
+str
+wkbDumpRings(bat *geomBAT_id, wkb **geomWKB) {
+    return wkbDumpRings_(NULL, geomBAT_id, geomWKB, NULL);
+}
+
+
+static str
 wkbPolygonize_(wkb** outWKB, wkb** geom1, wkb** geom2){
     str msg = MAL_SUCCEED;
        GEOSGeom geos1Geometry = NULL, geos2Geometry = NULL;
@@ -4173,7 +4291,7 @@ wkbInteriorRingN(wkb **interiorRingWKB, 
        if (rN == -1) {
                *interiorRingWKB = NULL;
                GEOSGeom_destroy(geosGeometry);
-               throw(MAL, "geom.InteriorRingN", "GEOSGetInteriorRingN 
failed.");
+               throw(MAL, "geom.InteriorRingN", "GEOSGetNumInteriorRings 
failed.");
        }
 
        if (rN < *ringNum || *ringNum <= 0) {
diff --git a/geom/monetdb5/geom.h b/geom/monetdb5/geom.h
--- a/geom/monetdb5/geom.h
+++ b/geom/monetdb5/geom.h
@@ -260,6 +260,7 @@ geom_export str wkbDump(bat* idBAT_id, b
 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 wkbDumpPointsP(bat* partentBAT_id, bat* idBAT_id, bat* 
geomBAT_id, wkb**, int* parent);
+geom_export str wkbDumpRings(bat* geomBAT_id, wkb**);
 geom_export str dumpGeometriesGeometry(BAT *idBAT, BAT *geomBAT, const 
GEOSGeometry *geosGeometry, const char *path);
 geom_export str wkbPolygonize(wkb **res, wkb **geom);
 geom_export str wkbsubPolygonize(bat *outBAT_id, bat* bBAT_id, bat *gBAT_id, 
bat *eBAT_id, bit* flag);
diff --git a/geom/monetdb5/geom.mal b/geom/monetdb5/geom.mal
--- a/geom/monetdb5/geom.mal
+++ b/geom/monetdb5/geom.mal
@@ -358,6 +358,8 @@ command DumpPoints(a:wkb) (id:bat[:str],
 comment "Gets a Geometry and returns the Points in it";
 command DumpPointsP(a:wkb, p:int) (parent:bat[:int], id:bat[:str], 
geom:bat[:wkb]) address wkbDumpPointsP
 comment "Gets a Geometry and returns the Points in it";
+command DumpRings(a:wkb) (geom:bat[:wkb]) address wkbDumpRings
+comment "Gets a Polygon and returns the rings it";
 
 command Polygonize(a:wkb) :wkb address wkbPolygonize
 comment "Creates a GeometryCollection containing possible polygons formed from 
the constituent linework of a set of geometries.";
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
@@ -4371,7 +4371,7 @@ CREATE FUNCTION ST_Dump(geom Geometry) R
 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_DumpPoints(geom Geometry, parent int) RETURNS TABLE(parent 
int, path string, pointG Geometry) EXTERNAL NAME geom."DumpPointsP";
---CREATE FUNCTION ST_DumpRings RETURNS EXTERNAL NAME
+CREATE FUNCTION ST_DumpRings RETURNS TABLE(polygonWKB Geometry) EXTERNAL NAME 
geom."DumpRings";
 --CREATE FUNCTION ST_FlipCoordinates RETURNS EXTERNAL NAME
 --CREATE FUNCTION ST_Intersection(geog1 Geography, geog2 Geography) RETURNS 
Geography EXTERNAL NAME geom."Intersection";
 --CREATE FUNCTION ST_LineToCurve RETURNS EXTERNAL NAME
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to