From: Bborie Park Date: Wed, 24 Oct 2012 22:21:56 +0000 (+0000) Subject: Added checks to rt_raster_gdal_rasterize() and RASTER_asRaster() where X-Git-Tag: 2.1.0beta2~465 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=04434e7ef936a28e6d87bc6c0bb69c95db28c0a4;p=postgis Added checks to rt_raster_gdal_rasterize() and RASTER_asRaster() where if input geometry is empty, return empty raster. git-svn-id: http://svn.osgeo.org/postgis/trunk@10550 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/raster/rt_core/rt_api.c b/raster/rt_core/rt_api.c index e4b02b9e0..11761a047 100644 --- a/raster/rt_core/rt_api.c +++ b/raster/rt_core/rt_api.c @@ -10272,6 +10272,24 @@ rt_raster_gdal_rasterize(const unsigned char *wkb, return NULL; } + /* OGR Geometry is empty */ + if (OGR_G_IsEmpty(src_geom)) { + rtinfo("Geometry provided is empty. Returning empty raster"); + + if (noband) { + rtdealloc(_pixtype); + rtdealloc(_init); + rtdealloc(_nodata); + rtdealloc(_hasnodata); + rtdealloc(_value); + } + + OSRDestroySpatialReference(src_sr); + /* OGRCleanupAll(); */ + + return rt_raster_new(0, 0); + } + /* get envelope */ OGR_G_GetEnvelope(src_geom, &src_env); rt_util_from_ogr_envelope(src_env, &extent); diff --git a/raster/rt_pg/rt_pg.c b/raster/rt_pg/rt_pg.c index 1f28133ea..bca35f09b 100644 --- a/raster/rt_pg/rt_pg.c +++ b/raster/rt_pg/rt_pg.c @@ -10628,6 +10628,26 @@ Datum RASTER_asRaster(PG_FUNCTION_ARGS) geom = geom2d; } + /* empty geometry, return empty raster */ + if (lwgeom_is_empty(geom)) { + POSTGIS_RT_DEBUG(3, "Input geometry is empty. Returning empty raster"); + lwgeom_free(geom); + PG_FREE_IF_COPY(gser, 0); + + rast = rt_raster_new(0, 0); + if (rast == NULL) + PG_RETURN_NULL(); + + pgrast = rt_raster_serialize(rast); + rt_raster_destroy(rast); + + if (NULL == pgrast) + PG_RETURN_NULL(); + + SET_VARSIZE(pgrast, pgrast->size); + PG_RETURN_POINTER(pgrast); + } + /* scale x */ if (!PG_ARGISNULL(1)) { scale[0] = PG_GETARG_FLOAT8(1);