]> granicus.if.org Git - postgis/commitdiff
#2395, force un-closed KML polygons closed, and issue NOTICE
authorPaul Ramsey <pramsey@cleverelephant.ca>
Wed, 22 Jul 2015 17:54:09 +0000 (17:54 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Wed, 22 Jul 2015 17:54:09 +0000 (17:54 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@13834 b70326c6-7e19-0410-871a-916f4a2858ee

postgis/lwgeom_in_kml.c
regress/in_kml.sql
regress/in_kml_expected

index caa38b955770d34b2737d6c86e3f9b1af678dbce..82b0f855e12ab2825f425408334f3cb71de7cf70 100644 (file)
@@ -407,10 +407,17 @@ static LWGEOM* parse_kml_polygon(xmlNodePtr xnode, bool *hasz)
                        ppa = (POINTARRAY**) lwalloc(sizeof(POINTARRAY*));
                        ppa[0] = parse_kml_coordinates(xb->children, hasz);
 
-                       if (ppa[0]->npoints < 4
-                               || (!*hasz && !ptarray_is_closed_2d(ppa[0]))
-                               ||  (*hasz && !ptarray_is_closed_3d(ppa[0])))
+                       if (ppa[0]->npoints < 4)
                                lwpgerror("invalid KML representation");
+
+                       if ((!*hasz && !ptarray_is_closed_2d(ppa[0])) || 
+                           ( *hasz && !ptarray_is_closed_3d(ppa[0])))
+                       {
+                               POINT4D pt;
+                               getPoint4d_p(ppa[0], 0, &pt);
+                               ptarray_append_point(ppa[0], &pt, LW_TRUE);
+                               lwpgnotice("forced closure on an un-closed KML polygon");
+                       }
                }
        }
 
@@ -433,11 +440,18 @@ static LWGEOM* parse_kml_polygon(xmlNodePtr xnode, bool *hasz)
                                                       sizeof(POINTARRAY*) * (ring + 1));
                        ppa[ring] = parse_kml_coordinates(xb->children, hasz);
 
-                       if (ppa[ring]->npoints < 4
-                               || (!*hasz && !ptarray_is_closed_2d(ppa[ring]))
-                               ||  (*hasz && !ptarray_is_closed_3d(ppa[ring])))
+                       if (ppa[ring]->npoints < 4)
                                lwpgerror("invalid KML representation");
 
+                       if ((!*hasz && !ptarray_is_closed_2d(ppa[ring])) || 
+                           ( *hasz && !ptarray_is_closed_3d(ppa[ring])))
+                       {
+                               POINT4D pt;
+                               getPoint4d_p(ppa[ring], 0, &pt);
+                               ptarray_append_point(ppa[ring], &pt, LW_TRUE);
+                               lwpgnotice("forced closure on an un-closed KML polygon");
+                       }
+
                        ring++;
                }
        }
index 3ac14e0c323db3b1d92836742baa909fab9922ea..2af1f1c2a8caa13ede78d5e8730d42f386a5f829 100644 (file)
@@ -81,10 +81,10 @@ SELECT 'polygon_1', ST_AsEWKT(ST_GeomFromKML('<kml:Polygon><kml:outerBoundaryIs>
 -- ERROR: In exterior ring: Last point is not the same as the first one 
 SELECT 'polygon_2', ST_AsEWKT(ST_GeomFromKML('<kml:Polygon><kml:outerBoundaryIs><kml:LinearRing><kml:coordinates>1,2 3,4 5,6 1,3</kml:coordinates></kml:LinearRing></kml:outerBoundaryIs></kml:Polygon>'));
 
--- ERROR: In exterior 3D ring: Last point is not the same as the first one in Z
+-- FORCE CLOSE: In exterior 3D ring: Last point is not the same as the first one in Z
 SELECT 'polygon_3', ST_AsEWKT(ST_GeomFromKML('<kml:Polygon><kml:outerBoundaryIs><kml:LinearRing><kml:coordinates>1,2,3 4,5,6 7,8,9 1,2,0</kml:coordinates></kml:LinearRing></kml:outerBoundaryIs></kml:Polygon>'));
 
--- ERROR: Only 3 points in exterior ring
+-- FORCE CLOSE: Only 3 points in exterior ring
 SELECT 'polygon_4', ST_AsEWKT(ST_GeomFromKML('<kml:Polygon><kml:outerBoundaryIs><kml:LinearRing><kml:coordinates>1,2 3,4 1,2</kml:coordinates></kml:LinearRing></kml:outerBoundaryIs></kml:Polygon>'));
 
 -- ERROR: Empty exterior ring coordinates 
@@ -105,10 +105,10 @@ SELECT 'polygon_11', ST_AsEWKT(ST_GeomFromKML('<kml:Polygon><kml:outerBoundaryIs
 -- ERROR: Only 3 points in interior ring
 SELECT 'polygon_12', ST_AsEWKT(ST_GeomFromKML('<kml:Polygon><kml:outerBoundaryIs><kml:LinearRing><kml:coordinates>1,2 3,4 5,6 1,2</kml:coordinates></kml:LinearRing></kml:outerBoundaryIs><kml:innerBoundaryIs><kml:LinearRing><kml:coordinates>7,8 9,10 7,8</kml:coordinates></kml:LinearRing></kml:innerBoundaryIs></kml:Polygon>'));
 
--- ERROR: In interior ring: Last point is not the same as the first one 
+-- FORCE CLOSE: In interior ring: Last point is not the same as the first one 
 SELECT 'polygon_13', ST_AsEWKT(ST_GeomFromKML('<kml:Polygon><kml:outerBoundaryIs><kml:LinearRing><kml:coordinates>1,2 3,4 5,6 1,2</kml:coordinates></kml:LinearRing></kml:outerBoundaryIs><kml:innerBoundaryIs><kml:LinearRing><kml:coordinates>7,8 9,10 11,12 7,9</kml:coordinates></kml:LinearRing></kml:innerBoundaryIs></kml:Polygon>'));
 
--- ERROR: In interior 3D ring: Last point is not the same as the first one in Z
+-- FORCE CLOSE: In interior 3D ring: Last point is not the same as the first one in Z
 SELECT 'polygon_14', ST_AsEWKT(ST_GeomFromKML('<kml:Polygon><kml:outerBoundaryIs><kml:LinearRing><kml:coordinates>1,2,3 4,5,6 7,8,9 1,2,3</kml:coordinates></kml:LinearRing></kml:outerBoundaryIs><kml:innerBoundaryIs><kml:LinearRing><kml:coordinates>10,11,12 13,14,15 16,17,18 10,11,0</kml:coordinates></kml:LinearRing></kml:innerBoundaryIs></kml:Polygon>'));
 
 -- 3 rings
index 0203db68543051c52ff2538d8cd0951eaf8582f4..d345146894558bd52f67c20ac6d00b027735d468 100644 (file)
@@ -15,8 +15,10 @@ ERROR:  invalid KML representation
 ERROR:  invalid KML representation
 linestring_5|SRID=4326;LINESTRING(1 2,3 4)
 polygon_1|SRID=4326;POLYGON((1 2,3 4,5 6,1 2))
-ERROR:  invalid KML representation
-ERROR:  invalid KML representation
+NOTICE:  forced closure on an un-closed KML polygon
+polygon_2|SRID=4326;POLYGON((1 2,3 4,5 6,1 3,1 2))
+NOTICE:  forced closure on an un-closed KML polygon
+polygon_3|SRID=4326;POLYGON((1 2 3,4 5 6,7 8 9,1 2 0,1 2 3))
 ERROR:  invalid KML representation
 ERROR:  invalid KML representation
 ERROR:  invalid KML representation
@@ -26,8 +28,10 @@ polygon_9|SRID=4326;POLYGON((1 2,3 4,5 6,1 2),(7 8,9 10,11 12,7 8))
 polygon_10|SRID=4326;POLYGON((1 2,3 4,5 6,1 2),(7 8,9 10,11 12,7 8))
 polygon_11|SRID=4326;POLYGON((1 2,3 4,5 6,1 2))
 ERROR:  invalid KML representation
-ERROR:  invalid KML representation
-ERROR:  invalid KML representation
+NOTICE:  forced closure on an un-closed KML polygon
+polygon_13|SRID=4326;POLYGON((1 2,3 4,5 6,1 2),(7 8,9 10,11 12,7 9,7 8))
+NOTICE:  forced closure on an un-closed KML polygon
+polygon_14|SRID=4326;POLYGON((1 2 3,4 5 6,7 8 9,1 2 3),(10 11 12,13 14 15,16 17 18,10 11 0,10 11 12))
 polygon_15|SRID=4326;POLYGON((1 2,3 4,5 6,1 2),(7 8,9 10,11 12,7 8),(13 14,15 16,17 18,13 14))
 multi_7|SRID=4326;GEOMETRYCOLLECTION(POINT(1 2),LINESTRING(3 4,5 6),POLYGON((7 8,9 10,11 12,7 8)))
 multi_8|SRID=4326;GEOMETRYCOLLECTION EMPTY