Changeset: 7117fb704d8d for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=7117fb704d8d
Added Files:
geom/sql/Tests/asEWKT.sql
geom/sql/Tests/asEWKT.stable.err
geom/sql/Tests/asEWKT.stable.out
geom/sql/Tests/boundary.sql
geom/sql/Tests/boundary.stable.err
geom/sql/Tests/boundary.stable.out
geom/sql/Tests/dimension.sql
geom/sql/Tests/dimension.stable.err
geom/sql/Tests/dimension.stable.out
Modified Files:
geom/monetdb5/geom.c
geom/monetdb5/geom.mal
geom/sql/40_geom.sql
geom/sql/Tests/All
Branch: geo
Log Message:
function for asEWKT added + mTests for boundary dimension and asEWKT
diffs (truncated from 813 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
@@ -105,7 +105,7 @@ geom_export str wkbDimension(int*, wkb**
geom_export str wkbGeometryType(char**, wkb**, int*);
geom_export str wkbGetSRID(int*, wkb**);
//Envelope
-geom_export str wkbAsText(str*, wkb**);
+geom_export str wkbAsText(char**, wkb**, int*);
//AsBinary
geom_export str wkbIsEmpty(bit*, wkb**);
geom_export str wkbIsSimple(bit*, wkb**);
@@ -1189,10 +1189,58 @@ str wkbFromText(wkb **geomWKB, str *geom
}
/*create textual representation of the wkb */
-str wkbAsText(str *txt, wkb **geomWKB) {
+str wkbAsText(char **txt, wkb **geomWKB, int* withSRID) {
int len =0;
- if(wkbTOSTR(txt, &len, *geomWKB))
+ char* wkt;
+
+ if(wkbTOSTR(&wkt, &len, *geomWKB)) {
+ if(*withSRID == 0) {
+ *txt = GDKmalloc(strlen(wkt));
+ if(*txt == NULL) {
+ GDKfree(wkt);
+ throw(MAL, "geom.wkbAsText", MAL_MALLOC_FAIL);
+ }
+ strcpy(*txt, wkt);
+ } else {
+ char* sridTxt = "SRID:";
+ char* sridIntToString = NULL;
+ int len = 0;
+
+ //count the number of digits in srid
+ int tmp = (*geomWKB)->srid;
+ int digitsNum =0;
+ while(tmp > 0) {
+ tmp/=10;
+ digitsNum++;
+ }
+
+ sridIntToString = GDKmalloc(digitsNum+1);
+ if(sridIntToString == NULL) {
+ GDKfree(wkt);
+ throw(MAL, "geom.wkbAsText", MAL_MALLOC_FAIL);
+ }
+ sprintf(sridIntToString, "%d", (*geomWKB)->srid);
+
+ len =
strlen(wkt)+strlen(sridIntToString)+strlen(sridTxt)+2;
+ *txt = GDKmalloc(len);
+ if(*txt == NULL) {
+ GDKfree(wkt);
+ GDKfree(sridIntToString);
+ throw(MAL, "geom.wkbAsText", MAL_MALLOC_FAIL);
+ }
+
+ memcpy(*txt, sridTxt, strlen(sridTxt));
+ memcpy(*txt+strlen(sridTxt), sridIntToString,
strlen(sridIntToString));
+ (*txt)[strlen(sridTxt)+strlen(sridIntToString)] = ';';
+ memcpy(*txt+strlen(sridTxt)+strlen(sridIntToString)+1,
wkt, strlen(wkt));
+ (*txt)[len-1] = '\0';
+
+ GDKfree(sridIntToString);
+ }
+
+ GDKfree(wkt);
return MAL_SUCCEED;
+ }
throw(MAL, "geom.AsText", "Failed to create Text from Well Known
Format");
}
diff --git a/geom/monetdb5/geom.mal b/geom/monetdb5/geom.mal
--- a/geom/monetdb5/geom.mal
+++ b/geom/monetdb5/geom.mal
@@ -46,6 +46,7 @@ command heap() :int address wkbHEAP;
#command wkb{unsafe}(v:str) :wkb address wkbFromString;
command FromText{unsafe}(wkt:str, srid:int, type:int) :wkb address
wkbFromText;
+command ToText(w:wkb, withSRID:int) :str address wkbAsText;
module geom;
@@ -63,8 +64,20 @@ comment "Returns the number of interior
#Geometry Constructors
-command AsText(w:wkb) :str address wkbAsText
-comment "Creates the text representation of the Geometry.";
+#command AsText(w:wkb) :str address wkbAsText
+#comment "Creates the text representation of the Geometry.";
+#command AsEWKT(w:wkb) :str address wkbAsEWKT
+#comment "Returns the text representation of the geometry including the srid";
+
+function AsText(w:wkb) :str;
+ x := wkb.ToText(w,0);
+ return x;
+end AsText;
+function AsEWKT(w:wkb) :str;
+ x := wkb.ToText(w,1);
+ return x;
+end AsEWKT;
+
function GeomFromText{unsafe}(wkt:str, srid:int) :wkb;
x := wkb.FromText(wkt,srid,0);
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
@@ -4200,7 +4200,7 @@ END;
-------------------------------------------------------------------------
--CREATE FUNCTION ST_AsBinary RETURNS EXTERNAL NAME
--CREATE FUNCTION ST_AsEWKB RETURNS EXTERNAL NAME
---CREATE FUNCTION ST_AsEWKT RETURNS EXTERNAL NAME
+CREATE FUNCTION ST_AsEWKT(geom Geometry) RETURNS string EXTERNAL NAME
geom."AsEWKT";
--CREATE FUNCTION ST_AsGeoJSON RETURNS EXTERNAL NAME
--CREATE FUNCTION ST_AsGML RETURNS EXTERNAL NAME
--CREATE FUNCTION ST_AsHEXEWKB RETURNS EXTERNAL NAME
@@ -4208,7 +4208,7 @@ END;
--CREATE FUNCTION ST_AsSVG RETURNS EXTERNAL NAME
--CREATE FUNCTION ST_AsX3D RETURNS EXTERNAL NAME
--CREATE FUNCTION ST_GeoHash RETURNS EXTERNAL NAME
-CREATE FUNCTION ST_AsText(g Geometry) RETURNS string EXTERNAL NAME
geom."AsText";
+CREATE FUNCTION ST_AsText(geom Geometry) RETURNS string EXTERNAL NAME
geom."AsText";
--CREATE FUNCTION ST_AsLatLonText RETURNS EXTERNAL NAME
-------------------------------------------------------------------------
diff --git a/geom/sql/Tests/All b/geom/sql/Tests/All
--- a/geom/sql/Tests/All
+++ b/geom/sql/Tests/All
@@ -21,5 +21,6 @@ numRings
transform
contains
equals
-
-
+boundary
+dimension
+asEWKT
diff --git a/geom/sql/Tests/asEWKT.sql b/geom/sql/Tests/asEWKT.sql
new file mode 100644
--- /dev/null
+++ b/geom/sql/Tests/asEWKT.sql
@@ -0,0 +1,58 @@
+select st_asEWKT(st_pointfromtext('point(10 10)'));
+select st_asEWKT(st_pointfromtext('point(20 20)', 4326));
+select st_asEWKT(st_pointfromtext('point(10 10 10)'));
+select st_asEWKT(st_makepoint(10, 10));
+select st_asEWKT(st_point(20, 20));
+select st_asEWKT(st_makepoint(10, 10, 10));
+select st_asEWKT(st_linefromtext('linestring(10 10, 20 20, 30 30)'));
+select st_asEWKT(st_linefromtext('linestring(20 20, 30 30, 40 40)', 4326));
+select st_asEWKT(st_linefromtext('linestring(20 20 20, 30 30 30, 40 40 40)',
4326));
+select st_asEWKT(st_polygonfromtext('polygon((10 10, 20 20, 30 30, 10 10))'));
+select st_asEWKT(st_polygonfromtext('polygon((20 20, 30 30, 40 40, 20 20))',
4326));
+select st_asEWKT(st_polygonfromtext('polygon((10 10 10, 20 20 20, 30 30 30, 10
10 10))'));
+select st_asEWKT(st_mpointfromtext('multipoint(10 10, 20 20)'));
+select st_asEWKT(st_mpointfromtext('multipoint(20 20, 30 30)', 4326));
+select st_asEWKT(st_mpointfromtext('multipoint(20 20 20, 30 30 30)', 4326));
+select st_asEWKT(st_mlinefromtext('multilinestring((10 10, 20 20, 30 30), (40
40, 50 50, 60 60))'));
+select st_asEWKT(st_mlinefromtext('multilinestring((20 20, 30 30, 40 40), (50
50, 60 60, 70 70))', 4326));
+select st_asEWKT(st_mlinefromtext('multilinestring((20 20 20, 30 30 30, 40 40
40), (50 50 50, 60 60 60, 70 70 70))', 4326));
+select st_asEWKT(st_mpolyfromtext('multipolygon(((10 10, 20 20, 30 30, 10
10),(100 100, 200 200, 300 300, 100 100)))'));
+select st_asEWKT(st_mpolyfromtext('multipolygon(((20 20, 30 30, 40 40, 20
20),(200 200, 300 300, 400 400, 200 200)))', 4326));
+select st_asEWKT(st_mpolyfromtext('multipolygon(((10 10 10, 20 20 20, 30 30
30, 10 10 10),(100 100 100, 200 200 200, 300 300 300, 100 100 100)))'));
+
+select st_asEWKT(st_geomfromtext('point(10 10)'));
+select st_asEWKT(st_geomfromtext('linestring(10 10, 20 20, 30 30)'));
+select st_asEWKT(st_geomfromtext('polygon((10 10, 20 20, 30 30, 10 10))'));
+select st_asEWKT(st_geomfromtext('multipoint(10 10, 20 20)'));
+select st_asEWKT(st_geomfromtext('multilinestring((10 10, 20 20, 30 30), (40
40, 50 50, 60 60))'));
+select st_asEWKT(st_geomfromtext('multipolygon(((10 10, 20 20, 30 30, 10
10),(100 100, 200 200, 300 300, 100 100)))'));
+
+create table points_tbl(g geometry(point));
+insert into points_tbl values (st_pointfromtext('point(10 10)'));
+select st_asEWKT(g) from points_tbl;
+drop table points_tbl;
+
+create table lines_tbl(g geometry(linestring));
+insert into lines_tbl values (st_linefromtext('linestring(10 10, 20 20, 30
30)'));
+select st_asEWKT(g) from lines_tbl;
+drop table lines_tbl;
+
+create table polygons_tbl(g geometry(polygon));
+insert into polygons_tbl values (st_polygonfromtext('polygon((10 10, 20 20, 30
30, 10 10))'));
+select st_asEWKT(g) from polygons_tbl;
+drop table polygons_tbl;
+
+create table points_tbl(g geometry(pointz));
+insert into points_tbl values (st_pointfromtext('point(10 10 10)'));
+select st_asEWKT(g) from points_tbl;
+drop table points_tbl;
+
+create table lines_tbl(g geometry(linestringz));
+insert into lines_tbl values (st_linefromtext('linestring(10 10 10, 20 20 20,
30 30 30)'));
+select st_asEWKT(g) from lines_tbl;
+drop table lines_tbl;
+
+create table polygons_tbl(g geometry(polygonz));
+insert into polygons_tbl values (st_polygonfromtext('polygon((10 10 10, 20 20
20, 30 30 30, 10 10 10))'));
+select st_asEWKT(g) from polygons_tbl;
+drop table polygons_tbl;
diff --git a/geom/sql/Tests/asEWKT.stable.err b/geom/sql/Tests/asEWKT.stable.err
new file mode 100644
--- /dev/null
+++ b/geom/sql/Tests/asEWKT.stable.err
@@ -0,0 +1,36 @@
+stderr of test 'asEWKT` in directory 'geom/sql` itself:
+
+
+# 12:59:30 >
+# 12:59:30 > "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set"
"mapi_open=true" "--set" "mapi_port=31607" "--set"
"mapi_usock=/var/tmp/mtest-13998/.s.monetdb.31607" "--set" "monet_prompt="
"--forcemito" "--set" "mal_listing=2"
"--dbpath=/export/scratch1/alvanaki/INSTALL/monetdb/var/MonetDB/mTests_geom_sql"
"--set" "mal_listing=0"
+# 12:59:30 >
+
+# builtin opt gdk_dbpath =
/export/scratch1/alvanaki/INSTALL/monetdb/var/monetdb5/dbfarm/demo
+# builtin opt gdk_debug = 0
+# builtin opt gdk_vmtrim = no
+# builtin opt monet_prompt = >
+# builtin opt monet_daemon = no
+# builtin opt mapi_port = 50000
+# builtin opt mapi_open = false
+# builtin opt mapi_autosense = false
+# builtin opt sql_optimizer = default_pipe
+# builtin opt sql_debug = 0
+# cmdline opt gdk_nr_threads = 0
+# cmdline opt mapi_open = true
+# cmdline opt mapi_port = 31607
+# cmdline opt mapi_usock = /var/tmp/mtest-13998/.s.monetdb.31607
+# cmdline opt monet_prompt =
+# cmdline opt mal_listing = 2
+# cmdline opt gdk_dbpath =
/export/scratch1/alvanaki/INSTALL/monetdb/var/MonetDB/mTests_geom_sql
+# cmdline opt mal_listing = 0
+# cmdline opt gdk_debug = 536870922
+
+# 12:59:31 >
+# 12:59:31 > "mclient" "-lsql" "-ftest" "-Eutf-8" "-i" "-e"
"--host=/var/tmp/mtest-13998" "--port=31607"
+# 12:59:31 >
+
+
+# 12:59:32 >
+# 12:59:32 > "Done."
+# 12:59:32 >
+
diff --git a/geom/sql/Tests/asEWKT.stable.out b/geom/sql/Tests/asEWKT.stable.out
new file mode 100644
--- /dev/null
+++ b/geom/sql/Tests/asEWKT.stable.out
@@ -0,0 +1,286 @@
+stdout of test 'asEWKT` in directory 'geom/sql` itself:
+
+
+# 12:59:30 >
+# 12:59:30 > "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set"
"mapi_open=true" "--set" "mapi_port=31607" "--set"
"mapi_usock=/var/tmp/mtest-13998/.s.monetdb.31607" "--set" "monet_prompt="
"--forcemito" "--set" "mal_listing=2"
"--dbpath=/export/scratch1/alvanaki/INSTALL/monetdb/var/MonetDB/mTests_geom_sql"
"--set" "mal_listing=0"
+# 12:59:30 >
+
+# MonetDB 5 server v11.18.0
+# This is an unreleased version
+# Serving database 'mTests_geom_sql', using 8 threads
+# Compiled for x86_64-unknown-linux-gnu/64bit with 64bit OIDs dynamically
linked
+# Found 15.356 GiB available main-memory.
+# Copyright (c) 1993-July 2008 CWI.
+# Copyright (c) August 2008-2014 MonetDB B.V., all rights reserved
+# Visit http://www.monetdb.org/ for further information
+# Listening for connection requests on mapi:monetdb://sibuyan.da.cwi.nl:31607/
+# Listening for UNIX domain connection requests on
mapi:monetdb:///var/tmp/mtest-13998/.s.monetdb.31607
+# MonetDB/GIS module loaded
+# MonetDB/SQL module loaded
+
+Ready.
+# SQL catalog created, loading sql scripts once
+# loading sql script: 09_like.sql
+# loading sql script: 10_math.sql
+# loading sql script: 11_times.sql
+# loading sql script: 12_url.sql
+# loading sql script: 13_date.sql
+# loading sql script: 14_inet.sql
+# loading sql script: 15_querylog.sql
+# loading sql script: 16_tracelog.sql
+# loading sql script: 19_cluster.sql
+# loading sql script: 20_vacuum.sql
+# loading sql script: 21_dependency_functions.sql
+# loading sql script: 22_clients.sql
+# loading sql script: 23_skyserver.sql
+# loading sql script: 24_zorder.sql
+# loading sql script: 25_debug.sql
+# loading sql script: 26_sysmon.sql
+# loading sql script: 39_analytics.sql
+# loading sql script: 40_geom.sql
+# loading sql script: 40_json.sql
+# loading sql script: 41_jsonstore.sql
+# loading sql script: 45_uuid.sql
+# loading sql script: 46_gsl.sql
+# loading sql script: 75_storagemodel.sql
+# loading sql script: 80_statistics.sql
+# loading sql script: 80_udf.sql
+# loading sql script: 99_system.sql
+#WARNING To speedup geom.AsEWKT a bulk operator implementation is needed
+#WARNING To speedup geom.AsEWKT a bulk operator implementation is needed
+#WARNING To speedup geom.AsEWKT a bulk operator implementation is needed
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list