Opened 4 years ago

Closed 2 years ago

#2283 closed defect (fixed)

shp2pgsql may be parsing shp's multipolygon incorrectly

Reported by: qtxie Owned by: mcayland
Priority: high Milestone: PostGIS 2.2.0
Component: loader/dumper Version: trunk
Keywords: multipolygon Cc:

Description

I find shp2pgsql may be parsing shp's multipolygon incorrectly, which will generate two overlapped innter rings. Please see the picture in attachment.

The algorithm to put the inner rings into the list of the outer rings may be wrong. In function:

file: shp2pgsql-core.c
int
FindPolygons(SHPObject *obj, Ring ***Out);
{
    ...
    /* Put the inner rings into the list of the outer rings */
    /* of which they are within */
    for (pi = 0; pi < in_index; pi++)
    {
        // May be wrong to do those.
        // Some inner rings insert to the wrong outer ring
        ....
    }

According 'ESRI_shapefile_technical_description.pdf', the rings along with a outer ring is the inner rings belong with it, so we don't need to find the inner ring manually.

Attachments (2)

hole_correct.JPG (22.8 KB) - added by qtxie 4 years ago.
Correct split the multipolygon
hole_wrong.JPG (22.3 KB) - added by qtxie 4 years ago.
Incorrect split the multipolygon

Download all attachments as: .zip

Change History (8)

Changed 4 years ago by qtxie

Attachment: hole_correct.JPG added

Correct split the multipolygon

Changed 4 years ago by qtxie

Attachment: hole_wrong.JPG added

Incorrect split the multipolygon

comment:1 Changed 4 years ago by robe

Milestone: PostGIS 2.0.4

comment:2 Changed 4 years ago by robe

Milestone: PostGIS 2.0.4PostGIS 2.1.1

comment:3 Changed 4 years ago by robe

Milestone: PostGIS 2.1.1PostGIS 2.2.0

sounds complicated -- too much so for a micro release

comment:4 Changed 2 years ago by pramsey

Confirmed, this polygon

MULTIPOLYGON(
 ((0 0,100 0,100 100,0 100,0 0),(10 10,90 10,90 90,10 90,10 10)),
 ((20 20,20 80,80 80,80 20,20 20),(30 30,30 70,70 70,70 30,30 30))
)

when exported to shape and then reimported, turns into this one

MULTIPOLYGON(
 ((0 0,0 100,100 100,100 0,0 0),(10 10,90 10,90 90,10 90,10 10),(30 30,70 30,70 70,30 70,30 30)),
 ((20 20,20 80,80 80,80 20,20 20))
)

comment:5 Changed 2 years ago by pramsey

Fixed in 2.1 at r13932

comment:6 Changed 2 years ago by pramsey

Resolution: fixed
Status: newclosed

Fixed in trunk at r13933

Note: See TracTickets for help on using tickets.