Changeset: 301d3795916a for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=301d3795916a
Modified Files:
        geom/monetdb5/geom.c
        geom/monetdb5/geomBulk.c
        geom/monetdb5/geom_x3d.c
Branch: sfcgal
Log Message:

Handle the case where a BAT has zero records. However, a more robust way to 
handling NULL or empty Geometries is required. In X3D check if it is a Point or 
a LineString, if the latter you iterate over its points otherwise not.


diffs (91 lines):

diff --git a/geom/monetdb5/geom.c b/geom/monetdb5/geom.c
--- a/geom/monetdb5/geom.c
+++ b/geom/monetdb5/geom.c
@@ -4356,12 +4356,23 @@ wkbUnionAggr(wkb **outWKB, bat *inBAT_id
        BAT *inBAT = NULL;
        BATiter inBAT_iter;
        BUN i;
+    wkb *geomWKB = wkbNULL();
        str err;
 
        //get the BATs
        if (!(inBAT = BATdescriptor(*inBAT_id))) {
                throw(MAL, "geom.Union", "Problem retrieving BATs");
        }
+
+    /*TODO: We need a better way to handle the cases where the BAT was 
created, but it has zero elements*/
+    if (!BATcount(inBAT)) {
+               BBPunfix(inBAT->batCacheid);
+               if ((err = wkbUnion(outWKB,&geomWKB, &geomWKB)) != MAL_SUCCEED) 
{
+                       BBPunfix(inBAT->batCacheid);
+                       return err;
+               }
+        return MAL_SUCCEED;
+    }
        //check if the BATs are dense and aligned
        if (!BAThdense(inBAT)) {
                BBPunfix(inBAT->batCacheid);
@@ -4374,6 +4385,7 @@ wkbUnionAggr(wkb **outWKB, bat *inBAT_id
        for (i = BUNfirst(inBAT); i < BUNfirst(inBAT) + 1; i += 2) {
                wkb *aWKB = NULL, *bWKB = NULL;
 
+        /*TODO: check if the BAT only has one elemente in that case report 
error*/
                aWKB = (wkb *) BUNtail(inBAT_iter, i + BUNfirst(inBAT));
                bWKB = (wkb *) BUNtail(inBAT_iter, i + 1 + BUNfirst(inBAT));
 
diff --git a/geom/monetdb5/geomBulk.c b/geom/monetdb5/geomBulk.c
--- a/geom/monetdb5/geomBulk.c
+++ b/geom/monetdb5/geomBulk.c
@@ -974,6 +974,8 @@ wkbMakePoint_bat(bat *outBAT_id, bat *xB
                pointWKB = NULL;
        }
 
+       //set the number of elements in the outBAT
+       BATsetcount(outBAT, BATcount(xBAT));
        BBPkeepref(*outBAT_id = outBAT->batCacheid);
 
       clean:
diff --git a/geom/monetdb5/geom_x3d.c b/geom/monetdb5/geom_x3d.c
--- a/geom/monetdb5/geom_x3d.c
+++ b/geom/monetdb5/geom_x3d.c
@@ -709,7 +709,7 @@ geom_toX3D3(const GEOSGeometry *geom, ch
     char x[OUT_MAX_DIGS_DOUBLE+OUT_MAX_DOUBLE_PRECISION+1];
     char y[OUT_MAX_DIGS_DOUBLE+OUT_MAX_DOUBLE_PRECISION+1];
     char z[OUT_MAX_DIGS_DOUBLE+OUT_MAX_DOUBLE_PRECISION+1];
-    uint32_t npoints = 0;
+    uint32_t npoints = -1;
     numPointsGeometry(&npoints, geom);
 
     ptr = output;
@@ -720,8 +720,14 @@ geom_toX3D3(const GEOSGeometry *geom, ch
         {
             if ( !is_closed || i < (npoints - 1) )
             {
-                GEOSGeom point = (GEOSGeom) GEOSGeomGetPointN(geom, i);
+                const GEOSGeometry *point = NULL;
                 double pt_x, pt_y;
+                if (GEOSGeomTypeId(geom) == GEOS_POINT) {
+                    point = geom;
+                } else {
+                    assert(GEOSGeomTypeId(geom) == GEOS_LINESTRING);
+                    point = GEOSGeomGetPointN(geom, i);
+                }
                 GEOSGeomGetX(point, &pt_x);
                 GEOSGeomGetY(point, &pt_y);
 
@@ -753,8 +759,14 @@ geom_toX3D3(const GEOSGeometry *geom, ch
         {
             if ( !is_closed || i < (npoints - 1) )
             {
-                GEOSGeom point = (GEOSGeom) GEOSGeomGetPointN(geom, i);
+                const GEOSGeometry *point = NULL;
                 double pt_x, pt_y, pt_z = 0.0;
+                if (GEOSGeomTypeId(geom) == GEOS_POINT) {
+                    point = geom;
+                } else {
+                    assert(GEOSGeomTypeId(geom) == GEOS_LINESTRING);
+                    point = GEOSGeomGetPointN(geom, i);
+                }
                 GEOSGeomGetX(point, &pt_x);
                 GEOSGeomGetY(point, &pt_y);
                 if (GEOSHasZ(point) == 1)
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to