if (mpoly != NULL) {
/* convert to multi */
if (!lwgeom_is_collection(mpoly)) {
+ LWGEOM *tmp2 = NULL;
tmp = mpoly;
#if POSTGIS_DEBUG_LEVEL > 3
{
- char *wkt = NULL;
- wkt = lwgeom_to_wkt(mpoly, WKT_ISO, DBL_DIG, NULL);
+ char *wkt = lwgeom_to_wkt(mpoly, WKT_ISO, DBL_DIG, NULL);
RASTER_DEBUGF(4, "before multi = %s", wkt);
rtdealloc(wkt);
}
#endif
- mpoly = lwgeom_clone_deep(lwgeom_as_multi(tmp));
+ RASTER_DEBUGF(4, "mpoly @ %p", mpoly);
+
+ /*
+ lwgeom_as_multi() only does a shallow clone internally
+ so input and output geometries may share memory
+ */
+ mpoly = lwgeom_as_multi(tmp);
+ tmp2 = lwgeom_clone_deep(mpoly);
lwgeom_free(tmp);
+ lwgeom_free(mpoly);
+ mpoly = tmp2;
+
+ RASTER_DEBUGF(4, "mpoly @ %p", mpoly);
#if POSTGIS_DEBUG_LEVEL > 3
{
- char *wkt = NULL;
- wkt = lwgeom_to_wkt(mpoly, WKT_ISO, DBL_DIG, NULL);
+ char *wkt = lwgeom_to_wkt(mpoly, WKT_ISO, DBL_DIG, NULL);
RASTER_DEBUGF(4, "after multi = %s", wkt);
rtdealloc(wkt);
}
#endif
-
}
#if POSTGIS_DEBUG_LEVEL > 3
{
- char *wkt = NULL;
- wkt = lwgeom_to_wkt(mpoly, WKT_ISO, DBL_DIG, NULL);
+ char *wkt = lwgeom_to_wkt(mpoly, WKT_ISO, DBL_DIG, NULL);
RASTER_DEBUGF(4, "returning geometry = %s", wkt);
rtdealloc(wkt);
}
deepRelease(rast);
}
+static void testPixelAsPolygon() {
+ rt_raster rast;
+ rt_band band;
+ uint32_t x, y;
+ int rtn;
+ const int maxX = 10;
+ const int maxY = 10;
+ LWPOLY *poly = NULL;
+
+ rast = rt_raster_new(maxX, maxY);
+ assert(rast);
+
+ band = addBand(rast, PT_32BUI, 1, 0);
+ CHECK(band);
+
+ for (x = 0; x < maxX; x++) {
+ for (y = 0; y < maxY; y++) {
+ rtn = rt_band_set_pixel(band, x, y, 1);
+ CHECK((rtn != -1));
+ }
+ }
+
+ rt_band_set_pixel(band, 0, 0, 0);
+ rt_band_set_pixel(band, 3, 0, 0);
+ rt_band_set_pixel(band, 6, 0, 0);
+ rt_band_set_pixel(band, 9, 0, 0);
+ rt_band_set_pixel(band, 1, 2, 0);
+ rt_band_set_pixel(band, 4, 2, 0);
+ rt_band_set_pixel(band, 7, 2, 0);
+ rt_band_set_pixel(band, 2, 4, 0);
+ rt_band_set_pixel(band, 5, 4, 0);
+ rt_band_set_pixel(band, 8, 4, 0);
+ rt_band_set_pixel(band, 0, 6, 0);
+ rt_band_set_pixel(band, 3, 6, 0);
+ rt_band_set_pixel(band, 6, 6, 0);
+ rt_band_set_pixel(band, 9, 6, 0);
+ rt_band_set_pixel(band, 1, 8, 0);
+ rt_band_set_pixel(band, 4, 8, 0);
+ rt_band_set_pixel(band, 7, 8, 0);
+
+ poly = rt_raster_pixel_as_polygon(rast, 1, 1);
+ CHECK((poly != NULL));
+ lwpoly_free(poly);
+
+ deepRelease(rast);
+}
+
static void testRasterSurface() {
rt_raster rast;
rt_band band;
mpoly = rt_raster_surface(rast, 0);
CHECK((mpoly != NULL));
- wkt = lwgeom_to_wkt((const LWGEOM *) lwmpoly_as_lwgeom(mpoly), WKT_ISO, DBL_DIG, NULL);
- RASTER_DEBUGF(4, "wkt = %s", wkt);
+ wkt = lwgeom_to_text(lwmpoly_as_lwgeom(mpoly));
CHECK(!strcmp(wkt, "MULTIPOLYGON(((0 0,1 0,2 0,3 0,4 0,5 0,5 -1,5 -2,5 -3,5 -4,5 -5,4 -5,3 -5,2 -5,1 -5,0 -5,0 -4,0 -3,0 -2,0 -1,0 0)))"));
rtdealloc(wkt);
lwmpoly_free(mpoly);
+ mpoly = NULL;
/* 0,0 NODATA */
rt_band_set_pixel(band, 0, 0, 0);
mpoly = rt_raster_surface(rast, 0);
CHECK((mpoly != NULL));
- wkt = lwgeom_to_wkt((const LWGEOM *) lwmpoly_as_lwgeom(mpoly), WKT_ISO, DBL_DIG, NULL);
- RASTER_DEBUGF(4, "wkt = %s", wkt);
+ wkt = lwgeom_to_text(lwmpoly_as_lwgeom(mpoly));
CHECK(!strcmp(wkt, "MULTIPOLYGON(((1 0,2 0,3 0,4 0,5 0,5 -1,5 -2,5 -3,5 -4,5 -5,4 -5,3 -5,2 -5,1 -5,0 -5,0 -4,0 -3,0 -2,0 -1,1 -1,1 0)))"));
rtdealloc(wkt);
lwmpoly_free(mpoly);
+ mpoly = NULL;
/* plus 1,1 NODATA */
rt_band_set_pixel(band, 1, 1, 0);
mpoly = rt_raster_surface(rast, 0);
CHECK((mpoly != NULL));
- wkt = lwgeom_to_wkt((const LWGEOM *) lwmpoly_as_lwgeom(mpoly), WKT_ISO, DBL_DIG, NULL);
- RASTER_DEBUGF(4, "wkt = %s", wkt);
+ wkt = lwgeom_to_text(lwmpoly_as_lwgeom(mpoly));
CHECK(!strcmp(wkt, "MULTIPOLYGON(((1 0,2 0,3 0,4 0,5 0,5 -1,5 -2,5 -3,5 -4,5 -5,4 -5,3 -5,2 -5,1 -5,0 -5,0 -4,0 -3,0 -2,0 -1,1 -1,1 0),(1 -1,1 -2,2 -2,2 -1,1 -1)))"));
rtdealloc(wkt);
lwmpoly_free(mpoly);
+ mpoly = NULL;
deepRelease(rast);
}
testPixelOfValue();
printf("OK\n");
+ printf("Testing rt_raster_pixel_as_polygon... ");
+ testPixelAsPolygon();
+ printf("OK\n");
+
printf("Testing rt_raster_surface... ");
testRasterSurface();
printf("OK\n");