Discussion:
Testing for empty feature
Sean Fulton
2008-07-04 14:40:09 UTC
Permalink
How do I test for an empty feature such as 'MULTIPOLYGON(( EMPTY ))' ?

IsEmpty seems to work only for collections.

astext(wkb_geometry) = 'MULTIPOLYGON(( EMPTY ))' doesn't seem to work.

Thanks,

Sean
Kevin Neufeld
2008-07-04 15:32:13 UTC
Permalink
I believe that an empty multipolygon is converted into an empty
geometrycollection in JTS and hence PostGIS.


postgis=# SELECT ST_AsText('MULTIPOLYGON EMPTY'::geometry);
st_astext
--------------------------
GEOMETRYCOLLECTION EMPTY
(1 row)


postgis=# SELECT ST_IsEmpty('MULTIPOLYGON EMPTY'::geometry);
st_isempty
------------
t
(1 row)

Alternatively, I suppose you could get the number of points in the geometry.

postgis=# SELECT ST_NPoints('MULTIPOLYGON EMPTY'::geometry);
st_npoints
------------
0
(1 row)


Cheers,
Kevin
Post by Sean Fulton
How do I test for an empty feature such as 'MULTIPOLYGON(( EMPTY ))' ?
IsEmpty seems to work only for collections.
astext(wkb_geometry) = 'MULTIPOLYGON(( EMPTY ))' doesn't seem to work.
Thanks,
Sean
_______________________________________________
postgis-users mailing list
http://postgis.refractions.net/mailman/listinfo/postgis-users
Martin Davis
2008-07-04 16:03:33 UTC
Permalink
Actually JTS/GEOS handle empty MultiPolygons just fine. I don't know why
the MULTIPOLYGON EMPTY is being converted to a general
GeometryCollection - I think this must be something that is being done
by PostGIS.

Seems like the answer is to use ST_IsEmpty. Doing text comparisons is
always going to be risky.
Post by Kevin Neufeld
I believe that an empty multipolygon is converted into an empty
geometrycollection in JTS and hence PostGIS.
postgis=# SELECT ST_AsText('MULTIPOLYGON EMPTY'::geometry);
st_astext
--------------------------
GEOMETRYCOLLECTION EMPTY
(1 row)
postgis=# SELECT ST_IsEmpty('MULTIPOLYGON EMPTY'::geometry);
st_isempty
------------
t
(1 row)
Alternatively, I suppose you could get the number of points in the geometry.
postgis=# SELECT ST_NPoints('MULTIPOLYGON EMPTY'::geometry);
st_npoints
------------
0
(1 row)
Cheers,
Kevin
Post by Sean Fulton
How do I test for an empty feature such as 'MULTIPOLYGON(( EMPTY ))' ?
IsEmpty seems to work only for collections.
astext(wkb_geometry) = 'MULTIPOLYGON(( EMPTY ))' doesn't seem to work.
Thanks,
Sean
_______________________________________________
postgis-users mailing list
http://postgis.refractions.net/mailman/listinfo/postgis-users
_______________________________________________
postgis-users mailing list
http://postgis.refractions.net/mailman/listinfo/postgis-users
--
Martin Davis
Senior Technical Architect
Refractions Research, Inc.
(250) 383-3022
Sean Fulton
2008-07-06 20:43:52 UTC
Permalink
ST_IsEmpty doesn't seem to work for me and I don't see the MultiPolygon
being converted to a GeometryCollection.


civics=# SELECT astext(wkb_geometry) FROM scale150000 LIMIT 1;
astext
------------------------
MULTIPOLYGON(( EMPTY))
(1 row)

civics=# SELECT ST_IsEmpty(wkb_geometry) FROM scale150000 LIMIT 1;
st_isempty
------------
f
(1 row)

ST_NPOINTS works. It seems like there should be a more direct way.


Sean
Post by Martin Davis
Actually JTS/GEOS handle empty MultiPolygons just fine. I don't know why
the MULTIPOLYGON EMPTY is being converted to a general
GeometryCollection - I think this must be something that is being done
by PostGIS.
Seems like the answer is to use ST_IsEmpty. Doing text comparisons is
always going to be risky.
Post by Kevin Neufeld
I believe that an empty multipolygon is converted into an empty
geometrycollection in JTS and hence PostGIS.
postgis=# SELECT ST_AsText('MULTIPOLYGON EMPTY'::geometry);
st_astext
--------------------------
GEOMETRYCOLLECTION EMPTY
(1 row)
postgis=# SELECT ST_IsEmpty('MULTIPOLYGON EMPTY'::geometry);
st_isempty
------------
t
(1 row)
Alternatively, I suppose you could get the number of points in the geometry.
postgis=# SELECT ST_NPoints('MULTIPOLYGON EMPTY'::geometry);
st_npoints
------------
0
(1 row)
Cheers,
Kevin
Post by Sean Fulton
How do I test for an empty feature such as 'MULTIPOLYGON(( EMPTY ))' ?
IsEmpty seems to work only for collections.
astext(wkb_geometry) = 'MULTIPOLYGON(( EMPTY ))' doesn't seem to work.
Thanks,
Sean
_______________________________________________
postgis-users mailing list
http://postgis.refractions.net/mailman/listinfo/postgis-users
_______________________________________________
postgis-users mailing list
http://postgis.refractions.net/mailman/listinfo/postgis-users
Loading...