Changeset: 921cbbb9aa0d for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=921cbbb9aa0d
Modified Files:
        geom/monetdb5/geom.c
        geom/monetdb5/geom.h
Branch: sfcgal
Log Message:

AddPoint available at C level. Fix a bug, check if the BAT pointer is NULL.


diffs (103 lines):

diff --git a/geom/monetdb5/geom.c b/geom/monetdb5/geom.c
--- a/geom/monetdb5/geom.c
+++ b/geom/monetdb5/geom.c
@@ -3225,7 +3225,7 @@ wkbMakePolygon(wkb **out, wkb **external
        linearRingGeometry = GEOSGeom_createLinearRing(coordSeq_copy);
 
        //create a polygon using the linearRing
-       if (*internalBAT_id == 0) {
+       if (internalBAT_id == NULL && *internalBAT_id == 0) {
                geosGeometry = GEOSGeom_createPolygon(linearRingGeometry, NULL, 
0);
                if (geosGeometry == NULL) {
                        *out = NULL;
@@ -4711,6 +4711,78 @@ wkbNumGeometries(int *out, wkb **geom)
        return MAL_SUCCEED;
 }
 
+/* Add point to LineString */
+geom_export str wkbAddPoint(wkb** out, wkb** lineWKB, wkb** pointWKB) {
+    str ret = MAL_SUCCEED;
+    const GEOSCoordSequence *lineGCS;
+    GEOSCoordSeq gcs_new = NULL;
+    double x, y, z;
+    uint32_t lineDim, idx;
+    const GEOSGeometry *line;
+    GEOSGeom point, outGeometry;
+    line = wkb2geos(*lineWKB);
+    point = wkb2geos(*pointWKB);
+
+       if ( ((GEOSGeomTypeId(line) + 1) != wkbLineString_mdb) && 
((GEOSGeomTypeId(point) + 1) != wkbPoint_mdb)) {
+        *out = NULL;
+        throw(MAL, "geom.AddPoint", "It should a LineString and Point");
+    }
+
+       //get the coordinate sequences of the LineString
+       if (!(lineGCS = GEOSGeom_getCoordSeq(line))) {
+               *out = NULL;
+               throw(MAL, "geom.AddPoint", "GEOSGeom_getCoordSeq failed");
+       }
+
+       //create a copy of it
+       if ((gcs_new = GEOSCoordSeq_clone(lineGCS)) == NULL) {
+               *out = NULL;
+               throw(MAL, "geom.AddPoint", "GEOSCoordSeq_clone failed");
+       }
+
+    //Get dimension of the LineString
+       if (GEOSCoordSeq_getDimensions(gcs_new, &lineDim) == 0) {
+               *out = NULL;
+               throw(MAL, "geom.AddPoint", "GEOSGeom_getDimensions failed");
+       }
+
+    //Get dimension of the Point.
+    if ( lineDim == 3 && (GEOSHasZ(point) != 1)) {
+               *out = NULL;
+               throw(MAL, "geom.AddPoint", "LineString and Point have 
different dimensions");
+    }
+    
+    //Get Coordinates from Point
+       if (GEOSGeomGetX(point, &x) == -1 || GEOSGeomGetY(point, &y) == -1 || 
GEOSGeomGetZ(point, &z) != MAL_SUCCEED) {
+               *out = NULL;
+               throw(MAL, "geom.AddPoint", "Error in reading the points' 
coordinates");
+    }
+
+       /* get the number of points in the geometry */
+       GEOSCoordSeq_getSize(gcs_new, &idx);
+
+    //Add Point's coordinates
+       if (!GEOSCoordSeq_setX(gcs_new, idx, x))
+               throw(MAL, "geom.AddPoint", "GEOSCoordSeq_setX failed");
+       if (!GEOSCoordSeq_setY(gcs_new, idx, y))
+               throw(MAL, "geom.AddPoint", "GEOSCoordSeq_setY failed");
+       if (lineDim > 2)
+               if (!GEOSCoordSeq_setZ(gcs_new, idx, z))
+                       throw(MAL, "geom.AddPoint", "GEOSCoordSeq_setZ failed");
+
+    //Create new LineString
+       if (!(outGeometry = GEOSGeom_createLineString(gcs_new))) {
+               *out = NULL;
+               throw(MAL, "geom.AddPoint", "GEOSGeom_createLineString failed");
+       }
+
+       GEOSSetSRID(outGeometry, GEOSGetSRID(line));
+       *out = geos2wkb(outGeometry);
+    
+    return ret;
+}
+
+
 /* MBR */
 
 /* Creates the mbr for the given geom_geometry. */
diff --git a/geom/monetdb5/geom.h b/geom/monetdb5/geom.h
--- a/geom/monetdb5/geom.h
+++ b/geom/monetdb5/geom.h
@@ -218,6 +218,8 @@ geom_export str wkbGeometryN_bat(bat *ou
 geom_export str wkbNumGeometries(int* out, wkb** geom);
 geom_export str wkbNumGeometries_bat(bat *outBAT_id, bat *inBAT_id);
 
+geom_export str wkbAddPoint(wkb**, wkb**, wkb**);
+
 geom_export str wkbTransform(wkb**, wkb**, int*, int*, char**, char**);
 geom_export str wkbTranslate(wkb**, wkb**, dbl*, dbl*, dbl*);
 geom_export str wkbDelaunayTriangles(wkb**, wkb**, dbl*, int*);
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to