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(
for (i = 0; i < itrcount; 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;
}
}
......@@ -1118,11 +1118,11 @@ rt_raster_iterator(
switch (extenttype) {
case ET_CUSTOM:
memcpy(rtnrast, customextent, sizeof(struct rt_raster_serialized_t));
memcpy(rtnrast, customextent, sizeof(struct rt_raster_t));
break;
/* first, second, last */
default:
memcpy(rtnrast, _param->raster[i], sizeof(struct rt_raster_serialized_t));
memcpy(rtnrast, _param->raster[i], sizeof(struct rt_raster_t));
break;
}
rtnrast->numBands = 0;
......
......@@ -1262,12 +1262,12 @@ rt_raster_compute_skewed_raster(
return NULL;
}
if (covers)
break;
if (!covers)
{
raster->width++;
raster->height++;
}
}
while (!covers);
RASTER_DEBUGF(4, "Skewed extent does cover normal extent with dimensions %d x %d", raster->width, raster->height);
......@@ -1309,17 +1309,13 @@ rt_raster_compute_skewed_raster(
rt_raster_destroy(raster);
return NULL;
}
} while (covers);
if (!covers) {
if (i < 1)
raster->width++;
else
raster->height++;
break;
}
}
while (covers);
}
GEOSGeom_destroy(ngeom);
......@@ -1336,7 +1332,7 @@ rt_raster_compute_skewed_raster(
*/
int
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(
/* check alignment flag: grid_xw */
if (
(NULL == ul_xw && NULL == ul_yw) &&
(NULL != grid_xw && NULL != grid_xw) &&
(NULL != grid_xw && NULL != grid_yw) &&
FLT_NEQ(*grid_xw, extent.MinX)
) {
/* do nothing */
......@@ -2798,7 +2794,7 @@ rt_raster_gdal_rasterize(
/* check alignment flag: grid_yw */
if (
(NULL == ul_xw && NULL == ul_yw) &&
(NULL != grid_xw && NULL != grid_xw) &&
(NULL != grid_xw && NULL != grid_yw) &&
FLT_NEQ(*grid_yw, extent.MaxY)
) {
/* do nothing */
......@@ -2815,7 +2811,7 @@ rt_raster_gdal_rasterize(
/* check alignment flag: grid_xw */
if (
(NULL == ul_xw && NULL == ul_yw) &&
(NULL != grid_xw && NULL != grid_xw) &&
(NULL != grid_xw && NULL != grid_yw) &&
FLT_NEQ(*grid_xw, extent.MinX)
) {
/* do nothing */
......@@ -2831,7 +2827,7 @@ rt_raster_gdal_rasterize(
/* check alignment flag: grid_yw */
if (
(NULL == ul_xw && NULL == ul_yw) &&
(NULL != grid_xw && NULL != grid_xw) &&
(NULL != grid_xw && NULL != grid_yw) &&
FLT_NEQ(*grid_yw, extent.MaxY)
) {
/* do nothing */
......
......@@ -995,7 +995,6 @@ rt_raster_intersects(
int *intersects
) {
int i;
int j;
int within = 0;
LWGEOM *hull[2] = {NULL};
......@@ -1069,27 +1068,28 @@ rt_raster_intersects(
initGEOS(rtinfo, lwgeom_geos_error);
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]) {
for (j = 0; j < i; j++) {
GEOSGeom_destroy(ghull[j]);
lwgeom_free(hull[j]);
}
rtn = 0;
if ((rt_raster_get_convex_hull(rast1, &(hull[0])) != ES_NONE) || !hull[0]) {
break;
}
ghull[i] = (GEOSGeometry *) LWGEOM2GEOS(hull[i], 0);
if (NULL == ghull[i]) {
for (j = 0; j < i; j++) {
GEOSGeom_destroy(ghull[j]);
lwgeom_free(hull[j]);
ghull[0] = (GEOSGeometry *) LWGEOM2GEOS(hull[0], 0);
if (!ghull[0]) {
lwgeom_free(hull[0]);
break;
}
lwgeom_free(hull[i]);
rtn = 0;
if ((rt_raster_get_convex_hull(rast2, &(hull[1])) != ES_NONE) || !hull[1]) {
GEOSGeom_destroy(ghull[0]);
lwgeom_free(hull[0]);
break;
}
ghull[1] = (GEOSGeometry *) LWGEOM2GEOS(hull[1], 0);
if (!ghull[0]) {
GEOSGeom_destroy(ghull[0]);
lwgeom_free(hull[1]);
lwgeom_free(hull[0]);
break;
}
if (!rtn) break;
/* test to see if raster within the other */
within = 0;
......
......@@ -1312,7 +1312,7 @@ Datum RASTER_tile(PG_FUNCTION_ARGS)
int nband = arg2->nbands[i] + 1;
rt_raster_destroy(tile);
rt_raster_destroy(arg2->raster.raster);
if (arg2->numbands) pfree(arg2->nbands);
pfree(arg2->nbands);
pfree(arg2);
elog(ERROR, "RASTER_tile: Could not get band %d from source raster", nband);
SRF_RETURN_DONE(funcctx);
......@@ -1343,7 +1343,7 @@ Datum RASTER_tile(PG_FUNCTION_ARGS)
if (band == NULL) {
rt_raster_destroy(tile);
rt_raster_destroy(arg2->raster.raster);
if (arg2->numbands) pfree(arg2->nbands);
pfree(arg2->nbands);
pfree(arg2);
elog(ERROR, "RASTER_tile: Could not get newly added band from output tile");
SRF_RETURN_DONE(funcctx);
......@@ -1368,7 +1368,7 @@ Datum RASTER_tile(PG_FUNCTION_ARGS)
if (rt_band_get_pixel_line(_band, rx, k, len, &vals, &nvals) != ES_NONE) {
rt_raster_destroy(tile);
rt_raster_destroy(arg2->raster.raster);
if (arg2->numbands) pfree(arg2->nbands);
pfree(arg2->nbands);
pfree(arg2);
elog(ERROR, "RASTER_tile: Could not get pixel line from source raster");
SRF_RETURN_DONE(funcctx);
......@@ -1377,7 +1377,7 @@ Datum RASTER_tile(PG_FUNCTION_ARGS)
if (nvals && rt_band_set_pixel_line(band, 0, j, vals, nvals) != ES_NONE) {
rt_raster_destroy(tile);
rt_raster_destroy(arg2->raster.raster);
if (arg2->numbands) pfree(arg2->nbands);
pfree(arg2->nbands);
pfree(arg2);
elog(ERROR, "RASTER_tile: Could not set pixel line of output tile");
SRF_RETURN_DONE(funcctx);
......@@ -1399,7 +1399,7 @@ Datum RASTER_tile(PG_FUNCTION_ARGS)
if (band == NULL) {
rt_raster_destroy(tile);
rt_raster_destroy(arg2->raster.raster);
if (arg2->numbands) pfree(arg2->nbands);
pfree(arg2->nbands);
pfree(arg2);
elog(ERROR, "RASTER_tile: Could not create new offline band for output tile");
SRF_RETURN_DONE(funcctx);
......@@ -1409,7 +1409,7 @@ Datum RASTER_tile(PG_FUNCTION_ARGS)
rt_band_destroy(band);
rt_raster_destroy(tile);
rt_raster_destroy(arg2->raster.raster);
if (arg2->numbands) pfree(arg2->nbands);
pfree(arg2->nbands);
pfree(arg2);
elog(ERROR, "RASTER_tile: Could not add new offline band to output tile");
SRF_RETURN_DONE(funcctx);
......@@ -1482,9 +1482,7 @@ Datum RASTER_band(PG_FUNCTION_ARGS)
elog(NOTICE, "Band number(s) not provided. Returning original raster");
skip = TRUE;
}
do {
if (skip) break;
if (!skip) {
numBands = rt_raster_get_num_bands(raster);
array = PG_GETARG_ARRAYTYPE_P(1);
......@@ -1536,7 +1534,6 @@ Datum RASTER_band(PG_FUNCTION_ARGS)
skip = TRUE;
}
}
while (0);
if (!skip) {
rast = rt_raster_from_band(raster, bandNums, j);
......
......@@ -250,7 +250,7 @@ Datum RASTER_asGDALRaster(PG_FUNCTION_ARGS)
if (strlen(option)) {
options[j] = (char *) palloc(sizeof(char) * (strlen(option) + 1));
options[j] = option;
strcpy(options[j], option);
j++;
}
}
......@@ -323,15 +323,8 @@ Datum RASTER_asGDALRaster(PG_FUNCTION_ARGS)
SET_VARSIZE(result, result_size);
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 */
if (gdal) CPLFree(gdal);
CPLFree(gdal);
POSTGIS_RT_DEBUG(3, "RASTER_asGDALRaster: Returning pointer to GDAL raster");
PG_RETURN_POINTER(result);
......@@ -649,7 +642,7 @@ Datum RASTER_GDALWarp(PG_FUNCTION_ARGS)
dst_srs = rtpg_getSR(dst_srid);
if (NULL == dst_srs) {
if (!no_srid) pfree(src_srs);
pfree(src_srs);
rt_raster_destroy(raster);
PG_FREE_IF_COPY(pgraster, 0);
elog(ERROR, "RASTER_GDALWarp: Target SRID (%d) is unknown", dst_srid);
......
......@@ -1199,7 +1199,7 @@ Datum RASTER_asRaster(PG_FUNCTION_ARGS)
/* all touched */
if (!PG_ARGISNULL(14) && PG_GETARG_BOOL(14) == TRUE) {
if (options_len < 1) {
if (options_len == 0) {
options_len = 1;
options = (char **) palloc(sizeof(char *) * options_len);
}
......@@ -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] = "ALL_TOUCHED=TRUE";
strcpy(options[options_len - 1], "ALL_TOUCHED=TRUE");
}
if (options_len) {
......
......@@ -1050,7 +1050,7 @@ static int rtpg_nmapalgebraexpr_callback(
rtpg_nmapalgebraexpr_callback_arg *callback = (rtpg_nmapalgebraexpr_callback_arg *) userarg;
SPIPlanPtr plan = NULL;
int i = 0;
int id = -1;
uint8_t id = 0;
if (arg == NULL)
return 0;
......@@ -4715,7 +4715,6 @@ Datum RASTER_mapAlgebraExpr(PG_FUNCTION_ARGS)
POSTGIS_RT_DEBUGF(4, "RASTER_mapAlgebraExpr: New raster now has %d bands",
rt_raster_get_num_bands(newrast));
if (initexpr)
pfree(initexpr);
rt_raster_destroy(raster);
PG_FREE_IF_COPY(pgraster, 0);
......@@ -7004,13 +7003,13 @@ Datum RASTER_mapAlgebra2(PG_FUNCTION_ARGS)
else if (spi_plan[i] != NULL) {
POSTGIS_RT_DEBUGF(4, "Using prepared plan: %d", i);
/* expression has argument(s) */
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);
/* expression has argument(s) */
if (spi_argcount[i]) {
/* set values and nulls */
for (j = 0; j < argkwcount; j++) {
idx = argpos[i][j];
......
This diff is collapsed.
......@@ -240,8 +240,8 @@ static int testRasterIterator3_callback(rt_iterator_arg arg, void *userarg, doub
}
/* 0,2 */
else if (
arg->dst_pixel[0] == 3 &&
arg->dst_pixel[1] == 3
arg->dst_pixel[0] == 0 &&
arg->dst_pixel[1] == 2
) {
CU_ASSERT_DOUBLE_EQUAL(arg->values[0][0][0], 16, DBL_EPSILON);
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