]> granicus.if.org Git - postgis/commitdiff
GEOS no like POINT EMPTY (#1060)
authorPaul Ramsey <pramsey@cleverelephant.ca>
Wed, 29 Jun 2011 22:40:40 +0000 (22:40 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Wed, 29 Jun 2011 22:40:40 +0000 (22:40 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@7523 b70326c6-7e19-0410-871a-916f4a2858ee

postgis/lwgeom_geos.c
regress/tickets.sql
regress/tickets_expected

index 86bfc93c4585b3401f53359fe808051bfcb058cf..ca8a46468e44d0ede51f49314d2ee3ddde5b64b0 100644 (file)
@@ -3727,7 +3727,8 @@ GEOSGeometry *
 LWGEOM2GEOS(LWGEOM *lwgeom)
 {
        GEOSCoordSeq sq;
-       GEOSGeom g, shell, *geoms;
+       GEOSGeom g, shell;
+       GEOSGeom *geoms = NULL;
        /*
        LWGEOM *tmp;
        */
@@ -3749,15 +3750,31 @@ LWGEOM2GEOS(LWGEOM *lwgeom)
        
        switch (lwgeom->type)
        {
-               LWPOINT *lwp;
-               LWPOLY *lwpoly;
-               LWLINE *lwl;
-               LWCOLLECTION *lwc;
-
+               LWPOINT *lwp = NULL;
+               LWPOLY *lwpoly = NULL;
+               LWLINE *lwl = NULL;
+               LWCOLLECTION *lwc = NULL;
+               POINTARRAY *pa = NULL;
+               
        case POINTTYPE:
                lwp = (LWPOINT *)lwgeom;
-               sq = ptarray_to_GEOSCoordSeq(lwp->point);
-               g = GEOSGeom_createPoint(sq);
+               
+               if ( lwgeom_is_empty(lwgeom) )
+               {
+#if POSTGIS_GEOS_VERSION < 33
+                       pa = ptarray_construct_empty(lwgeom_has_z(lwgeom), lwgeom_has_m(lwgeom), 2);
+                       sq = ptarray_to_GEOSCoordSeq(pa);
+                       shell = GEOSGeom_createLinearRing(sq);
+                       g = GEOSGeom_createPolygon(shell, NULL, 0);
+#else
+                       g = GEOSGeom_createEmptyPolygon();
+#endif
+               }
+               else
+               {
+                       sq = ptarray_to_GEOSCoordSeq(lwp->point);
+                       g = GEOSGeom_createPoint(sq);
+               }
                if ( ! g )
                {
                        /* lwnotice("Exception in LWGEOM2GEOS"); */
@@ -3795,7 +3812,9 @@ LWGEOM2GEOS(LWGEOM *lwgeom)
                        if ( ! shell ) return NULL;
                        /*lwerror("LWGEOM2GEOS: exception during polygon shell conversion"); */
                        ngeoms = lwpoly->nrings-1;
-                       geoms = malloc(sizeof(GEOSGeom)*ngeoms);
+                       if ( ngeoms > 0 )
+                               geoms = malloc(sizeof(GEOSGeom)*ngeoms);
+
                        for (i=1; i<lwpoly->nrings; ++i)
                        {
                                sq = ptarray_to_GEOSCoordSeq(lwpoly->rings[i]);
@@ -3811,9 +3830,9 @@ LWGEOM2GEOS(LWGEOM *lwgeom)
                                /*lwerror("LWGEOM2GEOS: exception during polygon hole conversion"); */
                        }
                        g = GEOSGeom_createPolygon(shell, geoms, ngeoms);
-                       if ( ! g ) return NULL;
-                       free(geoms);
+                       if (geoms) free(geoms);
                }
+               if ( ! g ) return NULL;
                break;
        case MULTIPOINTTYPE:
        case MULTILINETYPE:
@@ -3829,8 +3848,10 @@ LWGEOM2GEOS(LWGEOM *lwgeom)
                        geostype = GEOS_GEOMETRYCOLLECTION;
 
                lwc = (LWCOLLECTION *)lwgeom;
+
                ngeoms = lwc->ngeoms;
-               geoms = malloc(sizeof(GEOSGeom)*ngeoms);
+               if ( ngeoms > 0 )
+                       geoms = malloc(sizeof(GEOSGeom)*ngeoms);
 
                for (i=0; i<ngeoms; ++i)
                {
@@ -3844,8 +3865,8 @@ LWGEOM2GEOS(LWGEOM *lwgeom)
                        geoms[i] = g;
                }
                g = GEOSGeom_createCollection(geostype, geoms, ngeoms);
+               if ( geoms ) free(geoms);
                if ( ! g ) return NULL;
-               free(geoms);
                break;
 
        default:
index 19323d2533c97cab9016f158e81682e3600e6579..d187052088fe998fb5bf1a5aff4e4f9c05f8519c 100644 (file)
@@ -387,5 +387,16 @@ DROP TABLE foo;
 -- #668 --
 select '#668',box2d('CIRCULARSTRING(10 2,12 2,14 2)'::geometry) as b;
 
+-- #711 --
+select '#711', ST_GeoHash(ST_GeomFromText('POLYGON EMPTY',4326));
+
+-- #712 --
+SELECT '#712',ST_IsValid(ST_GeomFromText('POLYGON EMPTY',4326));
+
+-- #1069 --
+select '#1060', ST_Relate(ST_GeomFromText('POINT EMPTY',4326), ST_GeomFromText('POINT EMPTY',4326)) As result;
+
+
 -- Clean up
 DELETE FROM spatial_ref_sys;
+
index 39a3ad517be173c519dde69c9539b92bb166d48f..72085d08ac4124d1ab349c5cd7d4614fc6096e7d 100644 (file)
@@ -112,3 +112,6 @@ ERROR:  First argument must be a LINESTRING
 #884|2|t
 #938|
 #668|BOX(10 2,14 2)
+#711|
+#712|t
+#1060|FFFFFFFF2