Skip to content

Commit

Permalink
Explicit error message when dimensions requested exceeds the maximum
Browse files Browse the repository at this point in the history
permitted of a raster.

git-svn-id: http://svn.osgeo.org/postgis/trunk@9838 b70326c6-7e19-0410-871a-916f4a2858ee
  • Loading branch information
Bborie Park committed May 31, 2012
1 parent 94b1778 commit 923d8f8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 29 deletions.
59 changes: 31 additions & 28 deletions raster/rt_core/rt_api.c
Expand Up @@ -1179,9 +1179,7 @@ rt_band_new_inline(
return NULL;
}

RASTER_DEBUGF(3, "Created rt_band @ %p with pixtype %s",
band, rt_pixtype_name(pixtype)
);
RASTER_DEBUGF(3, "Created rt_band @ %p with pixtype %s", band, rt_pixtype_name(pixtype));

band->pixtype = pixtype;
band->offline = 0;
Expand All @@ -1194,6 +1192,8 @@ rt_band_new_inline(
band->isnodata = FALSE;
band->raster = NULL;

RASTER_DEBUGF(3, "Created rt_band with dimensions %d x %d", band->width, band->height);

/* properly set nodataval as it may need to be constrained to the data type */
if (hasnodata && rt_band_set_nodata(band, nodataval) < 0) {
rterror("rt_band_new_inline: Unable to set NODATA value");
Expand Down Expand Up @@ -1843,7 +1843,7 @@ rt_band_set_pixel_line(
x < 0 || x >= band->width ||
y < 0 || y >= band->height
) {
rterror("rt_band_set_pixel_line: Coordinates out of range");
rterror("rt_band_set_pixel_line: Coordinates out of range (%d, %d) vs (%d, %d)", x, y, band->width, band->height);
return 0;
}

Expand Down Expand Up @@ -4751,36 +4751,37 @@ rt_band_reclass(rt_band srcband, rt_pixtype pixtype,
/*- rt_raster --------------------------------------------------------*/

rt_raster
rt_raster_new(uint16_t width, uint16_t height) {
rt_raster ret = NULL;
rt_raster_new(uint32_t width, uint32_t height) {
rt_raster ret = NULL;

ret = (rt_raster) rtalloc(sizeof (struct rt_raster_t));
if (!ret) {
rterror("rt_raster_new: Out of virtual memory creating an rt_raster");
return NULL;
}

RASTER_DEBUGF(3, "Created rt_raster @ %p", ret);

ret = (rt_raster) rtalloc(sizeof (struct rt_raster_t));
if (!ret) {
rterror("rt_raster_new: Out of virtual memory creating an rt_raster");
return 0;
}

RASTER_DEBUGF(3, "Created rt_raster @ %p", ret);

assert(NULL != ret);

ret->width = width;
assert(NULL != ret);

ret->height = height;
ret->scaleX = 1;
ret->scaleY = 1;
ret->ipX = 0.0;
ret->ipY = 0.0;
ret->skewX = 0.0;
ret->skewY = 0.0;
ret->srid = SRID_UNKNOWN;
if (width > 65535 || height > 65535) {
rterror("rt_raster_new: Dimensions requested exceed the maximum (65535 x 65535) permitted for a raster");
return NULL;
}

ret->numBands = 0;
ret->bands = 0;
ret->width = width;
ret->height = height;
ret->scaleX = 1;
ret->scaleY = 1;
ret->ipX = 0.0;
ret->ipY = 0.0;
ret->skewX = 0.0;
ret->skewY = 0.0;
ret->srid = SRID_UNKNOWN;

return ret;
ret->numBands = 0;
ret->bands = 0;
return ret;
}

void
Expand Down Expand Up @@ -8485,6 +8486,7 @@ rt_raster_from_gdal_dataset(GDALDatasetH ds) {
rterror("rt_raster_from_gdal_dataset: Out of memory allocating new raster");
return NULL;
}
RASTER_DEBUGF(3, "Created raster dimensions (width x height): %d x %d", rast->width, rast->height);

/* get raster attributes */
cplerr = GDALGetGeoTransform(ds, gt);
Expand Down Expand Up @@ -8566,6 +8568,7 @@ rt_raster_from_gdal_dataset(GDALDatasetH ds) {
return NULL;
}
band = rt_raster_get_band(rast, idx);
RASTER_DEBUGF(3, "Created band of dimension (width x height): %d x %d", band->width, band->height);

/* this makes use of GDAL's "natural" blocks */
GDALGetBlockSize(gdband, &nXBlockSize, &nYBlockSize);
Expand Down
2 changes: 1 addition & 1 deletion raster/rt_core/rt_api.h
Expand Up @@ -765,7 +765,7 @@ rt_band rt_band_reclass(rt_band srcband, rt_pixtype pixtype,
*
* @return an rt_raster or 0 if out of memory
*/
rt_raster rt_raster_new(uint16_t width, uint16_t height);
rt_raster rt_raster_new(uint32_t width, uint32_t height);

/**
* Construct an rt_raster from a binary WKB representation
Expand Down

0 comments on commit 923d8f8

Please sign in to comment.