Changeset: e233e5b3f7cf for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=e233e5b3f7cf
Modified Files:
geom/monetdb5/geom.c
geom/monetdb5/geom.h
geom/monetdb5/geom.mal
geom/sql/40_geom.sql
Branch: sfcgal
Log Message:
ST_AddPoint is now complete. By default it adds a point at the beginning of a
linestring if no position is indicated.
diffs (166 lines):
diff --git a/geom/monetdb5/geom.c b/geom/monetdb5/geom.c
--- a/geom/monetdb5/geom.c
+++ b/geom/monetdb5/geom.c
@@ -4712,36 +4712,34 @@ wkbNumGeometries(int *out, wkb **geom)
}
/* Add point to LineString */
-geom_export str wkbAddPoint(wkb** out, wkb** lineWKB, wkb** pointWKB) {
+str
+wkbAddPointIdx(wkb** out, wkb** lineWKB, wkb** pointWKB, int *idxPoint) {
str ret = MAL_SUCCEED;
- const GEOSCoordSequence *lineGCS;
+ const GEOSCoordSequence *gcs_old = NULL;
GEOSCoordSeq gcs_new = NULL;
- double x, y, z;
- uint32_t lineDim, idx;
+ double px, py, pz, x, y, z;
+ uint32_t lineDim, numGeom, i, idx = 0, jump = 0;
const GEOSGeometry *line;
GEOSGeom point, outGeometry;
line = wkb2geos(*lineWKB);
point = wkb2geos(*pointWKB);
+ if (idxPoint)
+ idx = *idxPoint;
+
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))) {
+ if (!(gcs_old = 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) {
+ if (GEOSCoordSeq_getDimensions(gcs_old, &lineDim) == 0) {
*out = NULL;
throw(MAL, "geom.AddPoint", "GEOSGeom_getDimensions failed");
}
@@ -4751,24 +4749,54 @@ geom_export str wkbAddPoint(wkb** out, w
*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) {
+ if (GEOSGeomGetX(point, &px) == -1 || GEOSGeomGetY(point, &py) == -1 ||
GEOSGeomGetZ(point, &pz) != 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");
+ GEOSCoordSeq_getSize(gcs_old, &numGeom);
+
+ if ((gcs_new = GEOSCoordSeq_create(numGeom+1, lineDim)) == NULL) {
+ *out = NULL;
+ throw(MAL, "geom.AddPoint", "GEOSCoordSeq_create failed");
+ }
+
+ /* Add the rest of the points */
+ for (i = 0; i < numGeom+1; i++) {
+ if (i == idx) {
+ //Add Point's coordinates
+ if (!GEOSCoordSeq_setX(gcs_new, i, px))
+ throw(MAL, "geom.AddPoint", "GEOSCoordSeq_setX failed");
+ if (!GEOSCoordSeq_setY(gcs_new, i, py))
+ throw(MAL, "geom.AddPoint", "GEOSCoordSeq_setY failed");
+ if (lineDim > 2)
+ if (!GEOSCoordSeq_setZ(gcs_new, i, pz))
+ throw(MAL, "geom.AddPoint", "GEOSCoordSeq_setZ failed");
+ /*You are doing a jump of one unit in the array indice*/
+ jump = 1;
+ } else {
+ if (!GEOSCoordSeq_getX(gcs_old, i-jump, &x))
+ throw(MAL, "geom.AddPoint", "GEOSCoordSeq_getX failed");
+
+ if (!GEOSCoordSeq_getY(gcs_old, i-jump, &y))
+ throw(MAL, "geom.AddPoint", "GEOSCoordSeq_getY failed");
+
+ if (!GEOSCoordSeq_setX(gcs_new, i, x))
+ throw(MAL, "geom.AddPoint", "GEOSCoordSeq_setX failed");
+
+ if (!GEOSCoordSeq_setY(gcs_new, i, y))
+ throw(MAL, "geom.AddPoint", "GEOSCoordSeq_setY failed");
+
+ if (lineDim > 2) {
+ GEOSCoordSeq_getZ(gcs_old, i-jump, &z);
+ if (!GEOSCoordSeq_setZ(gcs_new, i, z))
+ throw(MAL, "geom.AddPoint", "GEOSCoordSeq_setZ failed");
+ }
+ }
+ }
//Create new LineString
if (!(outGeometry = GEOSGeom_createLineString(gcs_new))) {
@@ -4782,6 +4810,10 @@ geom_export str wkbAddPoint(wkb** out, w
return ret;
}
+str
+wkbAddPoint(wkb** out, wkb** lineWKB, wkb** pointWKB) {
+ return wkbAddPointIdx(out, lineWKB, pointWKB, 0);
+}
/* MBR */
diff --git a/geom/monetdb5/geom.h b/geom/monetdb5/geom.h
--- a/geom/monetdb5/geom.h
+++ b/geom/monetdb5/geom.h
@@ -219,6 +219,7 @@ geom_export str wkbNumGeometries(int* ou
geom_export str wkbNumGeometries_bat(bat *outBAT_id, bat *inBAT_id);
geom_export str wkbAddPoint(wkb**, wkb**, wkb**);
+geom_export str wkbAddPointIdx(wkb**, wkb**, wkb**, int* idx);
geom_export str wkbTransform(wkb**, wkb**, int*, int*, char**, char**);
geom_export str wkbTranslate(wkb**, wkb**, dbl*, dbl*, dbl*);
diff --git a/geom/monetdb5/geom.mal b/geom/monetdb5/geom.mal
--- a/geom/monetdb5/geom.mal
+++ b/geom/monetdb5/geom.mal
@@ -325,7 +325,9 @@ comment "Returns the 1-based Nth geometr
command NumGeometries(g:wkb) :int address wkbNumGeometries
comment "Returns the number of geometries";
command AddPoint(w:wkb, p:wkb) :wkb address wkbAddPoint
-comment "Adds a new point to a Linestring.";
+comment "Adds a new point to position 0 of a Linestring.";
+command AddPointIdx(w:wkb, p:wkb, idx:int) :wkb address wkbAddPointIdx
+comment "Adds a new point to position idx of a Linestring.";
command Transform(g:wkb, srid_src:int, srid_dst:int, proj_src:str,
proj_dest:str) :wkb address wkbTransform
comment "Transforms a geometry from one srid to another";
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
@@ -4231,7 +4231,8 @@ CREATE FUNCTION ST_YMin(box mbr) RETURNS
-------------------------------------------------------------------------
--------------------------- Geometry Editors ----------------------------
-------------------------------------------------------------------------
-CREATE FUNCTION ST_AddPoint(geom Geometry, point Geometry) RETURNS Geometry
EXTERNAL NAME geom."AddPoint";
+CREATE FUNCTION ST_AddPoint(geom Geometry, pt Geometry) RETURNS Geometry
EXTERNAL NAME geom."AddPoint";
+CREATE FUNCTION ST_AddPoint(geom Geometry, pt Geometry, idx int) RETURNS
Geometry EXTERNAL NAME geom."AddPointIdx";
--CREATE FUNCTION ST_Affine RETURNS EXTERNAL NAME
CREATE FUNCTION ST_Force2D(geom Geometry) RETURNS Geometry EXTERNAL NAME
geom."Force2D";
CREATE FUNCTION ST_Force3D(geom Geometry) RETURNS Geometry EXTERNAL NAME
geom."Force3D";
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list