Commit b07084da authored by Darafei Praliaskouski's avatar Darafei Praliaskouski

Fix raster notices.

References #3994
Closes https://github.com/postgis/postgis/pull/271


git-svn-id: http://svn.osgeo.org/postgis/trunk@16645 b70326c6-7e19-0410-871a-916f4a2858ee
parent ca9f967a
Pipeline #25777457 passed with stage
in 18 minutes and 27 seconds
...@@ -1015,7 +1015,7 @@ rt_raster_iterator( ...@@ -1015,7 +1015,7 @@ rt_raster_iterator(
for (i = 0; i < itrcount; i++) { for (i = 0; i < itrcount; i++) {
if (!_param->isempty[i]) { if (!_param->isempty[i]) {
memcpy(rtnrast, _param->raster[i], sizeof(struct rt_raster_serialized_t)); memcpy(rtnrast, _param->raster[i], sizeof(struct rt_raster_t));
break; break;
} }
} }
...@@ -1118,11 +1118,11 @@ rt_raster_iterator( ...@@ -1118,11 +1118,11 @@ rt_raster_iterator(
switch (extenttype) { switch (extenttype) {
case ET_CUSTOM: case ET_CUSTOM:
memcpy(rtnrast, customextent, sizeof(struct rt_raster_serialized_t)); memcpy(rtnrast, customextent, sizeof(struct rt_raster_t));
break; break;
/* first, second, last */ /* first, second, last */
default: default:
memcpy(rtnrast, _param->raster[i], sizeof(struct rt_raster_serialized_t)); memcpy(rtnrast, _param->raster[i], sizeof(struct rt_raster_t));
break; break;
} }
rtnrast->numBands = 0; rtnrast->numBands = 0;
......
...@@ -1262,11 +1262,11 @@ rt_raster_compute_skewed_raster( ...@@ -1262,11 +1262,11 @@ rt_raster_compute_skewed_raster(
return NULL; return NULL;
} }
if (covers) if (!covers)
break; {
raster->width++;
raster->width++; raster->height++;
raster->height++; }
} }
while (!covers); while (!covers);
...@@ -1309,17 +1309,13 @@ rt_raster_compute_skewed_raster( ...@@ -1309,17 +1309,13 @@ rt_raster_compute_skewed_raster(
rt_raster_destroy(raster); rt_raster_destroy(raster);
return NULL; return NULL;
} }
} while (covers);
if (!covers) { if (i < 1)
if (i < 1) raster->width++;
raster->width++; else
else raster->height++;
raster->height++;
break;
}
}
while (covers);
} }
GEOSGeom_destroy(ngeom); GEOSGeom_destroy(ngeom);
...@@ -1336,7 +1332,7 @@ rt_raster_compute_skewed_raster( ...@@ -1336,7 +1332,7 @@ rt_raster_compute_skewed_raster(
*/ */
int int
rt_raster_is_empty(rt_raster raster) { rt_raster_is_empty(rt_raster raster) {
return (NULL == raster || raster->height <= 0 || raster->width <= 0); return (!raster || raster->height == 0 || raster->width == 0);
} }
/** /**
...@@ -2783,7 +2779,7 @@ rt_raster_gdal_rasterize( ...@@ -2783,7 +2779,7 @@ rt_raster_gdal_rasterize(
/* check alignment flag: grid_xw */ /* check alignment flag: grid_xw */
if ( if (
(NULL == ul_xw && NULL == ul_yw) && (NULL == ul_xw && NULL == ul_yw) &&
(NULL != grid_xw && NULL != grid_xw) && (NULL != grid_xw && NULL != grid_yw) &&
FLT_NEQ(*grid_xw, extent.MinX) FLT_NEQ(*grid_xw, extent.MinX)
) { ) {
/* do nothing */ /* do nothing */
...@@ -2798,7 +2794,7 @@ rt_raster_gdal_rasterize( ...@@ -2798,7 +2794,7 @@ rt_raster_gdal_rasterize(
/* check alignment flag: grid_yw */ /* check alignment flag: grid_yw */
if ( if (
(NULL == ul_xw && NULL == ul_yw) && (NULL == ul_xw && NULL == ul_yw) &&
(NULL != grid_xw && NULL != grid_xw) && (NULL != grid_xw && NULL != grid_yw) &&
FLT_NEQ(*grid_yw, extent.MaxY) FLT_NEQ(*grid_yw, extent.MaxY)
) { ) {
/* do nothing */ /* do nothing */
...@@ -2815,7 +2811,7 @@ rt_raster_gdal_rasterize( ...@@ -2815,7 +2811,7 @@ rt_raster_gdal_rasterize(
/* check alignment flag: grid_xw */ /* check alignment flag: grid_xw */
if ( if (
(NULL == ul_xw && NULL == ul_yw) && (NULL == ul_xw && NULL == ul_yw) &&
(NULL != grid_xw && NULL != grid_xw) && (NULL != grid_xw && NULL != grid_yw) &&
FLT_NEQ(*grid_xw, extent.MinX) FLT_NEQ(*grid_xw, extent.MinX)
) { ) {
/* do nothing */ /* do nothing */
...@@ -2831,7 +2827,7 @@ rt_raster_gdal_rasterize( ...@@ -2831,7 +2827,7 @@ rt_raster_gdal_rasterize(
/* check alignment flag: grid_yw */ /* check alignment flag: grid_yw */
if ( if (
(NULL == ul_xw && NULL == ul_yw) && (NULL == ul_xw && NULL == ul_yw) &&
(NULL != grid_xw && NULL != grid_xw) && (NULL != grid_xw && NULL != grid_yw) &&
FLT_NEQ(*grid_yw, extent.MaxY) FLT_NEQ(*grid_yw, extent.MaxY)
) { ) {
/* do nothing */ /* do nothing */
......
...@@ -995,7 +995,6 @@ rt_raster_intersects( ...@@ -995,7 +995,6 @@ rt_raster_intersects(
int *intersects int *intersects
) { ) {
int i; int i;
int j;
int within = 0; int within = 0;
LWGEOM *hull[2] = {NULL}; LWGEOM *hull[2] = {NULL};
...@@ -1069,27 +1068,28 @@ rt_raster_intersects( ...@@ -1069,27 +1068,28 @@ rt_raster_intersects(
initGEOS(rtinfo, lwgeom_geos_error); initGEOS(rtinfo, lwgeom_geos_error);
rtn = 1; rtn = 1;
for (i = 0; i < 2; i++) {
if ((rt_raster_get_convex_hull(i < 1 ? rast1 : rast2, &(hull[i])) != ES_NONE) || NULL == hull[i]) { if ((rt_raster_get_convex_hull(rast1, &(hull[0])) != ES_NONE) || !hull[0]) {
for (j = 0; j < i; j++) { break;
GEOSGeom_destroy(ghull[j]); }
lwgeom_free(hull[j]); ghull[0] = (GEOSGeometry *) LWGEOM2GEOS(hull[0], 0);
} if (!ghull[0]) {
rtn = 0; lwgeom_free(hull[0]);
break; break;
} }
ghull[i] = (GEOSGeometry *) LWGEOM2GEOS(hull[i], 0);
if (NULL == ghull[i]) { if ((rt_raster_get_convex_hull(rast2, &(hull[1])) != ES_NONE) || !hull[1]) {
for (j = 0; j < i; j++) { GEOSGeom_destroy(ghull[0]);
GEOSGeom_destroy(ghull[j]); lwgeom_free(hull[0]);
lwgeom_free(hull[j]); break;
} }
lwgeom_free(hull[i]); ghull[1] = (GEOSGeometry *) LWGEOM2GEOS(hull[1], 0);
rtn = 0; if (!ghull[0]) {
break; GEOSGeom_destroy(ghull[0]);
} lwgeom_free(hull[1]);
lwgeom_free(hull[0]);
break;
} }
if (!rtn) break;
/* test to see if raster within the other */ /* test to see if raster within the other */
within = 0; within = 0;
......
...@@ -1312,7 +1312,7 @@ Datum RASTER_tile(PG_FUNCTION_ARGS) ...@@ -1312,7 +1312,7 @@ Datum RASTER_tile(PG_FUNCTION_ARGS)
int nband = arg2->nbands[i] + 1; int nband = arg2->nbands[i] + 1;
rt_raster_destroy(tile); rt_raster_destroy(tile);
rt_raster_destroy(arg2->raster.raster); rt_raster_destroy(arg2->raster.raster);
if (arg2->numbands) pfree(arg2->nbands); pfree(arg2->nbands);
pfree(arg2); pfree(arg2);
elog(ERROR, "RASTER_tile: Could not get band %d from source raster", nband); elog(ERROR, "RASTER_tile: Could not get band %d from source raster", nband);
SRF_RETURN_DONE(funcctx); SRF_RETURN_DONE(funcctx);
...@@ -1343,7 +1343,7 @@ Datum RASTER_tile(PG_FUNCTION_ARGS) ...@@ -1343,7 +1343,7 @@ Datum RASTER_tile(PG_FUNCTION_ARGS)
if (band == NULL) { if (band == NULL) {
rt_raster_destroy(tile); rt_raster_destroy(tile);
rt_raster_destroy(arg2->raster.raster); rt_raster_destroy(arg2->raster.raster);
if (arg2->numbands) pfree(arg2->nbands); pfree(arg2->nbands);
pfree(arg2); pfree(arg2);
elog(ERROR, "RASTER_tile: Could not get newly added band from output tile"); elog(ERROR, "RASTER_tile: Could not get newly added band from output tile");
SRF_RETURN_DONE(funcctx); SRF_RETURN_DONE(funcctx);
...@@ -1368,7 +1368,7 @@ Datum RASTER_tile(PG_FUNCTION_ARGS) ...@@ -1368,7 +1368,7 @@ Datum RASTER_tile(PG_FUNCTION_ARGS)
if (rt_band_get_pixel_line(_band, rx, k, len, &vals, &nvals) != ES_NONE) { if (rt_band_get_pixel_line(_band, rx, k, len, &vals, &nvals) != ES_NONE) {
rt_raster_destroy(tile); rt_raster_destroy(tile);
rt_raster_destroy(arg2->raster.raster); rt_raster_destroy(arg2->raster.raster);
if (arg2->numbands) pfree(arg2->nbands); pfree(arg2->nbands);
pfree(arg2); pfree(arg2);
elog(ERROR, "RASTER_tile: Could not get pixel line from source raster"); elog(ERROR, "RASTER_tile: Could not get pixel line from source raster");
SRF_RETURN_DONE(funcctx); SRF_RETURN_DONE(funcctx);
...@@ -1377,7 +1377,7 @@ Datum RASTER_tile(PG_FUNCTION_ARGS) ...@@ -1377,7 +1377,7 @@ Datum RASTER_tile(PG_FUNCTION_ARGS)
if (nvals && rt_band_set_pixel_line(band, 0, j, vals, nvals) != ES_NONE) { if (nvals && rt_band_set_pixel_line(band, 0, j, vals, nvals) != ES_NONE) {
rt_raster_destroy(tile); rt_raster_destroy(tile);
rt_raster_destroy(arg2->raster.raster); rt_raster_destroy(arg2->raster.raster);
if (arg2->numbands) pfree(arg2->nbands); pfree(arg2->nbands);
pfree(arg2); pfree(arg2);
elog(ERROR, "RASTER_tile: Could not set pixel line of output tile"); elog(ERROR, "RASTER_tile: Could not set pixel line of output tile");
SRF_RETURN_DONE(funcctx); SRF_RETURN_DONE(funcctx);
...@@ -1399,7 +1399,7 @@ Datum RASTER_tile(PG_FUNCTION_ARGS) ...@@ -1399,7 +1399,7 @@ Datum RASTER_tile(PG_FUNCTION_ARGS)
if (band == NULL) { if (band == NULL) {
rt_raster_destroy(tile); rt_raster_destroy(tile);
rt_raster_destroy(arg2->raster.raster); rt_raster_destroy(arg2->raster.raster);
if (arg2->numbands) pfree(arg2->nbands); pfree(arg2->nbands);
pfree(arg2); pfree(arg2);
elog(ERROR, "RASTER_tile: Could not create new offline band for output tile"); elog(ERROR, "RASTER_tile: Could not create new offline band for output tile");
SRF_RETURN_DONE(funcctx); SRF_RETURN_DONE(funcctx);
...@@ -1409,7 +1409,7 @@ Datum RASTER_tile(PG_FUNCTION_ARGS) ...@@ -1409,7 +1409,7 @@ Datum RASTER_tile(PG_FUNCTION_ARGS)
rt_band_destroy(band); rt_band_destroy(band);
rt_raster_destroy(tile); rt_raster_destroy(tile);
rt_raster_destroy(arg2->raster.raster); rt_raster_destroy(arg2->raster.raster);
if (arg2->numbands) pfree(arg2->nbands); pfree(arg2->nbands);
pfree(arg2); pfree(arg2);
elog(ERROR, "RASTER_tile: Could not add new offline band to output tile"); elog(ERROR, "RASTER_tile: Could not add new offline band to output tile");
SRF_RETURN_DONE(funcctx); SRF_RETURN_DONE(funcctx);
...@@ -1482,9 +1482,7 @@ Datum RASTER_band(PG_FUNCTION_ARGS) ...@@ -1482,9 +1482,7 @@ Datum RASTER_band(PG_FUNCTION_ARGS)
elog(NOTICE, "Band number(s) not provided. Returning original raster"); elog(NOTICE, "Band number(s) not provided. Returning original raster");
skip = TRUE; skip = TRUE;
} }
do { if (!skip) {
if (skip) break;
numBands = rt_raster_get_num_bands(raster); numBands = rt_raster_get_num_bands(raster);
array = PG_GETARG_ARRAYTYPE_P(1); array = PG_GETARG_ARRAYTYPE_P(1);
...@@ -1521,7 +1519,7 @@ Datum RASTER_band(PG_FUNCTION_ARGS) ...@@ -1521,7 +1519,7 @@ Datum RASTER_band(PG_FUNCTION_ARGS)
POSTGIS_RT_DEBUGF(3, "band idx (before): %d", idx); POSTGIS_RT_DEBUGF(3, "band idx (before): %d", idx);
if (idx > numBands || idx < 1) { if (idx > numBands || idx < 1) {
elog(NOTICE, "Invalid band index (must use 1-based). Returning original raster"); elog(NOTICE, "Invalid band index (must use 1-based). Returning original raster");
skip = TRUE; skip = TRUE;
break; break;
} }
...@@ -1536,7 +1534,6 @@ Datum RASTER_band(PG_FUNCTION_ARGS) ...@@ -1536,7 +1534,6 @@ Datum RASTER_band(PG_FUNCTION_ARGS)
skip = TRUE; skip = TRUE;
} }
} }
while (0);
if (!skip) { if (!skip) {
rast = rt_raster_from_band(raster, bandNums, j); rast = rt_raster_from_band(raster, bandNums, j);
......
...@@ -250,7 +250,7 @@ Datum RASTER_asGDALRaster(PG_FUNCTION_ARGS) ...@@ -250,7 +250,7 @@ Datum RASTER_asGDALRaster(PG_FUNCTION_ARGS)
if (strlen(option)) { if (strlen(option)) {
options[j] = (char *) palloc(sizeof(char) * (strlen(option) + 1)); options[j] = (char *) palloc(sizeof(char) * (strlen(option) + 1));
options[j] = option; strcpy(options[j], option);
j++; j++;
} }
} }
...@@ -323,15 +323,8 @@ Datum RASTER_asGDALRaster(PG_FUNCTION_ARGS) ...@@ -323,15 +323,8 @@ Datum RASTER_asGDALRaster(PG_FUNCTION_ARGS)
SET_VARSIZE(result, result_size); SET_VARSIZE(result, result_size);
memcpy(VARDATA(result), gdal, VARSIZE(result) - VARHDRSZ); memcpy(VARDATA(result), gdal, VARSIZE(result) - VARHDRSZ);
/* for test output
FILE *fh = NULL;
fh = fopen("/tmp/out.dat", "w");
fwrite(gdal, sizeof(uint8_t), gdal_size, fh);
fclose(fh);
*/
/* free gdal mem buffer */ /* free gdal mem buffer */
if (gdal) CPLFree(gdal); CPLFree(gdal);
POSTGIS_RT_DEBUG(3, "RASTER_asGDALRaster: Returning pointer to GDAL raster"); POSTGIS_RT_DEBUG(3, "RASTER_asGDALRaster: Returning pointer to GDAL raster");
PG_RETURN_POINTER(result); PG_RETURN_POINTER(result);
...@@ -649,7 +642,7 @@ Datum RASTER_GDALWarp(PG_FUNCTION_ARGS) ...@@ -649,7 +642,7 @@ Datum RASTER_GDALWarp(PG_FUNCTION_ARGS)
dst_srs = rtpg_getSR(dst_srid); dst_srs = rtpg_getSR(dst_srid);
if (NULL == dst_srs) { if (NULL == dst_srs) {
if (!no_srid) pfree(src_srs); pfree(src_srs);
rt_raster_destroy(raster); rt_raster_destroy(raster);
PG_FREE_IF_COPY(pgraster, 0); PG_FREE_IF_COPY(pgraster, 0);
elog(ERROR, "RASTER_GDALWarp: Target SRID (%d) is unknown", dst_srid); elog(ERROR, "RASTER_GDALWarp: Target SRID (%d) is unknown", dst_srid);
......
...@@ -1199,7 +1199,7 @@ Datum RASTER_asRaster(PG_FUNCTION_ARGS) ...@@ -1199,7 +1199,7 @@ Datum RASTER_asRaster(PG_FUNCTION_ARGS)
/* all touched */ /* all touched */
if (!PG_ARGISNULL(14) && PG_GETARG_BOOL(14) == TRUE) { if (!PG_ARGISNULL(14) && PG_GETARG_BOOL(14) == TRUE) {
if (options_len < 1) { if (options_len == 0) {
options_len = 1; options_len = 1;
options = (char **) palloc(sizeof(char *) * options_len); options = (char **) palloc(sizeof(char *) * options_len);
} }
...@@ -1209,7 +1209,7 @@ Datum RASTER_asRaster(PG_FUNCTION_ARGS) ...@@ -1209,7 +1209,7 @@ Datum RASTER_asRaster(PG_FUNCTION_ARGS)
} }
options[options_len - 1] = palloc(sizeof(char*) * (strlen("ALL_TOUCHED=TRUE") + 1)); options[options_len - 1] = palloc(sizeof(char*) * (strlen("ALL_TOUCHED=TRUE") + 1));
options[options_len - 1] = "ALL_TOUCHED=TRUE"; strcpy(options[options_len - 1], "ALL_TOUCHED=TRUE");
} }
if (options_len) { if (options_len) {
......
...@@ -1050,7 +1050,7 @@ static int rtpg_nmapalgebraexpr_callback( ...@@ -1050,7 +1050,7 @@ static int rtpg_nmapalgebraexpr_callback(
rtpg_nmapalgebraexpr_callback_arg *callback = (rtpg_nmapalgebraexpr_callback_arg *) userarg; rtpg_nmapalgebraexpr_callback_arg *callback = (rtpg_nmapalgebraexpr_callback_arg *) userarg;
SPIPlanPtr plan = NULL; SPIPlanPtr plan = NULL;
int i = 0; int i = 0;
int id = -1; uint8_t id = 0;
if (arg == NULL) if (arg == NULL)
return 0; return 0;
...@@ -4715,8 +4715,7 @@ Datum RASTER_mapAlgebraExpr(PG_FUNCTION_ARGS) ...@@ -4715,8 +4715,7 @@ Datum RASTER_mapAlgebraExpr(PG_FUNCTION_ARGS)
POSTGIS_RT_DEBUGF(4, "RASTER_mapAlgebraExpr: New raster now has %d bands", POSTGIS_RT_DEBUGF(4, "RASTER_mapAlgebraExpr: New raster now has %d bands",
rt_raster_get_num_bands(newrast)); rt_raster_get_num_bands(newrast));
if (initexpr) pfree(initexpr);
pfree(initexpr);
rt_raster_destroy(raster); rt_raster_destroy(raster);
PG_FREE_IF_COPY(pgraster, 0); PG_FREE_IF_COPY(pgraster, 0);
...@@ -7004,13 +7003,13 @@ Datum RASTER_mapAlgebra2(PG_FUNCTION_ARGS) ...@@ -7004,13 +7003,13 @@ Datum RASTER_mapAlgebra2(PG_FUNCTION_ARGS)
else if (spi_plan[i] != NULL) { else if (spi_plan[i] != NULL) {
POSTGIS_RT_DEBUGF(4, "Using prepared plan: %d", i); POSTGIS_RT_DEBUGF(4, "Using prepared plan: %d", i);
/* reset values to (Datum) NULL */
memset(values, (Datum) NULL, sizeof(Datum) * argkwcount);
/* reset nulls to FALSE */
memset(nulls, FALSE, sizeof(char) * argkwcount);
/* expression has argument(s) */ /* expression has argument(s) */
if (spi_argcount[i]) { if (spi_argcount[i]) {
/* reset values to (Datum) NULL */
memset(values, (Datum) NULL, sizeof(Datum) * argkwcount);
/* reset nulls to FALSE */
memset(nulls, FALSE, sizeof(char) * argkwcount);
/* set values and nulls */ /* set values and nulls */
for (j = 0; j < argkwcount; j++) { for (j = 0; j < argkwcount; j++) {
idx = argpos[i][j]; idx = argpos[i][j];
......
This diff is collapsed.
...@@ -240,8 +240,8 @@ static int testRasterIterator3_callback(rt_iterator_arg arg, void *userarg, doub ...@@ -240,8 +240,8 @@ static int testRasterIterator3_callback(rt_iterator_arg arg, void *userarg, doub
} }
/* 0,2 */ /* 0,2 */
else if ( else if (
arg->dst_pixel[0] == 3 && arg->dst_pixel[0] == 0 &&
arg->dst_pixel[1] == 3 arg->dst_pixel[1] == 2
) { ) {
CU_ASSERT_DOUBLE_EQUAL(arg->values[0][0][0], 16, DBL_EPSILON); CU_ASSERT_DOUBLE_EQUAL(arg->values[0][0][0], 16, DBL_EPSILON);
CU_ASSERT_EQUAL(arg->nodata[0][0][0], 0); CU_ASSERT_EQUAL(arg->nodata[0][0][0], 0);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment