Changeset: 1c264f83fcd1 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=1c264f83fcd1
Modified Files:
geom/monetdb5/geom.c
geom/monetdb5/geom.mal
geom/sql/40_geom.sql
Branch: geo
Log Message:
wkbFromBinary
diffs (235 lines):
diff --git a/geom/monetdb5/geom.c b/geom/monetdb5/geom.c
--- a/geom/monetdb5/geom.c
+++ b/geom/monetdb5/geom.c
@@ -107,6 +107,7 @@ geom_export str wkbGetSRID(int*, wkb**);
//Envelope
geom_export str wkbAsText(char**, wkb**, int*);
geom_export str wkbAsBinary(char**, wkb**);
+geom_export str wkbFromBinary(wkb**, char**);
geom_export str wkbIsEmpty(bit*, wkb**);
geom_export str wkbIsSimple(bit*, wkb**);
//Is3D
@@ -771,6 +772,7 @@ wkb* geos2wkb(const GEOSGeometry* geosGe
*geomWKB = *wkbNULL();
return geomWKB;
}
+ assert(wkbLen <= GDK_int_max);
geomWKB = GDKmalloc(wkb_size(wkbLen));
//If malloc failed create a NULL wkb
@@ -781,7 +783,6 @@ wkb* geos2wkb(const GEOSGeometry* geosGe
return geomWKB;
}
- assert(wkbLen <= GDK_int_max);
geomWKB->len = (int) wkbLen;
geomWKB->srid = GEOSGetSRID(geosGeometry);
memcpy(&geomWKB->data, w, wkbLen);
@@ -999,28 +1000,112 @@ int wkbFROMSTR(char* geomWKT, int* len,
//Returns the wkb in a hex representation */
static char hexit[] = "0123456789ABCDEF";
-str wkbAsBinary(char **tostr, wkb **geomWKB) {
+str wkbAsBinary(char **toStr, wkb **geomWKB) {
char *s;
int i;
if(wkb_isnil(*geomWKB)) {
- *tostr = (str) GDKmalloc(1);
- **tostr = '\0';
+ *toStr = (str) GDKmalloc(1);
+ **toStr = '\0';
return MAL_SUCCEED;
}
- *tostr = (str) GDKmalloc(1+((*geomWKB)->len)*2);
-
- s = *tostr;
+ *toStr = (str) GDKmalloc(1+((*geomWKB)->len)*2);
+
+ s = *toStr;
for (i = 0; i < (*geomWKB)->len; i++) {
int val = ((*geomWKB)->data[i] >> 4) & 0xf;
*s++ = hexit[val];
val = (*geomWKB)->data[i] & 0xf;
*s++ = hexit[val];
+//fprintf(stderr, "%d First: %c - Second: %c ==> Original %c (%d)\n", i,
*(s-2), *(s-1), (*geomWKB)->data[i], (int)((*geomWKB)->data[i]));
}
*s = '\0';
return MAL_SUCCEED;
}
+static int decit(char hex) {
+ switch(hex) {
+ case '0':
+ return 0;
+ break;
+ case '1':
+ return 1;
+ break;
+ case '2':
+ return 2;
+ break;
+ case '3':
+ return 3;
+ break;
+ case '4':
+ return 4;
+ break;
+ case '5':
+ return 5;
+ break;
+ case '6':
+ return 6;
+ break;
+ case '7':
+ return 7;
+ break;
+ case '8':
+ return 8;
+ break;
+ case '9':
+ return 9;
+ break;
+ case 'A':
+ return 10;
+ break;
+ case 'B':
+ return 11;
+ break;
+ case 'C':
+ return 12;
+ break;
+ case 'D':
+ return 13;
+ break;
+ case 'E':
+ return 14;
+ break;
+ case 'F':
+ return 15;
+ break;
+ default:
+ return -1;
+ }
+}
+str wkbFromBinary(wkb** geomWKB, char **inStr) {
+ size_t strLength = 0, wkbLength = 0, i;
+ char* s;
+
+ strLength = strlen(*inStr);
+
+ wkbLength = strLength/2;
+ assert(wkbLength <= GDK_int_max);
+
+ s = (char*)GDKmalloc(wkbLength);
+
+ //compute the value for s
+ for(i=0; i<strLength; i+=2) {
+ char firstHalf = (decit((*inStr)[i]) << 4) & 0xf0; //make sure
that only the four most significant bits may be 1
+ char secondHalf = decit((*inStr)[i+1]) & 0xf; //make sure that
only the four least significant bits may be 1
+ s[i/2] = firstHalf | secondHalf; //concatenate the two halfs to
create the final byte
+//fprintf(stderr, "%zd First: %c - Second: %c ==> Final: %c (%d)\n", i,
(*inStr)[i], (*inStr)[i+1], s[i/2], (int)s[i/2]);
+ }
+
+ *geomWKB = GDKmalloc(wkb_size(wkbLength));
+ (*geomWKB)->len = (int) wkbLength;
+ (*geomWKB)->srid = 0;
+ memcpy(&(*geomWKB)->data, s, wkbLength);
+ GDKfree(s);
+
+
+ return MAL_SUCCEED;
+}
+
/* Creates the string representation (WKT) of a WKB */
/* return length of resulting string. */
int wkbTOSTR(char **geomWKT, int* len, wkb *geomWKB) {
diff --git a/geom/monetdb5/geom.mal b/geom/monetdb5/geom.mal
--- a/geom/monetdb5/geom.mal
+++ b/geom/monetdb5/geom.mal
@@ -68,7 +68,8 @@ comment "Returns the number of interior
#Geometry Constructors
command AsBinary(w:wkb) :str address wkbAsBinary
comment "Returns the wkb representation into HEX format";
-
+command FromBinary(w:str) :wkb address wkbFromBinary
+comment "Creates a wkb using the HEX representation";
#command AsText(w:wkb) :str address wkbAsText
#comment "Creates the text representation of the Geometry.";
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
@@ -4024,7 +4024,7 @@ CREATE FUNCTION mbr(geom Geometry) RETUR
CREATE FUNCTION ST_WKTToSQL(wkt string) RETURNS Geometry external name
geom."GeomFromText";
--Construct a Geoemtry from a WKB
---CREATE FUNCTION ST_WKBToSQL(wkb_arr WHATEVER_IS_STORED_IN_DB) RETURNS
Geometry EXTERNAL NAME geom."GeomFromWKB";
+CREATE FUNCTION ST_WKBToSQL(geom string) RETURNS Geometry EXTERNAL NAME
geom."FromBinary";
--Obtaining WKT from Geometry
CREATE FUNCTION ST_AsText(geom Geometry) RETURNS string EXTERNAL NAME
geom."AsText";
@@ -4041,7 +4041,7 @@ CREATE FUNCTION ST_IsEmpty(geom Geometry
CREATE FUNCTION ST_IsSimple(geom Geometry) RETURNS boolean EXTERNAL NAME
geom."IsSimple";
CREATE FUNCTION ST_Boundary(geom Geometry) RETURNS Geometry EXTERNAL NAME
geom."Boundary";
CREATE FUNCTION ST_Envelope(geom Geometry) RETURNS Geometry EXTERNAL NAME
geom."Envelope";
---Functions regarding relations between Geometries
+--Functions testing spatial relations between Geometries
CREATE FUNCTION ST_Equals(geom1 Geometry, geom2 Geometry) RETURNS boolean
EXTERNAL NAME geom."Equals";
CREATE FUNCTION ST_Disjoint(geom1 Geometry, geom2 Geometry) RETURNS boolean
EXTERNAL NAME geom."Disjoint";
CREATE FUNCTION ST_Intersects(geom1 Geometry, geom2 Geometry) RETURNS boolean
EXTERNAL NAME geom."Intersects";
@@ -4053,7 +4053,7 @@ CREATE FUNCTION ST_Overlaps(geom1 Geomet
CREATE FUNCTION ST_Relate(geom1 Geometry, geom2 Geometry,
intersection_matrix_pattern string) RETURNS boolean EXTERNAL NAME geom."Relate";
--Distance between Geometries
CREATE FUNCTION ST_Distance(geom1 Geometry, geom2 Geometry) RETURNS double
EXTERNAL NAME geom."Distance";
---Performing set theoretic operations
+--Functions that implement spatial operators
CREATE FUNCTION ST_Intersection(geom1 Geometry, geom2 Geometry) RETURNS
Geometry EXTERNAL NAME geom."Intersection";
CREATE FUNCTION ST_Difference(geom1 Geometry, geom2 Geometry) RETURNS Geometry
EXTERNAL NAME geom."Differnce";
CREATE FUNCTION ST_Union(geom1 Geometry, geom2 Geometry) RETURNS Geometry
EXTERNAL NAME geom."Union";
@@ -4071,6 +4071,7 @@ CREATE FUNCTION ST_StartPoint(geom Geome
CREATE FUNCTION ST_EndPoint(geom Geometry) RETURNS Geometry EXTERNAL NAME
geom."EndPoint";
CREATE FUNCTION ST_IsRing(geom Geometry) RETURNS boolean EXTERNAL NAME
geom."IsRing";
CREATE FUNCTION ST_Length(geom Geometry) RETURNS double EXTERNAL NAME
geom."Length"; --valid also for MultiCurve
+CREATE FUNCTION ST_IsClosed(geom Geometry) RETURNS boolean EXTERNAL NAME
geom."IsClosed"; --valid also for MultiCurve
--Functions on LineString
CREATE FUNCTION ST_NumPoints(geom Geometry) RETURNS integer EXTERNAL NAME
geom."NumPoints";
@@ -4093,13 +4094,16 @@ CREATE FUNCTION ST_InteriorRingN(geom Ge
--CREATE FUNCTION ST_Geometries(geom Geometry) RETURNS TABLE(geom Geometries)
EXTERNAL NAME geom."Geometries";
--CREATE FUNCTION NumSurfaces(geom Geometry) RETURNS integer EXTERNAL NAME
geom."NumSurfaces";
--CREATE FUNCTION Surface(positionNum integer) RETURNS Geometry EXTERNAL NAME
geom."SurfaceN";
+--from Part 1
+--CREATE FUNCTION ST_NumPatches(geom Geometry) RETURNS integer EXTERNAL NAME
--works only with polyhedral surface
+--CREATE FUNCTION ST_PatchN(geom Geometry, patchNum integer) RETURNS Geometry
EXTERNAL NAME --works with polyhedral surface
+--BoundingPolygons
+--IsClosed
--Functions on GeomCollection
CREATE FUNCTION ST_NumGeometries(geom Geometry) RETURNS integer EXTERNAL NAME
geom."NumGeometries";
CREATE FUNCTION ST_GeometryN(geom Geometry, positionNum integer) RETURNS
Geometry EXTERNAL NAME geom."GeometryN";
---Functions on MultiCurve
-CREATE FUNCTION ST_IsClosed(geom Geometry) RETURNS boolean EXTERNAL NAME
geom."IsClosed";
----------------
-- DEPRECATED --
@@ -4130,6 +4134,9 @@ CREATE FUNCTION ST_GeomCollFromText(wkt
--CREATE FUNCTION ST_BdMPolyFromWKB(wkb_raw WHATEVER_IS_STORED_IN_DB, srid
integer) RETURNS Geometry external name geom."BdMPolyFromWKB";
+-------------
+-- PostGIS --
+-------------
-------------------------------------------------------------------------
------------------------- Geometry Constructors -------------------------
@@ -4205,8 +4212,6 @@ CREATE FUNCTION ST_IsValidReason(geom Ge
--CREATE FUNCTION ST_NPoints(geom Geometry) RETURNS integer EXTERNAL NAME geom;
CREATE FUNCTION ST_NRings(geom Geometry) RETURNS integer EXTERNAL NAME
geom."NRings"; --is meaningfull for polygon and multipolygon
CREATE FUNCTION ST_NumInteriorRings(geom Geometry) RETURNS integer EXTERNAL
NAME geom."NumInteriorRings";
---CREATE FUNCTION ST_NumPatches(geom Geometry) RETURNS integer EXTERNAL NAME
--works only with polyhedral surface
---CREATE FUNCTION ST_PatchN(geom Geometry, patchNum integer) RETURNS Geometry
EXTERNAL NAME --works with polyhedral surface
--CREATE FUNCTION ST_Summary(geom Geometry) RETURNS string EXTERNAL NAME
CREATE FUNCTION ST_XMax(geom Geometry) RETURNS double EXTERNAL NAME
geom."XMaxFromWKB";
CREATE FUNCTION ST_XMax(box mbr) RETURNS double EXTERNAL NAME
geom."XMaxFromMBR";
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list