Changeset: e8d9508a6ebe for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=e8d9508a6ebe
Modified Files:
        geom/lib/libgeom.c
        geom/lib/libgeom.h
        geom/monetdb5/geom.c
        geom/monetdb5/geom.mal
        geom/sql/40_geom.sql
        sql/include/sql_catalog.h
Branch: geo
Log Message:

checked and added some more functions from Geometry Constructors and Geometry 
Accessors categories


diffs (truncated from 1082 to 300 lines):

diff --git a/geom/lib/libgeom.c b/geom/lib/libgeom.c
--- a/geom/lib/libgeom.c
+++ b/geom/lib/libgeom.c
@@ -130,20 +130,22 @@ const char *
 geom_type2str(int t)
 {
        switch (t) {
+       //case wkbGeometry:
+       //      return "GEOMETRY";
        case wkbPoint:
-               return "Point";
+               return "POINT";
        case wkbLineString:
-               return "Line";
+               return "LINESTRING";
        case wkbPolygon:
-               return "Polygon";
+               return "POLYGON";
        case wkbMultiPoint:
-               return "MultiPoint";
+               return "MULTIPOINT";
        case wkbMultiLineString:
-               return "MultiLine";
+               return "MULTILINESTRING";
        case wkbMultiPolygon:
-               return "MultiPolygon";
+               return "MULTIPOLYGON";
        case wkbGeometryCollection:
-               return "GeomCollection";
+               return "GEOMETRYCOLLECTION";
        }
-       return "unknown";
+       return "UKNOWN";
 }
diff --git a/geom/lib/libgeom.h b/geom/lib/libgeom.h
--- a/geom/lib/libgeom.h
+++ b/geom/lib/libgeom.h
@@ -44,6 +44,9 @@ typedef struct mbr {
        float ymin;
        float xmax;
        float ymax;
+       //mserver could not start with z coordinate
+       //float zmin;
+       //float zmax;
 } mbr;
 
 /*
@@ -94,6 +97,7 @@ 11 = MULTIPOLYGON
 */
 
 typedef enum wkb_type {
+       //wkbGeometry = 0,
        wkbPoint = 1,
        wkbLineString = 2,
        wkbPolygon = 3,
diff --git a/geom/monetdb5/geom.c b/geom/monetdb5/geom.c
--- a/geom/monetdb5/geom.c
+++ b/geom/monetdb5/geom.c
@@ -48,10 +48,13 @@
 #define GEOMETRY_HAS_Z(info)(info & 0x02)
 #define GEOMETRY_HAS_M(info)(info & 0x01)
 
+/* the first argument in the functions is the return variable */
+
 int TYPE_mbr;
 
 geom_export void geoHasZ(int* res, int* info);
 geom_export void geoHasM(int* res, int* info);
+geom_export void geoGetType(char** res, int* info);
 
 geom_export bat *geom_prelude(void);
 geom_export void geom_epilogue(void);
@@ -61,11 +64,26 @@ geom_export mbr *mbrNULL(void);
 
 geom_export int mbrFROMSTR(char *src, int *len, mbr **atom);
 geom_export int mbrTOSTR(char **dst, int *len, mbr *atom);
-geom_export int wkbFROMSTR(char *src, int *len, wkb **atom);
+geom_export int wkbFROMSTR(char *src, int srid, int *len, wkb **atom);
 geom_export int wkbTOSTR(char **dst, int *len, wkb *atom);
 geom_export str wkbFromText(wkb **w, str *wkt, int srid, int *tpe);
 geom_export str wkbAsText(str *r, wkb **w);
 
+geom_export str geomMakePoint2D(wkb**, double*, double*);
+geom_export str geomMakePoint3D(wkb**, double*, double*, double*);
+geom_export str geomMakePoint4D(wkb**, double*, double*, double*, double*);
+geom_export str geomMakePointM(wkb**, double*, double*, double*);
+
+geom_export str wkbGeometryType(char** out, wkb** geom);
+geom_export str wkbCoordDim(int *out, wkb **geom);
+geom_export str wkbDimension(int *out, wkb **geom);
+geom_export str wkbSRID(int *out, wkb **geom);
+geom_export str wkbGetCoordX(double*, wkb**);
+geom_export str wkbGetCoordY(double*, wkb**);
+geom_export str wkbGetCoordZ(double*, wkb**);
+
+geom_export str wkbIsEmpty(bit *out, wkb **geom);
+geom_export str wkbIsSimple(bit *out, wkb **geom);
 
 
 /*check if the geometry has z coordinate*/
@@ -79,6 +97,15 @@ void geoHasM(int* res, int* info) {
        if(GEOMETRY_HAS_M(*info)) *res=1;
        else *res=0;
 }
+/*check the geometry subtype*/
+/*returns the length of the resulting string*/
+void geoGetType(char** res, int* info) {
+       int type = (*info >> 2);
+       const char* typeStr=geom_type2str(type) ;
+       
+       *res=GDKmalloc(strlen(typeStr));
+       strcpy(*res, typeStr);
+}
 
 /* initialise geos */
 bat *geom_prelude(void) {
@@ -188,7 +215,7 @@ int mbrTOSTR(char **dst, int *len, mbr *
 
 /* FROMSTR: parse string to @1. */
 /* return number of parsed characters. */
-int wkbFROMSTR(char *src, int *len, wkb **atom) {
+int wkbFROMSTR(char *src, int srid, int *len, wkb **atom) {
        GEOSGeom geosGeometry = NULL;   /* The geometry object that is parsed 
from the src string. */
        unsigned char *wkbSer = NULL;   /* The "well known binary" 
serialization of the geometry object. */
        size_t wkbLen = 0;              /* The length of the wkbSer string. */
@@ -207,6 +234,12 @@ int wkbFROMSTR(char *src, int *len, wkb 
        }
 
        if (!nil) {
+               //add the srid
+               if(srid == 0 )
+                       GEOSSetSRID(geosGeometry, 4326);
+               else //should we check whether the srid exists in 
spatial_ref_sys?
+                       GEOSSetSRID(geosGeometry, srid);
+               //the srid is lost with the transformation of the GEOSGeom to 
wkb
                wkbSer = GEOSGeomToWKB_buf(geosGeometry, &wkbLen);
                GEOSGeom_destroy(geosGeometry);
        }
@@ -269,24 +302,23 @@ int wkbTOSTR(char **dst, int *len, wkb *
 }
 
 /* creates a wkb from the given textual representation */
+/*int* tpe is needed to verify that the type of the FromText function used is 
the
+ * same with the type of the geometry created from the wkt representation */
 str wkbFromText(wkb **w, str *wkt, int srid, int *tpe) {
        int len = 0, te = *tpe;
        char *errbuf;
        str ex;
-srid=1000;
-if(srid < 1000)
-       throw(MAL, "wkb.FromText", "dadsadas");
 
        *w = NULL;
-       if (wkbFROMSTR(*wkt, &len, w) &&
+       if (wkbFROMSTR(*wkt, srid, &len, w) &&
            (wkb_isnil(*w) || *tpe == wkbGeometryCollection ||
             (te = *((*w)->data + 1) & 0x0f) == *tpe))
                return MAL_SUCCEED;
        if (*w == NULL)
                *w = (wkb *) GDKmalloc(sizeof(wkb));
        **w = *wkbNULL();
-       if (te != *tpe)
-               throw(MAL, "wkb.FromText", "Trying to reaf Geometry type '%s' 
with function for Geometry type '%s'", geom_type2str(te), geom_type2str(*tpe));
+       if (*tpe > 0 && te != *tpe)
+               throw(MAL, "wkb.FromText", "Trying to read Geometry type '%s' 
with function for Geometry type '%s'", geom_type2str(te), geom_type2str(*tpe));
        errbuf = GDKerrbuf;
        if (errbuf) {
                if (strncmp(errbuf, "!ERROR: ", 8) == 0)
@@ -313,13 +345,255 @@ str wkbAsText(str *r, wkb **w) {
        throw(MAL, "geom.AsText", "Failed to create Text from Well Known 
Format");
 }
 
+static str geomMakePoint(wkb **out, GEOSGeom geosGeometry) {
+       unsigned char* wkbSer = NULL;
+       size_t wkbLen = 0;
+
+       //creates the wkbSer from the GeosGeometry structure
+       wkbSer = GEOSGeomToWKB_buf(geosGeometry, &wkbLen);
+       GEOSGeom_destroy(geosGeometry);
+
+       if(!wkbSer) {
+               **out = *wkbNULL();
+               throw(MAL, "geomMakePoint", "Failed to create wkb from 
GEOSGeometry");
+       }
+
+       assert(wkbLen <= GDK_int_max);
+       *out = GDKmalloc((int) wkb_size(wkbLen));
+
+       if(*out == NULL) {
+               **out = *wkbNULL();
+               throw(MAL, "geomMakePoint", "Failed to reserve memory for 
*wkb");
+       }
+
+       (*out)->len = (int) wkbLen;
+       memcpy(&(*out)->data, wkbSer, wkbLen);
+       GEOSFree(wkbSer);
+
+       return MAL_SUCCEED;
+}
+
+/* creates a point using the x, y coordinates */
+str geomMakePoint2D(wkb** out, double* x, double* y) {
+       GEOSGeom geosGeometry = NULL;
+
+       //create the point from the coordinates
+       GEOSCoordSequence *seq = GEOSCoordSeq_create(1, 2);
+       GEOSCoordSeq_setX(seq, 0, *x);
+       GEOSCoordSeq_setY(seq, 0, *y);
+       geosGeometry = GEOSGeom_createPoint(seq);
+
+       if(geosGeometry == NULL){
+               **out = *wkbNULL();
+               throw(MAL, "geomMakePoint", "Failed to create GEOSGeometry from 
the coordiates");
+       }
+
+       return geomMakePoint(out, geosGeometry);
+}
+
+/* creates a point using the x, y, z coordinates */
+str geomMakePoint3D(wkb** out, double* x, double* y, double* z) {
+       GEOSGeom geosGeometry = NULL;
+
+       //create the point from the coordinates
+       GEOSCoordSequence *seq = GEOSCoordSeq_create(1, 3);
+       GEOSCoordSeq_setX(seq, 0, *x);
+       GEOSCoordSeq_setY(seq, 0, *y);
+       GEOSCoordSeq_setZ(seq, 0, *z);
+       geosGeometry = GEOSGeom_createPoint(seq);
+
+       if(geosGeometry == NULL){
+               **out = *wkbNULL();
+               throw(MAL, "geomMakePoint", "Failed to create GEOSGeometry from 
the coordiates");
+       }
+
+       return geomMakePoint(out, geosGeometry);
+}
+
+/* creates a point using the x, y, z, m coordinates */
+str geomMakePoint4D(wkb** out, double* x, double* y, double* z, double* m) {
+       GEOSGeom geosGeometry = NULL;
+
+       //create the point from the coordinates
+       GEOSCoordSequence *seq = GEOSCoordSeq_create(1, 4);
+       GEOSCoordSeq_setX(seq, 0, *x);
+       GEOSCoordSeq_setY(seq, 0, *y);
+       GEOSCoordSeq_setZ(seq, 0, *z);
+       GEOSCoordSeq_setOrdinate(seq, 0, 3, *m);
+       geosGeometry = GEOSGeom_createPoint(seq);
+
+       if(geosGeometry == NULL){
+               **out = *wkbNULL();
+               throw(MAL, "geomMakePoint", "Failed to create GEOSGeometry from 
the coordiates");
+       }
+
+       return geomMakePoint(out, geosGeometry);
+}
+
+/* creates a point using the x, y, m coordinates */
+str geomMakePointM(wkb** out, double* x, double* y, double* m) {
+       GEOSGeom geosGeometry = NULL;
+
+       //create the point from the coordinates
+       GEOSCoordSequence *seq = GEOSCoordSeq_create(1, 3);
+       GEOSCoordSeq_setOrdinate(seq, 0, 0, *x);
+       GEOSCoordSeq_setOrdinate(seq, 0, 1, *y);
+       GEOSCoordSeq_setOrdinate(seq, 0, 2, *m);
+       geosGeometry = GEOSGeom_createPoint(seq);
+
+       if(geosGeometry == NULL){
+               **out = *wkbNULL();
+               throw(MAL, "geomMakePoint", "Failed to create GEOSGeometry from 
the coordiates");
+       }
+
+       return geomMakePoint(out, geosGeometry);
+}
+
+
+static str wkbbasic(int *out, wkb **geom, int (*func)(const GEOSGeometry *), 
const char *name) {
+       GEOSGeom geosGeometry = wkb2geos(*geom);
+
+       if (!geosGeometry) {
+               *out = int_nil;
+               return MAL_SUCCEED;
+       }
+
+       *out = (*func)(geosGeometry);
+
+       GEOSGeom_destroy(geosGeometry);
+
+       if (GDKerrbuf && GDKerrbuf[0])
+               throw(MAL, name, "failed");
+       return MAL_SUCCEED;
+
+}
+
+
+/* returns the type of the geometry as a string*/
+str wkbGeometryType(char** out, wkb** geom) {
+       int typeId = 0;
+       str ret = MAL_SUCCEED;
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to