Changeset: 02776ff8b690 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/02776ff8b690 Modified Files: geom/monetdb5/cleanup.md geom/monetdb5/geod.c geom/monetdb5/geod.h geom/monetdb5/geom.c geom/monetdb5/geom.h geom/monetdb5/geomBulk.c Branch: geo-update Log Message:
Moved MBR functions to mbr.c/mbr.h diffs (truncated from 1014 to 300 lines): diff --git a/geom/monetdb5/cleanup.md b/geom/monetdb5/cleanup.md --- a/geom/monetdb5/cleanup.md +++ b/geom/monetdb5/cleanup.md @@ -19,3 +19,5 @@ - Moved COPY INTO spatial_ref_sys to **spatial_ref_sys.sql** - Moved Geodetic functions (except bulk versions) to **geod.c** (MAL functions still on geom.c) - 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** diff --git a/geom/monetdb5/geod.c b/geom/monetdb5/geod.c --- a/geom/monetdb5/geod.c +++ b/geom/monetdb5/geod.c @@ -1270,6 +1270,8 @@ FP_EQUALS (double x, double y) return fabs(x-y) < 1e-12; } +//TODO Uncomment +/* str geodeticEdgeBoundingBox(const CartPoint3D* p1, const CartPoint3D* p2, BoundingBox* mbox) { @@ -1336,3 +1338,4 @@ 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,3 +1,5 @@ +#include "geom.h" + /* Geographic data types */ //Bounding box of a geographic shape typedef struct BoundingBox { @@ -60,6 +62,3 @@ 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); - -//TODO: Not used -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 @@ -13,6 +13,7 @@ #include "geom.h" #include "geod.h" +#include "mbr.h" #include "gdk_logger.h" #include "mal_exception.h" @@ -294,16 +295,12 @@ static const wkba wkba_nil = {.itemsNum static wkb * wkbNULLcopy(void) { - //TODO: Delete this - (void) geodeticEdgeBoundingBox; wkb *n = GDKmalloc(sizeof(wkb_nil)); if (n) *n = wkb_nil; return n; } -/* the first argument in the functions is the return variable */ - #ifdef HAVE_PROJ /* math.h files do not have M_PI defined */ @@ -2299,13 +2296,9 @@ geom_2_geom(wkb **resWKB, wkb **valueWKB return MAL_SUCCEED; } +#include "gdk_geomlogger.h" + /* initialize geos */ -/* NULL: generic nil mbr. */ -/* returns a pointer to a nil-mbr. */ -static mbr mbrNIL; /* to be filled in */ - -#include "gdk_geomlogger.h" - str geom_prelude(void *ret) { @@ -2329,13 +2322,6 @@ geom_epilogue(void *ret) return MAL_SUCCEED; } -/* Check if fixed-sized atom mbr is null */ -static bool -is_mbr_nil(const mbr *m) -{ - return (m == NULL || is_flt_nil(m->xmin) || is_flt_nil(m->ymin) || is_flt_nil(m->xmax) || is_flt_nil(m->ymax)); -} - /* returns the size of variable-sized atom wkb */ static var_t wkb_size(size_t len) @@ -2526,68 +2512,6 @@ geos2wkb(const GEOSGeometry *geosGeometr return geomWKB; } -/* gets the mbr from the geometry */ -mbr * -mbrFromGeos(const GEOSGeom geosGeometry) -{ - GEOSGeom envelope; - mbr *geomMBR; - double xmin = 0, ymin = 0, xmax = 0, ymax = 0; - - geomMBR = GDKmalloc(sizeof(mbr)); - if (geomMBR == NULL) //problem in reserving space - return NULL; - - /* if input is null or GEOSEnvelope created exception then create a nill mbr */ - if (!geosGeometry || (envelope = GEOSEnvelope(geosGeometry)) == NULL) { - *geomMBR = mbrNIL; - return geomMBR; - } - - if ((GEOSGeomTypeId(envelope) + 1) == wkbPoint_mdb) { -#if GEOS_CAPI_VERSION_MAJOR >= 1 && GEOS_CAPI_VERSION_MINOR >= 3 - const GEOSCoordSequence *coords = GEOSGeom_getCoordSeq(envelope); -#else - const GEOSCoordSeq coords = GEOSGeom_getCoordSeq(envelope); -#endif - GEOSCoordSeq_getX(coords, 0, &xmin); - GEOSCoordSeq_getY(coords, 0, &ymin); - assert(GDK_flt_min <= xmin && xmin <= GDK_flt_max); - assert(GDK_flt_min <= ymin && ymin <= GDK_flt_max); - geomMBR->xmin = (float) xmin; - geomMBR->ymin = (float) ymin; - geomMBR->xmax = (float) xmin; - geomMBR->ymax = (float) ymin; - } else { // GEOSGeomTypeId(envelope) == GEOS_POLYGON -#if GEOS_CAPI_VERSION_MAJOR >= 1 && GEOS_CAPI_VERSION_MINOR >= 3 - const GEOSGeometry *ring = GEOSGetExteriorRing(envelope); -#else - const GEOSGeom ring = GEOSGetExteriorRing(envelope); -#endif - if (ring) { -#if GEOS_CAPI_VERSION_MAJOR >= 1 && GEOS_CAPI_VERSION_MINOR >= 3 - const GEOSCoordSequence *coords = GEOSGeom_getCoordSeq(ring); -#else - const GEOSCoordSeq coords = GEOSGeom_getCoordSeq(ring); -#endif - GEOSCoordSeq_getX(coords, 0, &xmin); //left-lower corner - GEOSCoordSeq_getY(coords, 0, &ymin); - GEOSCoordSeq_getX(coords, 2, &xmax); //right-upper corner - GEOSCoordSeq_getY(coords, 2, &ymax); - assert(GDK_flt_min <= xmin && xmin <= GDK_flt_max); - assert(GDK_flt_min <= ymin && ymin <= GDK_flt_max); - assert(GDK_flt_min <= xmax && xmax <= GDK_flt_max); - assert(GDK_flt_min <= ymax && ymax <= GDK_flt_max); - geomMBR->xmin = (float) xmin; - geomMBR->ymin = (float) ymin; - geomMBR->xmax = (float) xmax; - geomMBR->ymax = (float) ymax; - } - } - GEOSGeom_destroy(envelope); - return geomMBR; -} - //Returns the wkb in a hex representation */ static char hexit[] = "0123456789ABCDEF"; @@ -2705,17 +2629,6 @@ wkbFromBinary(wkb **geomWKB, const char return MAL_SUCCEED; } -str -mbrFromMBR(mbr **w, mbr **src) -{ - *w = GDKmalloc(sizeof(mbr)); - if (*w == NULL) - throw(MAL, "calc.mbr", SQLSTATE(HY013) MAL_MALLOC_FAIL); - - **w = **src; - return MAL_SUCCEED; -} - static ssize_t wkbTOSTR(char **geomWKT, size_t *len, const void *GEOMWKB, bool external); str @@ -4772,494 +4685,6 @@ wkbNumGeometries(int *out, wkb **geom) return MAL_SUCCEED; } -/* MBR */ - -/* Creates the mbr for the given geom_geometry. */ -str -wkbMBR(mbr **geomMBR, wkb **geomWKB) -{ - GEOSGeom geosGeometry; - str ret = MAL_SUCCEED; - bit empty; - - //check if the geometry is nil - if (is_wkb_nil(*geomWKB)) { - if ((*geomMBR = GDKmalloc(sizeof(mbr))) == NULL) - throw(MAL, "geom.MBR", SQLSTATE(HY013) MAL_MALLOC_FAIL); - **geomMBR = mbrNIL; - return MAL_SUCCEED; - } - //check if the geometry is empty - if ((ret = wkbIsEmpty(&empty, geomWKB)) != MAL_SUCCEED) { - return ret; - } - if (empty) { - if ((*geomMBR = GDKmalloc(sizeof(mbr))) == NULL) - throw(MAL, "geom.MBR", SQLSTATE(HY013) MAL_MALLOC_FAIL); - **geomMBR = mbrNIL; - return MAL_SUCCEED; - } - - geosGeometry = wkb2geos(*geomWKB); - if (geosGeometry == NULL) { - *geomMBR = NULL; - throw(MAL, "geom.MBR", SQLSTATE(38000) "Geos problem converting GEOS to WKB"); - } - - *geomMBR = mbrFromGeos(geosGeometry); - - GEOSGeom_destroy(geosGeometry); - - if (*geomMBR == NULL || is_mbr_nil(*geomMBR)) { - GDKfree(*geomMBR); - *geomMBR = NULL; - throw(MAL, "wkb.mbr", SQLSTATE(38000) "Geos failed to create mbr"); - } - - return MAL_SUCCEED; -} - -str -wkbBox2D(mbr **box, wkb **point1, wkb **point2) -{ - GEOSGeom point1_geom, point2_geom; - double xmin = 0.0, ymin = 0.0, xmax = 0.0, ymax = 0.0; - str err = MAL_SUCCEED; - - //check null input - if (is_wkb_nil(*point1) || is_wkb_nil(*point2)) { - if ((*box = GDKmalloc(sizeof(mbr))) == NULL) - throw(MAL, "geom.MakeBox2D", SQLSTATE(HY013) MAL_MALLOC_FAIL); - **box = mbrNIL; - return MAL_SUCCEED; - } - //check input not point geometries - point1_geom = wkb2geos(*point1); - point2_geom = wkb2geos(*point2); - if (point1_geom == NULL || point2_geom == NULL) { - if (point1_geom) - GEOSGeom_destroy(point1_geom); - if (point2_geom) - GEOSGeom_destroy(point2_geom); - throw(MAL, "geom.MakeBox2D", SQLSTATE(HY013) MAL_MALLOC_FAIL); - } - if (GEOSGeomTypeId(point1_geom) + 1 != wkbPoint_mdb || - GEOSGeomTypeId(point2_geom) + 1 != wkbPoint_mdb) { - err = createException(MAL, "geom.MakeBox2D", SQLSTATE(38000) "Geometries should be points"); - } else if (GEOSGeomGetX(point1_geom, &xmin) == -1 || - GEOSGeomGetY(point1_geom, &ymin) == -1 || - GEOSGeomGetX(point2_geom, &xmax) == -1 || - GEOSGeomGetY(point2_geom, &ymax) == -1) { - - err = createException(MAL, "geom.MakeBox2D", SQLSTATE(38000) "Geos error in reading the points' coordinates"); - } else { - //Assign the coordinates. Ensure that they are in correct order - *box = GDKmalloc(sizeof(mbr)); - if (*box == NULL) { - err = createException(MAL, "geom.MakeBox2D", SQLSTATE(HY013) MAL_MALLOC_FAIL); - } else { - (*box)->xmin = (float) (xmin < xmax ? xmin : xmax); - (*box)->ymin = (float) (ymin < ymax ? ymin : ymax); - (*box)->xmax = (float) (xmax > xmin ? xmax : xmin); - (*box)->ymax = (float) (ymax > ymin ? ymax : ymin); - } - } - GEOSGeom_destroy(point1_geom); - GEOSGeom_destroy(point2_geom); - - return err; -} - -static str -mbrrelation_wkb(bit *out, wkb **geom1WKB, wkb **geom2WKB, str (*func)(bit *, mbr **, mbr **)) -{ - mbr *geom1MBR = NULL, *geom2MBR = NULL; - str ret = MAL_SUCCEED; - - if (is_wkb_nil(*geom1WKB) || is_wkb_nil(*geom2WKB)) { - *out = bit_nil; - return MAL_SUCCEED; - } - _______________________________________________ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org