LWGEOM2GEOS(LWGEOM *lwgeom)
{
GEOSCoordSeq sq;
- GEOSGeom g, shell, *geoms;
+ GEOSGeom g, shell;
+ GEOSGeom *geoms = NULL;
/*
LWGEOM *tmp;
*/
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"); */
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]);
/*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:
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)
{
geoms[i] = g;
}
g = GEOSGeom_createCollection(geostype, geoms, ngeoms);
+ if ( geoms ) free(geoms);
if ( ! g ) return NULL;
- free(geoms);
break;
default:
-- #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;
+