Changeset: 517fb3a6d3c9 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=517fb3a6d3c9
Added Files:
geom/sql/Tests/functions/Tests/ST_NPoints.sql
geom/sql/Tests/functions/Tests/ST_NPoints.stable.err
geom/sql/Tests/functions/Tests/ST_NPoints.stable.out
geom/sql/Tests/functions/Tests/ST_NumPoints.sql
geom/sql/Tests/functions/Tests/ST_NumPoints.stable.err
geom/sql/Tests/functions/Tests/ST_NumPoints.stable.out
Removed Files:
geom/sql/Tests/functions/Tests/numPoints.sql
geom/sql/Tests/functions/Tests/numPoints.stable.err
geom/sql/Tests/functions/Tests/numPoints.stable.out
Modified Files:
geom/monetdb5/geom.c
geom/monetdb5/geom.h
geom/monetdb5/geom.mal
geom/monetdb5/geomBulk.c
geom/sql/Tests/functions/Tests/All
geom/sql/Tests/functions/Tests/ST_GeomFromText.stable.err
geom/sql/Tests/functions/Tests/ST_LineFromText.stable.err
geom/sql/Tests/functions/Tests/ST_MLineFromText.stable.err
geom/sql/Tests/functions/Tests/ST_MPointFromText.stable.err
geom/sql/Tests/functions/Tests/ST_MPolygonFromText.stable.err
geom/sql/Tests/functions/Tests/ST_MakeBox2D.stable.err
geom/sql/Tests/functions/Tests/ST_MakePoint.stable.err
geom/sql/Tests/functions/Tests/ST_PointFromText.stable.err
geom/sql/Tests/functions/Tests/ST_PolygonFromText.stable.err
Branch: geo
Log Message:
ST_NumPoints + ST_NPoints : bulk + mtest
diffs (truncated from 1275 to 300 lines):
diff --git a/geom/monetdb5/geom.c b/geom/monetdb5/geom.c
--- a/geom/monetdb5/geom.c
+++ b/geom/monetdb5/geom.c
@@ -1557,9 +1557,9 @@ static str dumpPointsPoint(BAT* idBAT, B
}
static str dumpPointsLineString(BAT* idBAT, BAT* geomBAT, const GEOSGeometry*
geosGeometry, char* path) {
- unsigned int pointsNum = 0;
+ int pointsNum = 0;
str err;
- unsigned int i=0;
+ int i=0;
int check = 0;
unsigned int lvl =0;
@@ -1746,7 +1746,7 @@ str wkbDumpPoints(int* idBAT_id, int* ge
BAT *idBAT = NULL, *geomBAT = NULL;
GEOSGeom geosGeometry;
int check =0;
- unsigned int pointsNum;
+ int pointsNum;
str err;
char *path = NULL;
@@ -2186,7 +2186,7 @@ str wkbAsText(char **txt, wkb **geomWKB,
char* wkt;
if(wkbTOSTR(&wkt, &len, *geomWKB)) {
- if(*withSRID == 0) {
+ if(!withSRID || *withSRID == 0) { //accepting NULL withSRID to
make easier the internal use of it
*txt = GDKmalloc(strlen(wkt));
if(*txt == NULL) {
GDKfree(wkt);
@@ -3081,10 +3081,12 @@ static str numPointsGeometry(unsigned in
/* Returns the number of points in a geometry */
-str wkbNumPoints(unsigned int *out, wkb **geom, int *check) {
+str wkbNumPoints(int *out, wkb **geom, int *check) {
GEOSGeom geosGeometry = wkb2geos(*geom);
int geometryType = 0;
str err = MAL_SUCCEED;
+ char* geomSTR = NULL;
+ unsigned int pointsNum;
if (!geosGeometry) {
*out = int_nil;
@@ -3096,17 +3098,30 @@ str wkbNumPoints(unsigned int *out, wkb
if (*check && geometryType != wkbLineString) {
*out = int_nil;
GEOSGeom_destroy(geosGeometry);
- return createException(MAL, "geom.NumPoints", "Geometry not a
LineString");
- }
-
- if((err = numPointsGeometry(out, geosGeometry)) != MAL_SUCCEED) {
+
+ if((err = wkbAsText(&geomSTR, geom, NULL)) != MAL_SUCCEED) {
+ str msg = createException(MAL, "geom.NumPoints", "%s",
err);
+ GDKfree(err);
+ return msg;
+ }
+ return createException(MAL, "geom.NumPoints", "Geometry %s not
a LineString", geomSTR);
+ }
+
+ if((err = numPointsGeometry(&pointsNum, geosGeometry)) != MAL_SUCCEED) {
str msg = createException(MAL, "geom.NumPoints", "%s", err);
GDKfree(err);
*out = int_nil;
GEOSGeom_destroy(geosGeometry);
return msg;
}
-
+
+ if(pointsNum > INT_MAX) {
+ GEOSGeom_destroy(geosGeometry);
+ *out = int_nil;
+ return createException(MAL, "geom.NumPoints", "Overflow");
+ }
+
+ *out = pointsNum;
GEOSGeom_destroy(geosGeometry);
return MAL_SUCCEED;
diff --git a/geom/monetdb5/geom.h b/geom/monetdb5/geom.h
--- a/geom/monetdb5/geom.h
+++ b/geom/monetdb5/geom.h
@@ -177,7 +177,10 @@ geom_export str wkbGetCoordY(double*, wk
geom_export str wkbGetCoordZ(double*, wkb**);
geom_export str wkbStartPoint(wkb **out, wkb **geom);
geom_export str wkbEndPoint(wkb **out, wkb **geom);
-geom_export str wkbNumPoints(unsigned int *out, wkb **geom, int *check);
+
+geom_export str wkbNumPoints(int *out, wkb **geom, int *check);
+geom_export str wkbNumPoints_bat(bat *outBAT_id, bat *inBAT_id, int* flag);
+
geom_export str wkbPointN(wkb **out, wkb **geom, int *n);
geom_export str wkbEnvelope(wkb **out, wkb **geom);
geom_export str wkbEnvelopeFromCoordinates(wkb** out, double* xmin, double*
ymin, double* xmax, double* ymax, int* srid);
diff --git a/geom/monetdb5/geom.mal b/geom/monetdb5/geom.mal
--- a/geom/monetdb5/geom.mal
+++ b/geom/monetdb5/geom.mal
@@ -247,8 +247,6 @@ command StartPoint(w:wkb) :wkb address w
comment "Returns the first point of a LINESTRING geometry as a POINT or NULL
if the input parameter is not a LINESTRING";
command EndPoint(w:wkb) :wkb address wkbEndPoint
comment "Returns the last point of a LINESTRING geometry as a POINT or NULL if
the input parameter is not a LINESTRING.";
-command PointsNum(w:wkb, check:int) :int address wkbNumPoints
-comment "The number of points in the Geometry. If check=1, the geometry should
be a linestring";
command PointN(w:wkb, n:int) :wkb address wkbPointN
comment "Returns the n-th point of the Geometry. Argument w should be
Linestring.";
command Envelope(w:wkb) :wkb address wkbEnvelope
@@ -367,6 +365,8 @@ function Translate(g:wkb, dx:dbl, dy:dbl
return x;
end Translate;
+command PointsNum(w:wkb, check:int) :int address wkbNumPoints
+comment "The number of points in the Geometry. If check=1, the geometry should
be a linestring";
function NumPoints(w:wkb) :int;
x := PointsNum(w, 1);
return x;
@@ -621,6 +621,17 @@ function MakePoint(x:bat[:oid,:dbl], y:b
return p;
end MakePoint;
+command PointsNum(w:bat[:oid,:wkb], check:int) :bat[:oid,:int] address
wkbNumPoints_bat
+comment "The number of points in the Geometry. If check=1, the geometry should
be a linestring";
+function NumPoints(w:bat[:oid,:wkb]) :bat[:oid,:int];
+ x := PointsNum(w, 1);
+ return x;
+end NumPoints;
+function NPoints(w:bat[:oid,:wkb]) :bat[:oid,:int];
+ x := PointsNum(w, 0);
+ return x;
+end NPoints;
+
command Boundary(w:bat[:oid,:wkb]) :bat[:oid,:wkb] address wkbBoundary_bat;
diff --git a/geom/monetdb5/geomBulk.c b/geom/monetdb5/geomBulk.c
--- a/geom/monetdb5/geomBulk.c
+++ b/geom/monetdb5/geomBulk.c
@@ -333,6 +333,7 @@ str wkbIsValid_bat(bat *outBAT_id, bat *
return wkbBitOut_bat(outBAT_id, inBAT_id, wkbIsValid,
"batgeom.wkbIsValid");
}
+
/***************************************************************************/
/*************************** IN: wkb - OUT: int ****************************/
/***************************************************************************/
@@ -390,6 +391,62 @@ str wkbDimension_bat(bat *outBAT_id, bat
}
+/***************************************************************************************/
+/*************************** IN: wkb - OUT: int - FLAG: int
****************************/
+/***************************************************************************************/
+
+str wkbNumPoints_bat(bat *outBAT_id, bat *inBAT_id, int* flag) {
+ BAT *outBAT = NULL, *inBAT = NULL;
+ wkb *inWKB = NULL;
+ BUN p =0, q =0;
+ BATiter inBAT_iter;
+
+ //get the descriptor of the BAT
+ if ((inBAT = BATdescriptor(*inBAT_id)) == NULL) {
+ throw(MAL, "batgeom.wkbNumPoints", RUNTIME_OBJECT_MISSING);
+ }
+
+ if ( inBAT->htype != TYPE_void ) { //header type of BAT not void
+ BBPreleaseref(inBAT->batCacheid);
+ throw(MAL, "batgeom.wkbNumPoints", "The arguments must have
dense and aligned heads");
+ }
+
+ //create a new for the output BAT
+ if ((outBAT = BATnew(TYPE_void, ATOMindex("int"), BATcount(inBAT),
TRANSIENT)) == NULL) {
+ BBPreleaseref(inBAT->batCacheid);
+ throw(MAL, "batgeom.wkbNumPoints", MAL_MALLOC_FAIL);
+ }
+ //set the first idx of the new BAT equal to that of the input BAT
+ BATseqbase(outBAT, inBAT->hseqbase);
+
+ //iterator over the input BAT
+ inBAT_iter = bat_iterator(inBAT);
+ BATloop(inBAT, p, q) { //iterate over all valid elements
+ str err = NULL;
+ int outSingle;
+
+ inWKB = (wkb*) BUNtail(inBAT_iter, p);
+ if ((err = wkbNumPoints(&outSingle, &inWKB, flag)) !=
MAL_SUCCEED) {
+ str msg = createException(MAL, "batgeom.wkbNumPoints",
"%s", err);
+ GDKfree(err);
+
+ BBPreleaseref(inBAT->batCacheid);
+ BBPreleaseref(outBAT->batCacheid);
+
+ return msg;
+ }
+ BUNappend(outBAT,&outSingle,TRUE); //add the result to the new
BAT
+ }
+
+ //set the number of elements in the outBAT
+ BATsetcount(outBAT, BATcount(inBAT));
+
+ BBPreleaseref(inBAT->batCacheid);
+ BBPkeepref(*outBAT_id = outBAT->batCacheid);
+
+ return MAL_SUCCEED;
+
+}
/*******************************/
/********* Two inputs **********/
diff --git a/geom/sql/Tests/functions/Tests/All
b/geom/sql/Tests/functions/Tests/All
--- a/geom/sql/Tests/functions/Tests/All
+++ b/geom/sql/Tests/functions/Tests/All
@@ -28,7 +28,10 @@ ST_IsRing #ignores Z coordinate
#srid
#geometryN
#numGeometries
-#numPoints
+
+ST_NumPoints
+ST_NPoints
+
#numRings
#transform
diff --git a/geom/sql/Tests/functions/Tests/ST_GeomFromText.stable.err
b/geom/sql/Tests/functions/Tests/ST_GeomFromText.stable.err
--- a/geom/sql/Tests/functions/Tests/ST_GeomFromText.stable.err
+++ b/geom/sql/Tests/functions/Tests/ST_GeomFromText.stable.err
@@ -29,184 +29,184 @@ stderr of test 'ST_GeomFromText` in dire
# 15:46:20 > "mclient" "-lsql" "-ftest" "-Eutf-8" "-i" "-e"
"--host=/var/tmp/mtest-9662" "--port=32350"
# 15:46:20 >
-MAPI = (monetdb) /var/tmp/mtest-21977/.s.monetdb.34895
+MAPI = (monetdb) /var/tmp/mtest-1038/.s.monetdb.38496
QUERY = insert into points_tbl values (st_geomfromtext('point(0 20)', 4326));
ERROR = !column needs geometry(4, 0) and value is geometry(4, 4326)
-MAPI = (monetdb) /var/tmp/mtest-21977/.s.monetdb.34895
+MAPI = (monetdb) /var/tmp/mtest-1038/.s.monetdb.38496
QUERY = insert into points_tbl values (st_geomfromtext('linestring(10 10, 20
20, 30 40)'));
ERROR = !column needs geometry(4, 0) and value is geometry(8, 0)
-MAPI = (monetdb) /var/tmp/mtest-21977/.s.monetdb.34895
+MAPI = (monetdb) /var/tmp/mtest-1038/.s.monetdb.38496
QUERY = insert into points_tbl values (st_geomfromtext('point(0 20)'));
ERROR = !column needs geometry(4, 4326) and value is geometry(4, 0)
-MAPI = (monetdb) /var/tmp/mtest-21977/.s.monetdb.34895
+MAPI = (monetdb) /var/tmp/mtest-1038/.s.monetdb.38496
QUERY = insert into points_tbl values (st_geomfromtext('point(0 20)', 0));
ERROR = !column needs geometry(4, 4326) and value is geometry(4, 0)
-MAPI = (monetdb) /var/tmp/mtest-21977/.s.monetdb.34895
+MAPI = (monetdb) /var/tmp/mtest-1038/.s.monetdb.38496
QUERY = insert into points_tbl values (st_geomfromtext('linestring(10 10, 20
20, 30 40)', 4329));
ERROR = !column needs geometry(4, 4326) and value is geometry(8, 4329)
-MAPI = (monetdb) /var/tmp/mtest-21977/.s.monetdb.34895
+MAPI = (monetdb) /var/tmp/mtest-1038/.s.monetdb.38496
QUERY = insert into points_tbl values (st_geomfromtext('point(0 20 20)',
4326));
ERROR = !column needs geometry(6, 0) and value is geometry(6, 4326)
-MAPI = (monetdb) /var/tmp/mtest-21977/.s.monetdb.34895
+MAPI = (monetdb) /var/tmp/mtest-1038/.s.monetdb.38496
QUERY = insert into points_tbl values (st_geomfromtext('linestring(10 10, 20
20, 30 40)'));
ERROR = !column needs geometry(6, 0) and value is geometry(8, 0)
-MAPI = (monetdb) /var/tmp/mtest-21977/.s.monetdb.34895
+MAPI = (monetdb) /var/tmp/mtest-1038/.s.monetdb.38496
QUERY = insert into points_tbl values (st_geomfromtext('point(0 20 20)'));
ERROR = !column needs geometry(6, 4326) and value is geometry(6, 0)
-MAPI = (monetdb) /var/tmp/mtest-21977/.s.monetdb.34895
+MAPI = (monetdb) /var/tmp/mtest-1038/.s.monetdb.38496
QUERY = insert into points_tbl values (st_geomfromtext('point(0 20 20)', 0));
ERROR = !column needs geometry(6, 4326) and value is geometry(6, 0)
-MAPI = (monetdb) /var/tmp/mtest-21977/.s.monetdb.34895
+MAPI = (monetdb) /var/tmp/mtest-1038/.s.monetdb.38496
QUERY = insert into points_tbl values (st_geomfromtext('linestring(10 10, 20
20, 30 40)', 4326));
ERROR = !column needs geometry(6, 4326) and value is geometry(8, 4326)
-MAPI = (monetdb) /var/tmp/mtest-21977/.s.monetdb.34895
+MAPI = (monetdb) /var/tmp/mtest-1038/.s.monetdb.38496
QUERY = insert into lines_tbl values (st_geomfromtext('linestring(20 20, 30
30, 40 40)', 4326));
ERROR = !column needs geometry(8, 0) and value is geometry(8, 4326)
-MAPI = (monetdb) /var/tmp/mtest-21977/.s.monetdb.34895
+MAPI = (monetdb) /var/tmp/mtest-1038/.s.monetdb.38496
QUERY = insert into lines_tbl values (st_geomfromtext('point(0 0)'));
ERROR = !column needs geometry(8, 0) and value is geometry(4, 0)
-MAPI = (monetdb) /var/tmp/mtest-21977/.s.monetdb.34895
+MAPI = (monetdb) /var/tmp/mtest-1038/.s.monetdb.38496
QUERY = insert into lines_tbl values (st_geomfromtext('linestring(10 10, 20
20, 30 30)'));
ERROR = !column needs geometry(8, 4326) and value is geometry(8, 0)
-MAPI = (monetdb) /var/tmp/mtest-21977/.s.monetdb.34895
+MAPI = (monetdb) /var/tmp/mtest-1038/.s.monetdb.38496
QUERY = insert into lines_tbl values (st_geomfromtext('linestring(30 30, 40
40, 50 50)', 0));
ERROR = !column needs geometry(8, 4326) and value is geometry(8, 0)
-MAPI = (monetdb) /var/tmp/mtest-21977/.s.monetdb.34895
+MAPI = (monetdb) /var/tmp/mtest-1038/.s.monetdb.38496
QUERY = insert into lines_tbl values (st_geomfromtext('point(0 0)', 4326));
ERROR = !column needs geometry(8, 4326) and value is geometry(4, 4326)
-MAPI = (monetdb) /var/tmp/mtest-21977/.s.monetdb.34895
+MAPI = (monetdb) /var/tmp/mtest-1038/.s.monetdb.38496
QUERY = insert into lines_tbl values (st_geomfromtext('linestring(20 20 20, 30
30 30, 40 40 40)', 4326));
ERROR = !column needs geometry(10, 0) and value is geometry(10, 4326)
-MAPI = (monetdb) /var/tmp/mtest-21977/.s.monetdb.34895
+MAPI = (monetdb) /var/tmp/mtest-1038/.s.monetdb.38496
QUERY = insert into lines_tbl values (st_geomfromtext('point(0 0 0)'));
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list