pixtype = band->pixtype;
if (x >= band->width || y >= band->height) {
- ctx->warn("Coordinates out of range while setting pixel value");
+ ctx->err("rt_band_set_pixel: Coordinates out of range");
return -1;
}
if (band->offline) {
- ctx->warn("rt_band_set_pixel not implemented yet for OFFDB bands");
+ ctx->err("rt_band_set_pixel not implemented yet for OFFDB bands");
return -1;
}
}
if (band->offline) {
- ctx->warn("rt_band_get_pixel not implemented yet for OFFDB bands");
+ ctx->err("rt_band_get_pixel not implemented yet for OFFDB bands");
return -1;
}
RASTER_DEBUGF(3, "Adding band %p to raster %p", band, raster);
- if (band->width != raster->width || band->height != raster->height) {
- ctx->warn("Can't add a %dx%d band to a %dx%d raster",
+ if (band->width != raster->width) {
+ ctx->err("rt_raster_add_band: Can't add a %dx%d band to a %dx%d raster",
band->width, band->height, raster->width, raster->height);
return -1;
}
int nFeatureCount = 0;
rt_band band = NULL;
int iPixVal = -1;
- int nValidPols = 0;
double dValue = 0.0;
int iBandHasNodataValue = FALSE;
double dBandNoData = 0.0;
- double dEpsilon = 0.0;
- int nCont = 0;
/* Checkings */
assert(NULL != ctx);
memdatasource = OGR_Dr_CreateDataSource(ogr_drv, "", NULL);
if (NULL == memdatasource) {
- ctx->err("rt_raster_dump_as_wktpolygons: Couldn't create a OGR Datasource to store polygons\n");
+ ctx->err("rt_raster_dump_as_wktpolygons: Couldn't create a OGR Datasource to store pols\n");
return 0;
}
**/
if (iBandHasNodataValue) {
pszQuery = (char *) ctx->alloc(50 * sizeof (char));
- sprintf(pszQuery, "PixelValue != %f", &dBandNoData );
- OGR_L_SetAttributeFilter(hLayer, pszQuery);
+ sprintf(pszQuery, "PixelValue != %f", dBandNoData );
+ OGRErr e = OGR_L_SetAttributeFilter(hLayer, pszQuery);
+ if (e != OGRERR_NONE) {
+ ctx->warn("Error filtering NODATA values for band. All values will be treated as data values\n");
+ }
+
}
else {
*********************************************************************/
nFeatureCount = OGR_L_GetFeatureCount(hLayer, TRUE);
-
/* Allocate memory for pols */
pols = (rt_geomval) ctx->alloc(nFeatureCount * sizeof (struct rt_geomval_t));
* sizeof (char));
strcpy(pols[j].geom, pszSrcText);
- RASTER_DEBUGF(4, "Feature %d, Polygon: %s", j, pols[nCont].geom);
- RASTER_DEBUGF(4, "Feature %d, value: %f", j, pols[nCont].val);
- RASTER_DEBUGF(4, "Feature %d, srid: %d", j, pols[nCont].srid);
+ RASTER_DEBUGF(4, "Feature %d, Polygon: %s", j, pols[j].geom);
+ RASTER_DEBUGF(4, "Feature %d, value: %f", j, pols[j].val);
+ RASTER_DEBUGF(4, "Feature %d, srid: %d", j, pols[j].srid);
/**
* We can't use deallocator from rt_context, because it comes from
}
if (pnElements)
- *pnElements = nCont;
+ *pnElements = nFeatureCount;
RASTER_DEBUG(3, "destroying GDAL MEM raster");
/* Check bands limits */
if (fromrast->numBands < 1)
{
- ctx->warn("Second raster has no band to copy");
+ ctx->warn("rt_raster_copy_band: Second raster has no band");
return -1;
}
else if (fromindex < 0)
{
- ctx->warn("Band index for second raster to copy is smaller than 0. Defaulted to 1");
+ ctx->warn("rt_raster_copy_band: Band index for second raster < 0. Defaulted to 1");
fromindex = 0;
}
else if (fromindex >= fromrast->numBands)
{
- ctx->warn("Band index for second raster to copy is greater than number of raster bands. Truncated from %u to %u", fromindex - 1, fromrast->numBands);
+ ctx->warn("rt_raster_copy_band: Band index for second raster > number of bands, truncated from %u to %u", fromindex - 1, fromrast->numBands);
fromindex = fromrast->numBands - 1;
}
if (toindex < 0)
{
- ctx->warn("Band index for first raster to copy band to is smaller than 0. Defaulted to 1");
+ ctx->warn("rt_raster_copy_band: Band index for first raster < 0. Defaulted to 1");
toindex = 0;
}
else if (toindex > torast->numBands)
{
- ctx->warn("Band index for first raster to copy to is greater than number of bands. Truncated from %u to %u", toindex - 1, torast->numBands);
+ ctx->warn("rt_raster_copy_band: Band index for first raster > number of bands, truncated from %u to %u", toindex - 1, torast->numBands);
toindex = torast->numBands;
}
static rt_band addBand(rt_context ctx, rt_raster raster, rt_pixtype pixtype, int hasnodata, double nodataval);
static void deepRelease(rt_context ctx, rt_raster raster);
static void testBand1BB(rt_context ctx, rt_band band);
-static rt_raster fillRasterToPolygonize(rt_context ctx);
+static rt_raster fillRasterToPolygonize(rt_context ctx, int hasnodata, double nodatavalue);
static rt_band
addBand(rt_context ctx, rt_raster raster, rt_pixtype pixtype, int hasnodata, double nodataval)
static rt_raster
-fillRasterToPolygonize(rt_context ctx)
+fillRasterToPolygonize(rt_context ctx, int hasnodata, double nodatavalue)
{
/* Create raster */
/* Fill raster. Option 2: 9x9, 1 band */
- rt_band band = addBand(ctx, raster, PT_32BUI, 1, 0);
+ rt_band band = addBand(ctx, raster, PT_32BUI, hasnodata, nodatavalue);
{
int x, y;
{ /* Check ST_AsPolygon */
printf("Testing polygonize function\n");
- rt_raster rt = fillRasterToPolygonize(ctx);
+
+ /* First test: NODATA value = -1 */
+ rt_raster rt = fillRasterToPolygonize(ctx, 1, -1.0);
+ printf("*** POLYGONIZE WITH NODATA = -1.0\n");
+
/* We can check rt_raster_has_no_band here too */
CHECK(!rt_raster_has_no_band(ctx, rt, 1));
rt_geomval gv = (rt_geomval) rt_raster_dump_as_wktpolygons(ctx, rt, 1, &nPols);
-
CHECK_EQUALS_DOUBLE(gv[0].val, 1.0);
- 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(!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[2].val, 2.0);
+ 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(ctx, rt);
+
+
+ /* Second test: NODATA value = 1 */
+ rt = fillRasterToPolygonize(ctx, 1, 1.0);
+
+ /* We can check rt_raster_has_no_band here too */
+ CHECK(!rt_raster_has_no_band(ctx, rt, 1));
+
+ nPols = 0;
+
+ gv = (rt_geomval) rt_raster_dump_as_wktpolygons(ctx, 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[1].val, 2.0);
- 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(!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))"));
+ rt_raster_destroy(ctx, rt);
+
+ /* Third test: NODATA value = 2 */
+ rt = fillRasterToPolygonize(ctx, 1, 2.0);
+
+ /* We can check rt_raster_has_no_band here too */
+ CHECK(!rt_raster_has_no_band(ctx, rt, 1));
+
+ nPols = 0;
+ gv = (rt_geomval) rt_raster_dump_as_wktpolygons(ctx, rt, 1, &nPols);
+
+ CHECK_EQUALS_DOUBLE(gv[0].val, 1.0);
+ 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[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(ctx, rt);
+
+
+ /* Fourth test: NODATA value = 0 */
+ rt = fillRasterToPolygonize(ctx, 1, 0.0);
+
+ /* We can check rt_raster_has_no_band here too */
+ CHECK(!rt_raster_has_no_band(ctx, rt, 1));
+
+ nPols = 0;
+
+ gv = (rt_geomval) rt_raster_dump_as_wktpolygons(ctx, rt, 1, &nPols);
+
+ CHECK_EQUALS_DOUBLE(gv[0].val, 1.0);
+ 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(!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(ctx, rt);
+
+ /* Last test: There is no NODATA value (all values are valid) */
+ rt = fillRasterToPolygonize(ctx, 0, 1.0);
+
+ /* We can check rt_raster_has_no_band here too */
+ CHECK(!rt_raster_has_no_band(ctx, rt, 1));
+
+ nPols = 0;
+
+ gv = (rt_geomval) rt_raster_dump_as_wktpolygons(ctx, rt, 1, &nPols);
+
+ CHECK_EQUALS_DOUBLE(gv[0].val, 1.0);
+ 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[2].val, 2.0);
+ 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(ctx, rt);
+
}
printf("Testing 1BB band\n");