From: Jorge Arévalo Date: Wed, 1 Jun 2011 23:50:14 +0000 (+0000) Subject: Fixed ticket #650. You need to update your GDAL copy to a release up to 22476 to... X-Git-Tag: 2.0.0alpha1~1506 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f007bac333a1951bf46a9dfd70ad325262d735f9;p=postgis Fixed ticket #650. You need to update your GDAL copy to a release up to 22476 to make it work. git-svn-id: http://svn.osgeo.org/postgis/trunk@7308 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/raster/rt_core/Makefile.in b/raster/rt_core/Makefile.in index d2c4d6007..02fd75545 100644 --- a/raster/rt_core/Makefile.in +++ b/raster/rt_core/Makefile.in @@ -7,7 +7,7 @@ # the terms of the GNU General Public Licence. See the COPYING file. # ############################################################################# - + AR=ar rs CC=@CC@ @@ -16,10 +16,10 @@ LIBLWGEOM_CFLAGS=@LIBLWGEOM_CFLAGS@ LIBGDAL_CFLAGS=@LIBGDAL_CFLAGS@ LIBGDAL_LDFLAGS=@LIBGDAL_LDFLAGS@ LDFLAGS=$(LIBLWGEOM_LDFLAGS) $(LIBGDAL_LDFLAGS) -CFLAGS=@CFLAGS@ @PICFLAGS@ @WARNFLAGS@ $(LIBLWGEOM_CFLAGS) $(LIBGDAL_CFLAGS) +CFLAGS=@CFLAGS@ @PICFLAGS@ @WARNFLAGS@ $(LIBLWGEOM_CFLAGS) $(LIBGDAL_CFLAGS) # Standalone RTCORE objects -RT_OBJS=rt_api.o +RT_OBJS=rt_api.o RT_LIB=librtcore.a RT_HEADERS=rt_api.h @@ -27,7 +27,7 @@ all: $(RT_LIB) clean: $(RM) $(RT_OBJS) - $(RM) $(RT_LIB) + $(RM) $(RT_LIB) distclean: clean $(RM) Makefile diff --git a/raster/rt_core/rt_api.c b/raster/rt_core/rt_api.c index 43fdb8e2c..eac1cf42f 100644 --- a/raster/rt_core/rt_api.c +++ b/raster/rt_core/rt_api.c @@ -3253,10 +3253,9 @@ struct rt_geomval_t { }; rt_geomval -rt_raster_dump_as_wktpolygons(rt_raster raster, int nband, - int * pnElements) { - - char * pszQuery; +rt_raster_dump_as_wktpolygons(rt_raster raster, int nband, int * pnElements) +{ + char * pszQuery; char * pszDataPointer; char szGdalOption[50]; long j; @@ -3502,7 +3501,7 @@ rt_raster_dump_as_wktpolygons(rt_raster raster, int nband, */ /* First, create a field definition to create the field */ - hFldDfn = OGR_Fld_Create("PixelValue", OFTInteger); + hFldDfn = OGR_Fld_Create("PixelValue", OFTReal); /* Second, create the field */ if (OGR_L_CreateField(hLayer, hFldDfn, TRUE) != @@ -3543,7 +3542,7 @@ rt_raster_dump_as_wktpolygons(rt_raster raster, int nband, /** * We don't need a raster mask band. Each band has a nodata value. **/ - GDALPolygonize(gdal_band, NULL, hLayer, iPixVal, NULL, NULL, NULL); + GDALFPolygonize(gdal_band, NULL, hLayer, iPixVal, NULL, NULL, NULL); /** * Optimization: Apply a OGR SQL filter to the layer to select the @@ -3552,18 +3551,17 @@ rt_raster_dump_as_wktpolygons(rt_raster raster, int nband, * Thanks to David Zwarg. **/ if (iBandHasNodataValue) { - pszQuery = (char *) rtalloc(50 * sizeof (char)); - sprintf(pszQuery, "PixelValue != %f", dBandNoData ); - OGRErr e = OGR_L_SetAttributeFilter(hLayer, pszQuery); - if (e != OGRERR_NONE) { - rtwarn("Error filtering NODATA values for band. All values" - " will be treated as data values"); - } - + pszQuery = (char *) rtalloc(50 * sizeof (char)); + sprintf(pszQuery, "PixelValue != %f", dBandNoData ); + OGRErr e = OGR_L_SetAttributeFilter(hLayer, pszQuery); + if (e != OGRERR_NONE) { + rtwarn("Error filtering NODATA values for band. All values" + " will be treated as data values"); + } } else { - pszQuery = NULL; + pszQuery = NULL; } @@ -3607,7 +3605,7 @@ rt_raster_dump_as_wktpolygons(rt_raster raster, int nband, hFeature = OGR_L_GetNextFeature(hLayer); dValue = OGR_F_GetFieldAsDouble(hFeature, iPixVal); - hGeom = OGR_F_GetGeometryRef(hFeature); + hGeom = OGR_F_GetGeometryRef(hFeature); OGR_G_ExportToWkt(hGeom, &pszSrcText); pols[j].val = dValue; @@ -3658,8 +3656,6 @@ rt_raster_get_convex_hull(rt_raster raster) { LWPOLY* ret = NULL; POINT4D p4d; - - assert(NULL != raster); RASTER_DEBUGF(3, "rt_raster_get_convex_hull: raster is %dx%d", diff --git a/raster/test/core/testapi.c b/raster/test/core/testapi.c index 854eef7fd..6e758f506 100644 --- a/raster/test/core/testapi.c +++ b/raster/test/core/testapi.c @@ -82,43 +82,44 @@ fillRasterToPolygonize(int hasnodata, double nodatavalue) /* Fill raster. Option 2: 9x9, 1 band */ - rt_band band = addBand(raster, PT_32BUI, hasnodata, nodatavalue); + rt_band band = addBand(raster, PT_32BF, hasnodata, nodatavalue); { int x, y; for (x = 0; x < rt_band_get_width(band); ++x) - for (y = 0; y < rt_band_get_height(band); ++y) - rt_band_set_pixel(band, x, y, 0); - } + for (y = 0; y < rt_band_get_height(band); ++y) + rt_band_set_pixel(band, x, y, 0.0); + } + /**/ - rt_band_set_pixel(band, 3, 1, 1); - rt_band_set_pixel(band, 4, 1, 1); - rt_band_set_pixel(band, 5, 1, 2); - rt_band_set_pixel(band, 2, 2, 1); - rt_band_set_pixel(band, 3, 2, 1); - rt_band_set_pixel(band, 4, 2, 1); - rt_band_set_pixel(band, 5, 2, 2); - rt_band_set_pixel(band, 6, 2, 2); - rt_band_set_pixel(band, 1, 3, 1); - rt_band_set_pixel(band, 2, 3, 1); - rt_band_set_pixel(band, 6, 3, 2); - rt_band_set_pixel(band, 7, 3, 2); - rt_band_set_pixel(band, 1, 4, 1); - rt_band_set_pixel(band, 2, 4, 1); - rt_band_set_pixel(band, 6, 4, 2); - rt_band_set_pixel(band, 7, 4, 2); - rt_band_set_pixel(band, 1, 5, 1); - rt_band_set_pixel(band, 2, 5, 1); - rt_band_set_pixel(band, 6, 5, 2); - rt_band_set_pixel(band, 7, 5, 2); - rt_band_set_pixel(band, 2, 6, 1); - rt_band_set_pixel(band, 3, 6, 1); - rt_band_set_pixel(band, 4, 6, 1); - rt_band_set_pixel(band, 5, 6, 2); - rt_band_set_pixel(band, 6, 6, 2); - rt_band_set_pixel(band, 3, 7, 1); - rt_band_set_pixel(band, 4, 7, 1); - rt_band_set_pixel(band, 5, 7, 2); + rt_band_set_pixel(band, 3, 1, 1.5); + rt_band_set_pixel(band, 4, 1, 1.5); + rt_band_set_pixel(band, 5, 1, 2.5); + rt_band_set_pixel(band, 2, 2, 1.5); + rt_band_set_pixel(band, 3, 2, 1.5); + rt_band_set_pixel(band, 4, 2, 1.5); + rt_band_set_pixel(band, 5, 2, 2.5); + rt_band_set_pixel(band, 6, 2, 2.5); + rt_band_set_pixel(band, 1, 3, 1.5); + rt_band_set_pixel(band, 2, 3, 1.5); + rt_band_set_pixel(band, 6, 3, 2.5); + rt_band_set_pixel(band, 7, 3, 2.5); + rt_band_set_pixel(band, 1, 4, 1.5); + rt_band_set_pixel(band, 2, 4, 1.5); + rt_band_set_pixel(band, 6, 4, 2.5); + rt_band_set_pixel(band, 7, 4, 2.5); + rt_band_set_pixel(band, 1, 5, 1.5); + rt_band_set_pixel(band, 2, 5, 1.5); + rt_band_set_pixel(band, 6, 5, 2.5); + rt_band_set_pixel(band, 7, 5, 2.5); + rt_band_set_pixel(band, 2, 6, 1.5); + rt_band_set_pixel(band, 3, 6, 1.5); + rt_band_set_pixel(band, 4, 6, 1.5); + rt_band_set_pixel(band, 5, 6, 2.5); + rt_band_set_pixel(band, 6, 6, 2.5); + rt_band_set_pixel(band, 3, 7, 1.5); + rt_band_set_pixel(band, 4, 7, 1.5); + rt_band_set_pixel(band, 5, 7, 2.5); @@ -1506,11 +1507,11 @@ main() { /* Check ST_AsPolygon */ printf("Testing polygonize function\n"); - /* First test: NODATA value = -1 */ + /* First test: NODATA value = -1 */ rt_raster rt = fillRasterToPolygonize(1, -1.0); - /* We can check rt_raster_has_no_band here too */ - CHECK(!rt_raster_has_no_band(rt, 1)); + /* We can check rt_raster_has_no_band here too */ + CHECK(!rt_raster_has_no_band(rt, 1)); /** * Need to define again, to access the struct fields @@ -1526,104 +1527,104 @@ main() rt_geomval gv = (rt_geomval) rt_raster_dump_as_wktpolygons(rt, 1, &nPols); - CHECK_EQUALS_DOUBLE(gv[0].val, 1.0); + CHECK_EQUALS_DOUBLE(gv[0].val, 1.5); CHECK(!strcmp(gv[0].geom, "POLYGON ((3 1,3 2,2 2,2 3,1 3,1 6,2 6,2 7,3 7,3 8,5 8,5 6,3 6,3 3,4 3,5 3,5 1,3 1))")); - CHECK_EQUALS_DOUBLE(gv[1].val, 0.0); - CHECK(!strcmp(gv[1].geom, "POLYGON ((3 3,3 6,6 6,6 3,3 3))")); + CHECK_EQUALS_DOUBLE(gv[1].val, 0.0); + CHECK(!strcmp(gv[1].geom, "POLYGON ((3 3,3 6,6 6,6 3,3 3))")); - CHECK_EQUALS_DOUBLE(gv[2].val, 2.0); + CHECK_EQUALS_DOUBLE(gv[2].val, 2.5); CHECK(!strcmp(gv[2].geom, "POLYGON ((5 1,5 3,6 3,6 6,5 6,5 8,6 8,6 7,7 7,7 6,8 6,8 3,7 3,7 2,6 2,6 1,5 1))")); - CHECK_EQUALS_DOUBLE(gv[3].val, 0.0); - CHECK(!strcmp(gv[3].geom, "POLYGON ((0 0,0 9,9 9,9 0,0 0),(6 7,6 8,3 8,3 7,2 7,2 6,1 6,1 3,2 3,2 2,3 2,3 1,6 1,6 2,7 2,7 3,8 3,8 6,7 6,7 7,6 7))")); + CHECK_EQUALS_DOUBLE(gv[3].val, 0.0); + CHECK(!strcmp(gv[3].geom, "POLYGON ((0 0,0 9,9 9,9 0,0 0),(6 7,6 8,3 8,3 7,2 7,2 6,1 6,1 3,2 3,2 2,3 2,3 1,6 1,6 2,7 2,7 3,8 3,8 6,7 6,7 7,6 7))")); rt_raster_destroy(rt); - /* Second test: NODATA value = 1 */ - rt = fillRasterToPolygonize(1, 1.0); + /* Second test: NODATA value = 1.5 */ + rt = fillRasterToPolygonize(1, 1.5); - /* We can check rt_raster_has_no_band here too */ - CHECK(!rt_raster_has_no_band(rt, 1)); + /* We can check rt_raster_has_no_band here too */ + CHECK(!rt_raster_has_no_band(rt, 1)); nPols = 0; gv = (rt_geomval) rt_raster_dump_as_wktpolygons(rt, 1, &nPols); - CHECK_EQUALS_DOUBLE(gv[0].val, 0.0); - CHECK(!strcmp(gv[0].geom, "POLYGON ((3 3,3 6,6 6,6 3,3 3))")); + CHECK_EQUALS_DOUBLE(gv[0].val, 0.0); + CHECK(!strcmp(gv[0].geom, "POLYGON ((3 3,3 6,6 6,6 3,3 3))")); - CHECK_EQUALS_DOUBLE(gv[1].val, 2.0); + CHECK_EQUALS_DOUBLE(gv[1].val, 2.5); CHECK(!strcmp(gv[1].geom, "POLYGON ((5 1,5 3,6 3,6 6,5 6,5 8,6 8,6 7,7 7,7 6,8 6,8 3,7 3,7 2,6 2,6 1,5 1))")); - CHECK_EQUALS_DOUBLE(gv[2].val, 0.0); - CHECK(!strcmp(gv[2].geom, "POLYGON ((0 0,0 9,9 9,9 0,0 0),(6 7,6 8,3 8,3 7,2 7,2 6,1 6,1 3,2 3,2 2,3 2,3 1,6 1,6 2,7 2,7 3,8 3,8 6,7 6,7 7,6 7))")); + CHECK_EQUALS_DOUBLE(gv[2].val, 0.0); + CHECK(!strcmp(gv[2].geom, "POLYGON ((0 0,0 9,9 9,9 0,0 0),(6 7,6 8,3 8,3 7,2 7,2 6,1 6,1 3,2 3,2 2,3 2,3 1,6 1,6 2,7 2,7 3,8 3,8 6,7 6,7 7,6 7))")); rt_raster_destroy(rt); - /* Third test: NODATA value = 2 */ - rt = fillRasterToPolygonize(1, 2.0); + /* Third test: NODATA value = 2.5 */ + rt = fillRasterToPolygonize(1, 2.5); - /* We can check rt_raster_has_no_band here too */ - CHECK(!rt_raster_has_no_band(rt, 1)); + /* We can check rt_raster_has_no_band here too */ + CHECK(!rt_raster_has_no_band(rt, 1)); nPols = 0; gv = (rt_geomval) rt_raster_dump_as_wktpolygons(rt, 1, &nPols); - CHECK_EQUALS_DOUBLE(gv[0].val, 1.0); + CHECK_EQUALS_DOUBLE(gv[0].val, 1.5); CHECK(!strcmp(gv[0].geom, "POLYGON ((3 1,3 2,2 2,2 3,1 3,1 6,2 6,2 7,3 7,3 8,5 8,5 6,3 6,3 3,4 3,5 3,5 1,3 1))")); - CHECK_EQUALS_DOUBLE(gv[1].val, 0.0); - CHECK(!strcmp(gv[1].geom, "POLYGON ((3 3,3 6,6 6,6 3,3 3))")); + CHECK_EQUALS_DOUBLE(gv[1].val, 0.0); + CHECK(!strcmp(gv[1].geom, "POLYGON ((3 3,3 6,6 6,6 3,3 3))")); - CHECK_EQUALS_DOUBLE(gv[2].val, 0.0); - CHECK(!strcmp(gv[2].geom, "POLYGON ((0 0,0 9,9 9,9 0,0 0),(6 7,6 8,3 8,3 7,2 7,2 6,1 6,1 3,2 3,2 2,3 2,3 1,6 1,6 2,7 2,7 3,8 3,8 6,7 6,7 7,6 7))")); + CHECK_EQUALS_DOUBLE(gv[2].val, 0.0); + CHECK(!strcmp(gv[2].geom, "POLYGON ((0 0,0 9,9 9,9 0,0 0),(6 7,6 8,3 8,3 7,2 7,2 6,1 6,1 3,2 3,2 2,3 2,3 1,6 1,6 2,7 2,7 3,8 3,8 6,7 6,7 7,6 7))")); rt_raster_destroy(rt); - /* Fourth test: NODATA value = 0 */ + /* Fourth test: NODATA value = 0 */ rt = fillRasterToPolygonize(1, 0.0); - /* We can check rt_raster_has_no_band here too */ - CHECK(!rt_raster_has_no_band(rt, 1)); + /* We can check rt_raster_has_no_band here too */ + CHECK(!rt_raster_has_no_band(rt, 1)); nPols = 0; gv = (rt_geomval) rt_raster_dump_as_wktpolygons(rt, 1, &nPols); - CHECK_EQUALS_DOUBLE(gv[0].val, 1.0); + CHECK_EQUALS_DOUBLE(gv[0].val, 1.5); CHECK(!strcmp(gv[0].geom, "POLYGON ((3 1,3 2,2 2,2 3,1 3,1 6,2 6,2 7,3 7,3 8,5 8,5 6,3 6,3 3,4 3,5 3,5 1,3 1))")); - CHECK_EQUALS_DOUBLE(gv[1].val, 2.0); + CHECK_EQUALS_DOUBLE(gv[1].val, 2.5); CHECK(!strcmp(gv[1].geom, "POLYGON ((5 1,5 3,6 3,6 6,5 6,5 8,6 8,6 7,7 7,7 6,8 6,8 3,7 3,7 2,6 2,6 1,5 1))")); - rt_raster_destroy(rt); + rt_raster_destroy(rt); - /* Last test: There is no NODATA value (all values are valid) */ - rt = fillRasterToPolygonize(0, 1.0); + /* Last test: There is no NODATA value (all values are valid) */ + rt = fillRasterToPolygonize(0, 0.0); - /* We can check rt_raster_has_no_band here too */ - CHECK(!rt_raster_has_no_band(rt, 1)); + /* We can check rt_raster_has_no_band here too */ + CHECK(!rt_raster_has_no_band(rt, 1)); nPols = 0; gv = (rt_geomval) rt_raster_dump_as_wktpolygons(rt, 1, &nPols); - CHECK_EQUALS_DOUBLE(gv[0].val, 1.0); + CHECK_EQUALS_DOUBLE(gv[0].val, 1.5); CHECK(!strcmp(gv[0].geom, "POLYGON ((3 1,3 2,2 2,2 3,1 3,1 6,2 6,2 7,3 7,3 8,5 8,5 6,3 6,3 3,4 3,5 3,5 1,3 1))")); - CHECK_EQUALS_DOUBLE(gv[1].val, 0.0); - CHECK(!strcmp(gv[1].geom, "POLYGON ((3 3,3 6,6 6,6 3,3 3))")); + CHECK_EQUALS_DOUBLE(gv[1].val, 0.0); + CHECK(!strcmp(gv[1].geom, "POLYGON ((3 3,3 6,6 6,6 3,3 3))")); - CHECK_EQUALS_DOUBLE(gv[2].val, 2.0); + CHECK_EQUALS_DOUBLE(gv[2].val, 2.5); CHECK(!strcmp(gv[2].geom, "POLYGON ((5 1,5 3,6 3,6 6,5 6,5 8,6 8,6 7,7 7,7 6,8 6,8 3,7 3,7 2,6 2,6 1,5 1))")); - CHECK_EQUALS_DOUBLE(gv[3].val, 0.0); - CHECK(!strcmp(gv[3].geom, "POLYGON ((0 0,0 9,9 9,9 0,0 0),(6 7,6 8,3 8,3 7,2 7,2 6,1 6,1 3,2 3,2 2,3 2,3 1,6 1,6 2,7 2,7 3,8 3,8 6,7 6,7 7,6 7))")); - rt_raster_destroy(rt); + CHECK_EQUALS_DOUBLE(gv[3].val, 0.0); + CHECK(!strcmp(gv[3].geom, "POLYGON ((0 0,0 9,9 9,9 0,0 0),(6 7,6 8,3 8,3 7,2 7,2 6,1 6,1 3,2 3,2 2,3 2,3 1,6 1,6 2,7 2,7 3,8 3,8 6,7 6,7 7,6 7))")); + rt_raster_destroy(rt); }