]> granicus.if.org Git - postgis/commitdiff
Added checks to rt_raster_gdal_rasterize() and RASTER_asRaster() where
authorBborie Park <bkpark at ucdavis.edu>
Wed, 24 Oct 2012 22:21:56 +0000 (22:21 +0000)
committerBborie Park <bkpark at ucdavis.edu>
Wed, 24 Oct 2012 22:21:56 +0000 (22:21 +0000)
if input geometry is empty, return empty raster.

git-svn-id: http://svn.osgeo.org/postgis/trunk@10550 b70326c6-7e19-0410-871a-916f4a2858ee

raster/rt_core/rt_api.c
raster/rt_pg/rt_pg.c

index e4b02b9e0939174da9a12421afb568ad950205b0..11761a047498575ccfab6ccc2af398b3953177ec 100644 (file)
@@ -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);
index 1f28133eac79041ab6d8cb4efd3cd1bf7665d12f..bca35f09b58c8bef99264d7d2417a1b9d9e70ecf 100644 (file)
@@ -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);