Changeset: 15c74f6662c2 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/15c74f6662c2
Added Files:
        geom/sql/40_geom_OGC.sql
        geom/sql/40_geom_PostGIS.sql
Modified Files:
        geom/lib/libgeom.c
        geom/lib/libgeom.h
        geom/monetdb5/CMakeLists.txt
        geom/monetdb5/cleanup.md
        geom/monetdb5/geod.c
        geom/monetdb5/geod.h
        geom/monetdb5/geom.c
        geom/monetdb5/geom.h
        geom/monetdb5/geomBulk.c
        geom/sql/40_geom.sql
Branch: geo-update
Log Message:

Split up SQL functions


diffs (truncated from 3681 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
@@ -52,6 +52,25 @@ is_wkb_nil(const wkb *w)
        return 0;
 }
 
+/* returns the size of variable-sized atom wkb */
+var_t
+wkb_size(size_t len)
+{
+       if (len == ~(size_t) 0)
+               len = 0;
+       assert(offsetof(wkb, data) + len <= VAR_MAX);
+       return (var_t) (offsetof(wkb, data) + len);
+}
+
+wkb *
+wkbNULLcopy(void)
+{
+       wkb *n = GDKmalloc(sizeof(wkb_nil));
+       if (n)
+               *n = wkb_nil;
+       return n;
+}
+
 GEOSGeom
 wkb2geos(const wkb *geomWKB)
 {
@@ -68,6 +87,45 @@ wkb2geos(const wkb *geomWKB)
        return geosGeometry;
 }
 
+/* create the WKB out of the GEOSGeometry
+ * It makes sure to make all checks before returning
+ * the input geosGeometry should not be altered by this function
+ * return NULL on error */
+wkb *
+geos2wkb(const GEOSGeometry *geosGeometry)
+{
+       size_t wkbLen = 0;
+       unsigned char *w = NULL;
+       wkb *geomWKB;
+
+       // if the geosGeometry is NULL create a NULL WKB
+       if (geosGeometry == NULL) {
+               return wkbNULLcopy();
+       }
+
+       GEOS_setWKBOutputDims(GEOSGeom_getCoordinateDimension(geosGeometry));
+       w = GEOSGeomToWKB_buf(geosGeometry, &wkbLen);
+
+       if (w == NULL)
+               return NULL;
+
+       assert(wkbLen <= GDK_int_max);
+
+       geomWKB = GDKmalloc(wkb_size(wkbLen));
+       //If malloc failed create a NULL wkb
+       if (geomWKB == NULL) {
+               GEOSFree(w);
+               return NULL;
+       }
+
+       geomWKB->len = (int) wkbLen;
+       geomWKB->srid = GEOSGetSRID(geosGeometry);
+       memcpy(&geomWKB->data, w, wkbLen);
+       GEOSFree(w);
+
+       return geomWKB;
+}
+
 const char *
 geom_type2str(int t, int flag)
 {
diff --git a/geom/lib/libgeom.h b/geom/lib/libgeom.h
--- a/geom/lib/libgeom.h
+++ b/geom/lib/libgeom.h
@@ -132,7 +132,14 @@ libgeom_export void libgeom_exit(void);
 
 #define mbr_nil mbrFromGeos(NULL);
 
+/* variables */
+int TYPE_mbr;
+static const wkb wkb_nil = { ~0, 0 };
+
 libgeom_export bool is_wkb_nil(const wkb *wkbp);
+libgeom_export var_t wkb_size(size_t len);
+libgeom_export wkb * wkbNULLcopy(void);
 libgeom_export GEOSGeom wkb2geos(const wkb *geomWKB);
+libgeom_export wkb * geos2wkb(const GEOSGeometry *geosGeometry);
 
 #endif /* LIBGEOM_H */
diff --git a/geom/monetdb5/CMakeLists.txt b/geom/monetdb5/CMakeLists.txt
--- a/geom/monetdb5/CMakeLists.txt
+++ b/geom/monetdb5/CMakeLists.txt
@@ -11,6 +11,8 @@ if(GEOS_FOUND)
 
   set(include_sql_files
     40_geom
+    40_geom_PostGIS
+    40_geom_OGC
     spatial_ref_sys)
 
   create_include_object(
@@ -24,6 +26,11 @@ if(GEOS_FOUND)
     geom.c
     geomBulk.c
     geom_upgrade.c
+    geod.c
+    geom_io.c
+    mbr.c
+    wkb.c
+    wkba.c
     ${MONETDB_CURRENT_SQL_SOURCES}
     PUBLIC
     ${geomodule_public_headers})
diff --git a/geom/monetdb5/cleanup.md b/geom/monetdb5/cleanup.md
--- a/geom/monetdb5/cleanup.md
+++ b/geom/monetdb5/cleanup.md
@@ -1,4 +1,20 @@
-## Clean up of geom module
+# geom module cleanup
+## Structure
+### C functions
+- **geod.c** -> Geodetic functions
+- **wkb.c** -> WKB atom functions
+- **wkba.c** -> WKBA atom functions + functions that use WKBA
+- **mbr.c** -> MBR atom functions + functions that use WKBA
+- **geom_srid.c** -> Projection functions + SRID functions
+- **geomBulk.c** -> Bulk functions
+- **geom_io.c** -> Geometry input/output functions
+
+### SQL
+- **40_geom.sql** -> Geodetic + mbr funtcions -> TODO Cleanup
+- **40_geom_OGC.sql** -> OGC Simple Features functions
+- **40_geom_PostGIS.sql** -> PostGIS functions
+
+## Changes
 ### Removed C functions:
 - geometryHasZ/geoHasZ
 - geometryHasM/geoHasM
@@ -13,6 +29,13 @@
 - HasZ
 - HasM
 - get_type
+- wkbIsnil (no usages, libgeom.c has *is_wkb_nil*)
+- ST_M
+- ST_CurveToLine
+- Functions that were commented out:
+    - ST_GeomFromWKB (and similar geometry-specific functions)
+    - ST_GeomFromText (and similar geometry-specific functions)
+    - ST_SetInteriorRings
 
 ### Moved:
 - Moved spatial_ref_sys and geometry_columns tables to **spatial_ref_sys.sql**
@@ -21,3 +44,40 @@
 - Moved Geodetic headers to **geod.h** 
 - Moved MBR functions (including atom functions) to **mbr.c** (MAL functions 
still on geom.c)
 - Moved MBR headers to **mbr.h**
+- Moved WKBA functions to **wkba.c** (MAL functions still on geom.c)
+- Moved WKBA headers to **wkba.h**
+- Merged *geoGetType* into *wkbGeometryType* (geoGetType wasn't being used 
outside of this func)
+- Moved WKB atom functions to **wkb.c**
+- OGC sql functions to **40_geom_OGC.sql**
+- PostGIS sql functions to **40_geom_PostGIS.sql**
+- Moved geos2wkb C function to **libgeom.c** (is used in a lot of modules)
+
+
+### Other changes:
+- **MBR** atom functions are now on the header file (mbr.h) and are *not 
static*
+- **WKBA** atom functions are now on the header file (wkba.h) and are *not 
static*
+- **WKB** atom functions are now on the header file (wkb.h) and are *not 
static*
+
+## TODO:
+- Remove libgeom.c/.h ? (or add a file with the start up and end functions + 
MAL ones?)
+- Clean mbr.c
+- Clean wkba.c
+- Clean geomBulk.c (and change name?)
+- Clean geom_srid.c
+- Clean geod.c
+- Clean geom_io.c
+- Should we allow z and m in constructor functions? (e.g. ST_MakePoint)
+- SQL Clean:
+    - Functions on Polyhedral Surfaces
+    - Management functions
+    - PostGIS Geometry Constructors
+    - PostGIS Geometry Editors
+    - PostGIS SQL functions in general
+    - PostGIS from "Operators" onwards (most aren't implemented)
+
+## Check with Stefanos
+- Changing atom functions to other files (mbr and wkba)
+- Should we keep wkba (and even mbr?)
+- Header include standards (everything on the .h, some includes in the .c?)
+- How to remove libgeom
+- Check the SQL division
diff --git a/geom/monetdb5/geod.c b/geom/monetdb5/geod.c
--- a/geom/monetdb5/geod.c
+++ b/geom/monetdb5/geod.c
@@ -1,3 +1,4 @@
+#include "geom.h"
 #include "geod.h"
 
 /**
@@ -1270,8 +1271,6 @@ FP_EQUALS (double x, double y)
        return fabs(x-y) < 1e-12;
 }
 
-//TODO Uncomment
-/*
 str
 geodeticEdgeBoundingBox(const CartPoint3D* p1, const CartPoint3D* p2, 
BoundingBox* mbox)
 {
@@ -1338,4 +1337,3 @@ geodeticEdgeBoundingBox(const CartPoint3
        }
        return MAL_SUCCEED;
 }
-*/
diff --git a/geom/monetdb5/geod.h b/geom/monetdb5/geod.h
--- a/geom/monetdb5/geod.h
+++ b/geom/monetdb5/geod.h
@@ -1,5 +1,3 @@
-#include "geom.h"
-
 /* Geographic data types */
 //Bounding box of a geographic shape
 typedef struct BoundingBox {
@@ -62,3 +60,5 @@ str wkbDWithinGeographicJoin(bat *lres_i
 str wkbIntersectsGeographic(bit* out, wkb** a, wkb** b);
 str wkbIntersectsGeographicSelect(bat* outid, const bat *bid , const bat *sid, 
wkb **wkb_const, bit *anti);
 str wkbIntersectsGeographicJoin(bat *lres_id, bat *rres_id, const bat *l_id, 
const bat *r_id, const bat *ls_id, const bat *rs_id, bit *nil_matches, lng 
*estimate, bit *anti);
+
+str geodeticEdgeBoundingBox(const CartPoint3D* p1, const CartPoint3D* p2, 
BoundingBox* mbox);
diff --git a/geom/monetdb5/geom.c b/geom/monetdb5/geom.c
--- a/geom/monetdb5/geom.c
+++ b/geom/monetdb5/geom.c
@@ -14,742 +14,58 @@
 #include "geom.h"
 #include "geod.h"
 #include "mbr.h"
+#include "wkba.h"
+#include "wkb.h"
+#include "geom_srid.h"
+#include "geom_io.h"
 #include "gdk_logger.h"
 #include "mal_exception.h"
 
-static wkb *geos2wkb(const GEOSGeometry *geosGeometry);
-
-/** 
-* 
-* Geographic update code start
-*
-**/
-
-/**
-* Collect (Group By implementation) 
-* 
-**/
-//Gets the type of collection a single geometry should belong to
-static int
-GEOSGeom_getCollectionType (int GEOSGeom_type) {
-       //Single geometries get collected into a Multi* geometry
-       if (GEOSGeom_type == GEOS_POINT)
-               return GEOS_MULTIPOINT;
-       else if (GEOSGeom_type == GEOS_LINESTRING || GEOSGeom_type == 
GEOS_LINEARRING)
-               return GEOS_MULTILINESTRING;
-       else if (GEOSGeom_type == GEOS_POLYGON)
-               return GEOS_MULTIPOLYGON;
-       //Multi* or GeometryCollections get collected into GeometryCollections
-       else
-               return GEOS_GEOMETRYCOLLECTION;
-}
-
-/* Group By operation. Joins geometries together in the same group into a 
MultiGeometry */
-//TODO Check if the SRID is consistent within a group (right now we only use 
the first SRID)
-//TODO The number of candidates is getting wrong here
-str 
-wkbCollectAggrSubGroupedCand(bat *outid, const bat *bid, const bat *gid, const 
bat *eid, const bat *sid, const bit *skip_nils)
+#include "gdk_geomlogger.h"
+
+/* initialize geos */
+str
+geom_prelude(void *ret)
 {
-       BAT *b = NULL, *g = NULL, *s = NULL, *out = NULL;
-       BAT *sortedgroups, *sortedorder, *sortedinput;
-       BATiter bi;
-       const oid *gids = NULL;
-       str msg = MAL_SUCCEED;
-       const char *err;
-
-       oid min, max;
-       BUN ngrp, ncand;
-       struct canditer ci;
-
-       oid lastGrp = -1;
-       int geomCollectionType = -1;
-       BUN geomCount = 0;
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to