]> granicus.if.org Git - postgis/commitdiff
Don't let lwgeom_add_bbox syntetize a fake box for empty geometries
authorSandro Santilli <strk@keybit.net>
Fri, 9 Dec 2011 14:37:11 +0000 (14:37 +0000)
committerSandro Santilli <strk@keybit.net>
Fri, 9 Dec 2011 14:37:11 +0000 (14:37 +0000)
Empty geometries have no box. Period.
Update GML extent output for empty geometries to handle the special
case by using empty tags. Regress test it.

git-svn-id: http://svn.osgeo.org/postgis/trunk@8334 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/cunit/cu_out_gml.c
liblwgeom/lwgeom.c
liblwgeom/lwout_gml.c

index 3bb47725acd6996b34a5557993a53ae256993827..f0a5f45eba446495c6e2d97c4f12de729b4c7d4c 100644 (file)
@@ -176,7 +176,7 @@ static void do_gml2_extent_test(char * in, char * out, char * srs,
 
        g = lwgeom_from_wkt(in, LW_PARSER_CHECK_NONE);
        h = lwgeom_extent_to_gml2(g, srs, precision, prefix);
-       if ( ! h ) h = cu_error_msg;
+       if ( ! h ) h = strdup(cu_error_msg);
 
        if (strcmp(h, out))
                fprintf(stderr, "\nEXT GML 2 - In:   %s\nObt: %s\nExp: %s\n",
@@ -196,7 +196,7 @@ static void do_gml3_extent_test(char * in, char * out, char * srs,
 
        g = lwgeom_from_wkt(in, LW_PARSER_CHECK_NONE);
        h = lwgeom_extent_to_gml3(g, srs, precision, opts, prefix);
-       if ( ! h ) h = cu_error_msg;
+       if ( ! h ) h = strdup(cu_error_msg);
 
        if (strcmp(h, out))
                fprintf(stderr, "\nEXT GML 3 - In:   %s\nObt: %s\nExp: %s\n",
@@ -1037,12 +1037,18 @@ static void out_gml2_extent(void)
            "<Box><coordinates>-2,-1 10,14</coordinates></Box>",
            NULL, 15, "");
 
-       /* GML2: empty (FIXME) */
+       /* GML2: empty */
        do_gml2_extent_test(
            "GEOMETRYCOLLECTION EMPTY",
-           "<Box><coordinates>0,0 0,0</coordinates></Box>",
+           "<Box/>",
            NULL, 15, "");
 
+       /* GML2: empty with srsName */
+       do_gml2_extent_test(
+           "GEOMETRYCOLLECTION EMPTY",
+           "<Box srsName=\"urn:ogc:def:crs:EPSG::4326\"/>",
+           "urn:ogc:def:crs:EPSG::4326", 15, "");
+
 }
 
 static void out_gml3_extent(void)
@@ -1109,12 +1115,18 @@ static void out_gml3_extent(void)
            "<Envelope><lowerCorner>-2 -1</lowerCorner><upperCorner>10 14</upperCorner></Envelope>",
            NULL, 15, 0, "");
 
-       /* GML3: empty (FIXME) */
+       /* GML3: empty */
        do_gml3_extent_test(
            "GEOMETRYCOLLECTION EMPTY",
-           "<Envelope><lowerCorner>0 0</lowerCorner><upperCorner>0 0</upperCorner></Envelope>",
+           "<Envelope/>",
            NULL, 15, 0, "");
 
+       /* GML3: empty with srsName */
+       do_gml3_extent_test(
+           "GEOMETRYCOLLECTION EMPTY",
+           "<Envelope srsName=\"urn:ogc:def:crs:EPSG::4326\"/>",
+           "urn:ogc:def:crs:EPSG::4326", 15, 0, "");
+
 }
 
 
index ae1dc47a3df026c40f67fb70aad1801ab294078f..20bab78f299933600396260b51be92acbdc508b6 100644 (file)
@@ -542,6 +542,9 @@ lwgeom_drop_bbox(LWGEOM *lwgeom)
 void
 lwgeom_add_bbox(LWGEOM *lwgeom)
 {
+       /* an empty LWGEOM has no bbox */
+       if( lwgeom_is_empty(lwgeom) ) return;
+
        if ( lwgeom->bbox ) return;
        FLAGS_SET_BBOX(lwgeom->flags, 1);
        lwgeom->bbox = gbox_new(lwgeom->flags);
index 2b2c151997fbb7dcea6381c6ed368ce25454bb05..df7b83f42733a5b5798aad86446a74d0f1f89ebe 100644 (file)
@@ -70,6 +70,21 @@ gbox_to_gml2(const GBOX *bbox, const char *srs, int precision, const char *prefi
        char *ptr, *output;
        size_t prefixlen = strlen(prefix);
 
+       if ( ! bbox ) {
+               size = ( sizeof("<Box>/") + (prefixlen*2) ) * 2;
+               if ( srs ) size += strlen(srs) + sizeof(" srsName=..");
+
+               ptr = output = lwalloc(size);
+
+               ptr += sprintf(ptr, "<%sBox", prefix);
+
+               if ( srs ) ptr += sprintf(ptr, " srsName=\"%s\"", srs);
+
+               ptr += sprintf(ptr, "/>");
+
+               return output;
+       }
+
         pa = ptarray_construct_empty(FLAGS_GET_Z(bbox->flags), 0, 2);
 
         pt.x = bbox->xmin; 
@@ -110,6 +125,20 @@ gbox_to_gml3(const GBOX *bbox, const char *srs, int precision, int opts, const c
        size_t prefixlen = strlen(prefix);
        int dimension = 2;
 
+       if ( ! bbox ) {
+               size = ( sizeof("<Envelope>/") + (prefixlen*2) ) * 2;
+               if ( srs ) size += strlen(srs) + sizeof(" srsName=..");
+
+               ptr = output = lwalloc(size);
+
+               ptr += sprintf(ptr, "<%sEnvelope", prefix);
+               if ( srs ) ptr += sprintf(ptr, " srsName=\"%s\"", srs);
+
+               ptr += sprintf(ptr, "/>");
+
+               return output;
+       }
+
         if (FLAGS_GET_Z(bbox->flags)) dimension = 3;
 
         pa = ptarray_construct_empty(FLAGS_GET_Z(bbox->flags), 0, 1);
@@ -157,10 +186,12 @@ extern char *
 lwgeom_extent_to_gml2(const LWGEOM *geom, const char *srs, int precision, const char *prefix)
 {
        const GBOX* bbox = lwgeom_get_bbox(geom);
+/*
        if ( ! bbox ) {
                lwerror("lwgeom_extent_to_gml2: empty geometry doesn't have a bounding box");
                return NULL;
        }
+*/
        char *ret = gbox_to_gml2(bbox, srs, precision, prefix);
        return ret;
 }
@@ -170,10 +201,12 @@ extern char *
 lwgeom_extent_to_gml3(const LWGEOM *geom, const char *srs, int precision, int opts, const char *prefix)
 {
        const GBOX* bbox = lwgeom_get_bbox(geom);
+/*
        if ( ! bbox ) {
                lwerror("lwgeom_extent_to_gml3: empty geometry doesn't have a bounding box");
                return NULL;
        }
+*/
        return gbox_to_gml3(bbox, srs, precision, opts, prefix);
 }