From b7e1a876eb0555cbbf682b515a31d38ccaa9d46a Mon Sep 17 00:00:00 2001 From: Paul Ramsey Date: Tue, 18 Aug 2015 13:40:02 +0000 Subject: [PATCH] #2283, shp2pgsql may be parsing shp's multipolygon incorrectly git-svn-id: http://svn.osgeo.org/postgis/trunk@13933 b70326c6-7e19-0410-871a-916f4a2858ee --- loader/shp2pgsql-core.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/loader/shp2pgsql-core.c b/loader/shp2pgsql-core.c index 44e08c7a1..5fb3d06de 100644 --- a/loader/shp2pgsql-core.c +++ b/loader/shp2pgsql-core.c @@ -650,7 +650,14 @@ FindPolygons(SHPObject *obj, Ring ***Out) pt2.x = inner->list[1].x; pt2.y = inner->list[1].y; - for (i = 0; i < out_index; i++) + /* + * If we assume that the case of the "big polygon w/o hole + * containing little polygon w/ hold" is ordered so that the + * big polygon comes first, then checking the list in reverse + * will assign the little polygon's hole to the little polygon + * w/o a lot of extra fancy containment logic here + */ + for (i = out_index - 1; i >= 0; i--) { int in; @@ -660,7 +667,6 @@ FindPolygons(SHPObject *obj, Ring ***Out) outer = Outer[i]; break; } - /*fprintf(stderr, "!PIP %s\nOUTE %s\n", dump_ring(inner), dump_ring(Outer[i])); */ } if (outer) @@ -683,7 +689,11 @@ FindPolygons(SHPObject *obj, Ring ***Out) } *Out = Outer; - free(Inner); + /* + * Only free the containing Inner array, not the ring elements, because + * the rings are now owned by the linked lists in the Outer array elements. + */ + free(Inner); return out_index; } -- 2.40.0