[postgis-users] exterior rings in multipolygons

Sandro Santilli strk at keybit.net
Mon Jul 25 13:44:04 PDT 2011


On Mon, Jul 25, 2011 at 03:40:34PM -0500, Mr. Puneet Kishor wrote:
> Please help me understand the following
> 
> ====
> SELECT 
>     ST_Nrings(the_geom) nr, 
>     ST_NumInteriorRings(the_geom) nir, 
>     ST_AsText(the_geom) WKT 
> FROM table 
> WHERE objectid = 280;
> 
> nr  nir  WKT
> --  ---  ----------------------------------------------------------------
>  4    3  "MULTIPOLYGON(((..),(..),(..),(..)))"
> 
> ====
> 
> Looking at the above, I am assuming the first (..) is the exterior ring, and the remaning three (..) are the 3 interior rings. However,
> 
> ====
> SELECT ST_ExteriorRing(the_geom) er  
> FROM table 
> WHERE objectid = 280;
> 
> ERROR: ExteriorRing: geom is not a polygon
> ====
> 
> 
> So, what is going on? Of course, the docs say that ST_ExteriorRing doesn't work on a MULTIPOLYGON. So, is the above only an implementation anomaly, and I can treat the first ring as an exterior ring? Or, is it really something else?

All your rings are wrapper in another pair of parens, which identify
a component of the MULTIPOLYGON, that is a POLYGON. You must extract
the Polygon to use ST_ExteriorRing against it. So your query would be:

 SELECT ST_ExteriorRing(ST_GeometryN(the_geom,1)) er
 FROM table
 WHERE objectid = 280;

--strk; 

  ()   Free GIS & Flash consultant/developer
  /\   http://strk.keybit.net/services.html



More information about the postgis-users mailing list