[postgis-users] exterior rings in multipolygons
Mr. Puneet Kishor
punk.kish at gmail.com
Mon Jul 25 14:16:02 PDT 2011
On Jul 25, 2011, at 3:44 PM, Sandro Santilli wrote:
> 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;
>
Thanks. The above works. So, does this mean that given "MULTIPOLYGON(((1),(2),(3),(4)))", 1 indeed is an exterior ring, and 2-4 are interior rings, and the "entity" does have 4 rings kinda like below?
+-------------------+
| |
| +-----+ +---+ |
| | | | 3 | |
| | 2 | +---+ |
| +-----+ |
| +--------+ |
| | | |
| 1 | 4 | |
| | | |
| +--------+ |
+-------------------+
Puneet.
More information about the postgis-users
mailing list