[postgis-users] exterior rings in multipolygons

Ben Madin lists at remoteinformation.com.au
Tue Jul 26 23:06:39 PDT 2011


G'day Puneet,

I've attached a picture of what I see - 280.shp is in fact two polygons - the top one is 280 and the bottom one 531. The numbers in black are the shapefile, those in red the postgis connection.


I ran shp2pgsql (RCSID: $Id: shp2pgsql-core.h 5983 2010-09-19 11:27:05Z mcayland $ RELEASE: 1.5 USE_GEOS=1 USE_PROJ=1 USE_STATS=1) :

warrambat:~$ shp2pgsql 280/280.shp public.pun | psql gms
Shapefile type: Polygon
Postgis type: MULTIPOLYGON[2]
SET
SET
BEGIN
NOTICE:  CREATE TABLE will create implicit sequence "pun_gid_seq" for serial column "pun.gid"
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "pun_pkey" for table "pun"
CREATE TABLE
                   addgeometrycolumn                   
-------------------------------------------------------
 public.pun.the_geom SRID:-1 TYPE:MULTIPOLYGON DIMS:2 
(1 row)

INSERT 0 1
INSERT 0 1
COMMIT

and I then tried your other query:

gms=# select objectid, ST_NumPoints(ST_InteriorRingN(ST_GeometryN(the_geom, 1), 2)) from pun;
 objectid | st_numpoints 
----------+--------------
      280 |           42
      531 |           52
(2 rows)

and for my own interest:


gms=# select objectid, st_summary(the_geom) from pun;
 objectid |           st_summary            
----------+---------------------------------
      280 |                                +
          | MultiPolygon[B] with 1 elements+
          |   Polygon[] with 4 rings       +
          |    ring 0 has 496 points       +
          |    ring 1 has 242 points       +
          |    ring 2 has 42 points        +
          |    ring 3 has 108 points       +
          | 
      531 |                                +
          | MultiPolygon[B] with 1 elements+
          |   Polygon[] with 21 rings      +
          |    ring 0 has 706 points       +
          |    ring 1 has 42 points        +
          |    ring 2 has 52 points        +
          |    ring 3 has 47 points        +
          |    ring 4 has 38 points        +
          |    ring 5 has 106 points       +
          |    ring 6 has 47 points        +
          |    ring 7 has 60 points        +
          |    ring 8 has 65 points        +
          |    ring 9 has 45 points        +
          |    ring 10 has 42 points       +
          |    ring 11 has 43 points       +
          |    ring 12 has 51 points       +
          |    ring 13 has 81 points       +
          |    ring 14 has 84 points       +
          |    ring 15 has 53 points       +
          |    ring 16 has 70 points       +
          |    ring 17 has 59 points       +
          |    ring 18 has 165 points      +
          |    ring 19 has 51 points       +
          |    ring 20 has 52 points       +
          | 
(2 rows)

I hope this helps somewhat. 

On 27/07/2011, at 1:01 PM, Mr. Puneet Kishor wrote:

> 
> On Jul 26, 2011, at 7:53 PM, Ben Madin wrote:
> 
>> Maybe you could share the polygon - does it pass tests like st_isvalid()?
> 
> it does pass the ST_IsValid() test with flying colors, but the truth is... the entire poly never got imported. So, from ArcMap, I exported poly id 280 to a shapefile. Then I opened that shapefile in QGIS, and overlaid the same poly from the Pg table. See the attached image. The orange line is the poly 280 from Pg, and the green solid is the same poly 280 from the shapefile. Most of the poly is missing in the Pg version.
> 
> The shapefile can be downloaded from http://dl.dropbox.com/u/3526821/280.zip
> 
>> 
>> cheers
>> 
>> Ben
>> 
>> 
>> On 27/07/2011, at 4:16 AM, Mr. Puneet Kishor wrote:
>> 
>>> 
>>> On Jul 26, 2011, at 9:56 AM, Sandro Santilli wrote:
>>> 
>>>> On Tue, Jul 26, 2011 at 09:47:23AM -0500, Mr. Puneet Kishor wrote:
>>>>> 
>>>>> On Jul 26, 2011, at 9:34 AM, Sandro Santilli wrote:
>>>>> 
>>>>>> On Tue, Jul 26, 2011 at 09:31:50AM -0500, Mr. Puneet Kishor wrote:
>>>>>> 
>>>>>>> 	ERROR:  function st_interiorringn(geometry) does not exist
>>>>>> 
>>>>>> Check your parens, the call above is missing a parameter (ring number).
>>>>>> 
>>>>> 
>>>>> That is a bit embarrassing. Yes, I had missed out on giving the ring number. However, still no luck --
>>>>> 
>>>>> SELECT objectid, 
>>>>> 	ST_NRings(the_geom) num_of_rings, 
>>>>> 	ST_NumInteriorRings(the_geom) num_of_int_rings, 
>>>>> 	ST_NumPoints(ST_ExteriorRing(ST_GeometryN(the_geom,1))) num_of_points_ext_ring,
>>>>> 	ST_AsText(the_geom) wkt_feature, 
>>>>> 	ST_AsText(ST_MakePolygon(ST_ExteriorRing(ST_GeometryN(the_geom, 1)))) wkt_ext_ring,
>>>>> 	ST_AsText(ST_MakePolygon(ST_InteriorRingN(ST_GeometryN(the_geom, 2), 2))) wkt_int_ring_a,
>>>>> 	ST_AsText(ST_MakePolygon(ST_GeometryN(the_geom, 2))) wkt_int_ring_b
>>>>> FROM table 
>>>>> WHERE objectid = 280;
>>>>> 
>>>>> objectid: 280;
>>>>> num_of_rings: 4;
>>>>> num_of_int_rings: 3;
>>>>> num_of_points_ext_ring: 496;
>>>>> wkt_feature: "MULTIPOLYGON(((<1>),(<2>),(<3>),(<4>))";
>>>>> wkt_ext_ring: "POLYGON((<1>))";
>>>>> wkt_int_ring_a: "";
>>>>> wkt_int_ring_b: ""
>>>>> 
>>>>> As you see, I tried to get the interior ring "n" two different ways. Not getting anywhere.
>>>> 
>>>> Write down a matrix of all combinations you tried.
>>>> Use real paper, and pencil.
>>>> Publish a scanned version.
>>>> 
>>> 
>>> So, as advised, I got a real pencil and paper, drew out all my options, scanned them in, and discovered that I had a poor understanding on the relationship of MULTIPOLYGONs and GEOMETRIES. Turns out, my MULTIPOLYGON has 1 GEOMETRY, 4 rings, one being exterior and three interior rings. Hence, an expression like the following works well
>>> 
>>> 	ST_NumPoints(ST_InteriorRingN(ST_GeometryN(the_geom, 1), 2))
>>> 	
>>> Now, here is where it gets interesting. My test feature in reality is a lot more complicated, as can be seen in the attached image (see the blue bordered multipoly). I took the shapefile and shp2pgsql-ed it, and now I get only 4 rings in my query. My guess is that these four rings are the ones on the top of the image. So, I thought maybe I have another GEOMETRY that I am missing out on. But, no... ST_NumGeometries(the_geom) = 1.
>>> 
>>> Can anyone theorize what happened to the rest of the feature? How did it get lost in translation? Was it simply ignored, or was it made into a different feature? Or, is it there, but I still haven't understood the MULTIPOLYGON/GEOMETRY/POLYGON/LINERSTRING nexus really well.
>>> 
> <280_error.png>
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20110727/8470c36a/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screen shot 2011-07-27 at 1.58.38 PM.png
Type: image/png
Size: 257711 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20110727/8470c36a/attachment.png>


More information about the postgis-users mailing list