[postgis-users] Testing for empty feature

Martin Davis mbdavis at refractions.net
Fri Jul 4 09:03:33 PDT 2008


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.

Kevin Neufeld wrote:
> 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
>
>
> Sean Fulton wrote:
>   
>> 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
>> postgis-users at postgis.refractions.net
>> http://postgis.refractions.net/mailman/listinfo/postgis-users
>>     
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users
>
>   

-- 
Martin Davis
Senior Technical Architect
Refractions Research, Inc.
(250) 383-3022




More information about the postgis-users mailing list