]> granicus.if.org Git - postgis/commitdiff
Fix parsing GeoJSON of multipolygon with holes (#2216)
authorSandro Santilli <strk@keybit.net>
Thu, 28 Feb 2013 17:42:49 +0000 (17:42 +0000)
committerSandro Santilli <strk@keybit.net>
Thu, 28 Feb 2013 17:42:49 +0000 (17:42 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@11120 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/cunit/cu_in_geojson.c
liblwgeom/lwin_geojson.c

index 5ecbf2346e6fae36aeb45267a72489e1f0f387ae..8f9f4b4213933a831e8af3d9a0f477088833b169 100644 (file)
@@ -29,6 +29,12 @@ static void do_geojson_test(const char * exp, char * in, char * exp_srs, int pre
   has_bbox = has_bbox; /* unused */
 
        g = lwgeom_from_geojson(in, &srs);
+  if ( ! g ) {
+               fprintf(stderr, "\nIn:   %s\nExp:  %s\nObt: %s\n", in, exp, cu_error_msg);
+         CU_ASSERT(g);
+    return;
+  }
+
        h = lwgeom_to_wkt(g, WKT_EXTENDED, 15, &size);
 
        if (strcmp(h, exp)) {
@@ -201,6 +207,13 @@ static void in_geojson_test_geoms(void)
            "{\"type\":\"MultiPolygon\",\"coordinates\":[[[[0,1],[2,3],[4,5],[0,1]]],[[[6,7],[8,9],[10,11],[6,7]]]]}",
            NULL, 0, 0);
 
+  /* MultiPolygon with internal rings */
+  /* See http://trac.osgeo.org/postgis/ticket/2216 */
+  do_geojson_test(
+      "MULTIPOLYGON(((4 0,0 -4,-4 0,0 4,4 0),(2 0,0 2,-2 0,0 -2,2 0)),((24 0,20 -4,16 0,20 4,24 0),(22 0,20 2,18 0,20 -2,22 0)),((44 0,40 -4,36 0,40 4,44 0),(42 0,40 2,38 0,40 -2,42 0)))",
+      "{'type':'MultiPolygon','coordinates':[[[[4,0],[0,-4],[-4,0],[0,4],[4,0]],[[2,0],[0,2],[-2,0],[0,-2],[2,0]]],[[[24,0],[20,-4],[16,0],[20,4],[24,0]],[[22,0],[20,2],[18,0],[20,-2],[22,0]]],[[[44,0],[40,-4],[36,0],[40,4],[44,0]],[[42,0],[40,2],[38,0],[40,-2],[42,0]]]]}",
+      NULL, 0, 0);
+
        /* GeometryCollection */
        do_geojson_test(
            "GEOMETRYCOLLECTION(POINT(0 1),LINESTRING(2 3,4 5))",
index 7e0d95f713cb4f5676b1ad5ef29f03f972d1221d..e4de54a167e985c8d3b57570cc4c64368c88e31a 100644 (file)
@@ -392,7 +392,7 @@ parse_geojson_multipolygon(json_object *geojson, int *hasz,  int root_srid)
                                        {
                                                json_object* coords = NULL;
                                                coords = json_object_array_get_idx( points, k );
-                                               parse_geojson_coord(coords, hasz, ppa[i]);
+                                               parse_geojson_coord(coords, hasz, ppa[j]);
                                        }
                                }