PostGIS  2.3.7dev-r@@SVN_REVISION@@
static void test_raster_surface ( )
static

Definition at line 255 of file cu_raster_geometry.c.

References ovdump::band, cu_add_band(), cu_free_raster(), ES_NONE, lwgeom_to_text(), lwmpoly_as_lwgeom(), lwmpoly_free(), PT_32BUI, rtpixdump::rast, rt_band_set_pixel(), rt_raster_new(), rt_raster_set_offsets(), rt_raster_set_scale(), rt_raster_surface(), rtdealloc(), pixval::x, and pixval::y.

Referenced by raster_geometry_suite_setup().

255  {
256  rt_raster rast;
257  rt_band band;
258  const int maxX = 5;
259  const int maxY = 5;
260  int x, y;
261  char *wkt = NULL;
262  LWMPOLY *mpoly = NULL;
263  int err;
264 
265  rast = rt_raster_new(maxX, maxY);
266  CU_ASSERT(rast != NULL);
267 
268  rt_raster_set_offsets(rast, 0, 0);
269  rt_raster_set_scale(rast, 1, -1);
270 
271  band = cu_add_band(rast, PT_32BUI, 1, 0);
272  CU_ASSERT(band != NULL);
273 
274  for (y = 0; y < maxY; y++) {
275  for (x = 0; x < maxX; x++) {
276  rt_band_set_pixel(band, x, y, 1, NULL);
277  }
278  }
279 
280  err = rt_raster_surface(rast, 0, &mpoly);
281  CU_ASSERT_EQUAL(err, ES_NONE);
282  CU_ASSERT(mpoly != NULL);
283  wkt = lwgeom_to_text(lwmpoly_as_lwgeom(mpoly));
284  CU_ASSERT_STRING_EQUAL(wkt, "MULTIPOLYGON(((0 0,0 -5,5 -5,5 0,0 0)))");
285  rtdealloc(wkt);
286  lwmpoly_free(mpoly);
287  mpoly = NULL;
288 
289  /* 0,0 NODATA */
290  rt_band_set_pixel(band, 0, 0, 0, NULL);
291 
292  err = rt_raster_surface(rast, 0, &mpoly);
293  CU_ASSERT_EQUAL(err, ES_NONE);
294  CU_ASSERT(mpoly != NULL);
295  wkt = lwgeom_to_text(lwmpoly_as_lwgeom(mpoly));
296  CU_ASSERT_STRING_EQUAL(wkt, "MULTIPOLYGON(((1 0,1 -1,0 -1,0 -5,4 -5,5 -5,5 0,1 0)))");
297  rtdealloc(wkt);
298  lwmpoly_free(mpoly);
299  mpoly = NULL;
300 
301  /* plus 1,1 NODATA */
302  rt_band_set_pixel(band, 1, 1, 0, NULL);
303 
304  err = rt_raster_surface(rast, 0, &mpoly);
305  CU_ASSERT_EQUAL(err, ES_NONE);
306  CU_ASSERT(mpoly != NULL);
307  wkt = lwgeom_to_text(lwmpoly_as_lwgeom(mpoly));
308  CU_ASSERT_STRING_EQUAL(wkt, "MULTIPOLYGON(((1 0,1 -1,0 -1,0 -5,4 -5,5 -5,5 0,1 0),(1 -1,1 -2,2 -2,2 -1,1 -1)))");
309  rtdealloc(wkt);
310  lwmpoly_free(mpoly);
311  mpoly = NULL;
312 
313  /* plus 2,2 NODATA */
314  rt_band_set_pixel(band, 2, 2, 0, NULL);
315 
316  err = rt_raster_surface(rast, 0, &mpoly);
317  CU_ASSERT_EQUAL(err, ES_NONE);
318  CU_ASSERT(mpoly != NULL);
319  wkt = lwgeom_to_text(lwmpoly_as_lwgeom(mpoly));
320 
321  CU_ASSERT_STRING_EQUAL(wkt, "MULTIPOLYGON(((1 -1,1 0,5 0,5 -5,4 -5,0 -5,0 -1,1 -1),(1 -1,1 -2,2 -2,2 -1,1 -1),(2 -2,2 -3,3 -3,3 -2,2 -2)))");
322 
323  rtdealloc(wkt);
324  lwmpoly_free(mpoly);
325  mpoly = NULL;
326 
327  /* plus 3,3 NODATA */
328  rt_band_set_pixel(band, 3, 3, 0, NULL);
329 
330  err = rt_raster_surface(rast, 0, &mpoly);
331  CU_ASSERT_EQUAL(err, ES_NONE);
332  CU_ASSERT(mpoly != NULL);
333  wkt = lwgeom_to_text(lwmpoly_as_lwgeom(mpoly));
334 
335  CU_ASSERT_STRING_EQUAL(wkt, "MULTIPOLYGON(((1 -1,1 0,5 0,5 -5,4 -5,0 -5,0 -1,1 -1),(1 -1,1 -2,2 -2,2 -1,1 -1),(2 -2,2 -3,3 -3,3 -2,2 -2),(3 -3,3 -4,4 -4,4 -3,3 -3)))");
336 
337  rtdealloc(wkt);
338  lwmpoly_free(mpoly);
339  mpoly = NULL;
340 
341  /* plus 4,4 NODATA */
342  rt_band_set_pixel(band, 4, 4, 0, NULL);
343 
344  err = rt_raster_surface(rast, 0, &mpoly);
345  CU_ASSERT_EQUAL(err, ES_NONE);
346  CU_ASSERT(mpoly != NULL);
347  wkt = lwgeom_to_text(lwmpoly_as_lwgeom(mpoly));
348  CU_ASSERT_STRING_EQUAL(wkt, "MULTIPOLYGON(((4 -4,4 -5,0 -5,0 -1,1 -1,1 -2,2 -2,2 -3,3 -3,3 -4,4 -4)),((1 -1,1 0,5 0,5 -4,4 -4,4 -3,3 -3,3 -2,2 -2,2 -1,1 -1)))");
349  rtdealloc(wkt);
350  lwmpoly_free(mpoly);
351  mpoly = NULL;
352 
353  /* a whole lot more NODATA */
354  rt_band_set_pixel(band, 4, 0, 0, NULL);
355  rt_band_set_pixel(band, 3, 1, 0, NULL);
356  rt_band_set_pixel(band, 1, 3, 0, NULL);
357  rt_band_set_pixel(band, 0, 4, 0, NULL);
358 
359  err = rt_raster_surface(rast, 0, &mpoly);
360  CU_ASSERT_EQUAL(err, ES_NONE);
361  CU_ASSERT(mpoly != NULL);
362  wkt = lwgeom_to_text(lwmpoly_as_lwgeom(mpoly));
363  CU_ASSERT_STRING_EQUAL(wkt, "MULTIPOLYGON(((1 -4,2 -4,2 -3,3 -3,3 -4,4 -4,4 -5,3 -5,1 -5,1 -4)),((1 -4,0 -4,0 -1,1 -1,1 -2,2 -2,2 -3,1 -3,1 -4)),((3 -2,4 -2,4 -1,5 -1,5 -4,4 -4,4 -3,3 -3,3 -2)),((3 -2,2 -2,2 -1,1 -1,1 0,4 0,4 -1,3 -1,3 -2)))");
364  rtdealloc(wkt);
365  lwmpoly_free(mpoly);
366  mpoly = NULL;
367 
368  cu_free_raster(rast);
369 }
tuple band
Definition: ovdump.py:57
tuple rast
Definition: rtpixdump.py:61
void cu_free_raster(rt_raster raster)
rt_band cu_add_band(rt_raster raster, rt_pixtype pixtype, int hasnodata, double nodataval)
rt_errorstate rt_raster_surface(rt_raster raster, int nband, LWMPOLY **surface)
Get a raster as a surface (multipolygon).
Definition: rt_geometry.c:355
void lwmpoly_free(LWMPOLY *mpoly)
Definition: lwmpoly.c:53
void rt_raster_set_scale(rt_raster raster, double scaleX, double scaleY)
Set scale in projection units.
Definition: rt_raster.c:137
void rt_raster_set_offsets(rt_raster raster, double x, double y)
Set insertion points in projection units.
Definition: rt_raster.c:199
rt_raster rt_raster_new(uint32_t width, uint32_t height)
Construct a raster with given dimensions.
Definition: rt_raster.c:48
tuple x
Definition: pixval.py:53
void rtdealloc(void *mem)
Definition: rt_context.c:186
rt_errorstate rt_band_set_pixel(rt_band band, int x, int y, double val, int *converted)
Set single pixel's value.
Definition: rt_band.c:841
static char * lwgeom_to_text(const LWGEOM *lwgeom)
LWGEOM * lwmpoly_as_lwgeom(const LWMPOLY *obj)
Definition: lwgeom.c:217
tuple y
Definition: pixval.py:54

Here is the call graph for this function:

Here is the caller graph for this function: