PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ test_raster_surface()

static void test_raster_surface ( )
static

Definition at line 255 of file cu_raster_geometry.c.

255  {
256  rt_raster rast;
257  rt_band band;
258  const int maxX = 5;
259  const int maxY = 5;
260  int x, y;
261  LWMPOLY *mpoly = NULL;
262  int err;
263  LWGEOM *gexpected, *gobserved;
264 
265  rast = rt_raster_new(maxX, maxY);
266  CU_ASSERT(rast != NULL);
267 
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  gobserved = (LWGEOM *)lwmpoly_as_lwgeom(mpoly);
285  gexpected = lwgeom_from_wkt("MULTIPOLYGON(((0 0,0 -5,5 -5,5 0,0 0)))", LW_PARSER_CHECK_NONE);
286  CU_ASSERT_DOUBLE_EQUAL(lwgeom_area(gobserved), lwgeom_area(gexpected), FLT_EPSILON);
287  lwmpoly_free(mpoly);
288  mpoly = NULL;
289 
290  /* 0,0 NODATA */
291  rt_band_set_pixel(band, 0, 0, 0, NULL);
292 
293  err = rt_raster_surface(rast, 0, &mpoly);
294  CU_ASSERT_EQUAL(err, ES_NONE);
295  CU_ASSERT(mpoly != NULL);
296  gobserved = (LWGEOM *)lwmpoly_as_lwgeom(mpoly);
297  gexpected = lwgeom_from_wkt("MULTIPOLYGON(((1 0,1 -1,0 -1,0 -5,4 -5,5 -5,5 0,1 0)))", LW_PARSER_CHECK_NONE);
298  CU_ASSERT_DOUBLE_EQUAL(lwgeom_area(gobserved), lwgeom_area(gexpected), FLT_EPSILON);
299  lwmpoly_free(mpoly);
300  mpoly = NULL;
301 
302  /* plus 1,1 NODATA */
303  rt_band_set_pixel(band, 1, 1, 0, NULL);
304 
305  err = rt_raster_surface(rast, 0, &mpoly);
306  CU_ASSERT_EQUAL(err, ES_NONE);
307  CU_ASSERT(mpoly != NULL);
308  gobserved = (LWGEOM *)lwmpoly_as_lwgeom(mpoly);
309  gexpected = lwgeom_from_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)))",
311  CU_ASSERT_DOUBLE_EQUAL(lwgeom_area(gobserved), lwgeom_area(gexpected), FLT_EPSILON);
312  lwmpoly_free(mpoly);
313  mpoly = NULL;
314 
315  /* plus 2,2 NODATA */
316  rt_band_set_pixel(band, 2, 2, 0, NULL);
317 
318  err = rt_raster_surface(rast, 0, &mpoly);
319  CU_ASSERT_EQUAL(err, ES_NONE);
320  CU_ASSERT(mpoly != NULL);
321  gobserved = (LWGEOM *)lwmpoly_as_lwgeom(mpoly);
322  gexpected = lwgeom_from_wkt(
323  "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)))",
325  CU_ASSERT_DOUBLE_EQUAL(lwgeom_area(gobserved), lwgeom_area(gexpected), FLT_EPSILON);
326  lwmpoly_free(mpoly);
327  mpoly = NULL;
328 
329  /* plus 3,3 NODATA */
330  rt_band_set_pixel(band, 3, 3, 0, NULL);
331 
332  err = rt_raster_surface(rast, 0, &mpoly);
333  CU_ASSERT_EQUAL(err, ES_NONE);
334  CU_ASSERT(mpoly != NULL);
335  gobserved = (LWGEOM *)lwmpoly_as_lwgeom(mpoly);
336  gexpected = lwgeom_from_wkt(
337  "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)))",
339  CU_ASSERT_DOUBLE_EQUAL(lwgeom_area(gobserved), lwgeom_area(gexpected), FLT_EPSILON);
340  lwmpoly_free(mpoly);
341  mpoly = NULL;
342 
343  /* plus 4,4 NODATA */
344  rt_band_set_pixel(band, 4, 4, 0, NULL);
345 
346  err = rt_raster_surface(rast, 0, &mpoly);
347  CU_ASSERT_EQUAL(err, ES_NONE);
348  CU_ASSERT(mpoly != NULL);
349  gobserved = (LWGEOM *)lwmpoly_as_lwgeom(mpoly);
350  gexpected = lwgeom_from_wkt(
351  "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)))",
353  CU_ASSERT_DOUBLE_EQUAL(lwgeom_area(gobserved), lwgeom_area(gexpected), FLT_EPSILON);
354  lwmpoly_free(mpoly);
355  mpoly = NULL;
356 
357  /* a whole lot more NODATA */
358  rt_band_set_pixel(band, 4, 0, 0, NULL);
359  rt_band_set_pixel(band, 3, 1, 0, NULL);
360  rt_band_set_pixel(band, 1, 3, 0, NULL);
361  rt_band_set_pixel(band, 0, 4, 0, NULL);
362 
363  err = rt_raster_surface(rast, 0, &mpoly);
364  CU_ASSERT_EQUAL(err, ES_NONE);
365  CU_ASSERT(mpoly != NULL);
366  gobserved = (LWGEOM *)lwmpoly_as_lwgeom(mpoly);
367  gexpected = lwgeom_from_wkt(
368  "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)))",
370  CU_ASSERT_DOUBLE_EQUAL(lwgeom_area(gobserved), lwgeom_area(gexpected), FLT_EPSILON);
371  lwmpoly_free(mpoly);
372  mpoly = NULL;
373 
375 }
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:2005
void lwmpoly_free(LWMPOLY *mpoly)
Definition: lwmpoly.c:53
LWGEOM * lwmpoly_as_lwgeom(const LWMPOLY *obj)
Definition: lwgeom.c:285
double lwgeom_area(const LWGEOM *geom)
Definition: lwgeom.c:1872
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:904
void rt_raster_set_scale(rt_raster raster, double scaleX, double scaleY)
Set scale in projection units.
Definition: rt_raster.c:137
@ PT_32BUI
Definition: librtcore.h:194
rt_errorstate rt_raster_surface(rt_raster raster, int nband, LWMPOLY **surface)
Get a raster as a surface (multipolygon).
Definition: rt_geometry.c:355
rt_raster rt_raster_new(uint32_t width, uint32_t height)
Construct a raster with given dimensions.
Definition: rt_raster.c:48
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:974
@ ES_NONE
Definition: librtcore.h:180
void rt_raster_set_offsets(rt_raster raster, double x, double y)
Set insertion points in projection units.
Definition: rt_raster.c:199
band
Definition: ovdump.py:57
rt_band cu_add_band(rt_raster raster, rt_pixtype pixtype, int hasnodata, double nodataval)
void cu_free_raster(rt_raster raster)

References ovdump::band, cu_add_band(), cu_free_raster(), ES_NONE, LW_PARSER_CHECK_NONE, lwgeom_area(), lwgeom_from_wkt(), 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(), pixval::x, and pixval::y.

Referenced by raster_geometry_suite_setup().

Here is the call graph for this function:
Here is the caller graph for this function: