PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ test_raster_perimeter()

static void test_raster_perimeter ( )
static

Definition at line 377 of file cu_raster_geometry.c.

377  {
378  rt_raster rast;
379  rt_band band;
380  const int maxX = 5;
381  const int maxY = 5;
382  int x, y;
383  char *wkt = NULL;
384  LWGEOM *geom = NULL;
385  int err;
386 
387  rast = rt_raster_new(maxX, maxY);
388  CU_ASSERT(rast != NULL);
389 
391  rt_raster_set_scale(rast, 1, -1);
392 
393  band = cu_add_band(rast, PT_32BUI, 1, 0);
394  CU_ASSERT(band != NULL);
395 
396  for (y = 0; y < maxY; y++) {
397  for (x = 0; x < maxX; x++) {
398  rt_band_set_pixel(band, x, y, 1, NULL);
399  }
400  }
401 
402  err = rt_raster_get_perimeter(rast, -1, &geom);
403  CU_ASSERT_EQUAL(err, ES_NONE);
404  CU_ASSERT(geom != NULL);
405  wkt = lwgeom_to_text(geom);
406  CU_ASSERT_STRING_EQUAL(wkt, "POLYGON((0 0,5 0,5 -5,0 -5,0 0))");
407  rtdealloc(wkt);
408  lwgeom_free(geom);
409  geom = NULL;
410 
411  /* row 0 is NODATA */
412  rt_band_set_pixel(band, 0, 0, 0, NULL);
413  rt_band_set_pixel(band, 1, 0, 0, NULL);
414  rt_band_set_pixel(band, 2, 0, 0, NULL);
415  rt_band_set_pixel(band, 3, 0, 0, NULL);
416  rt_band_set_pixel(band, 4, 0, 0, NULL);
417 
418  err = rt_raster_get_perimeter(rast, 0, &geom);
419  CU_ASSERT_EQUAL(err, ES_NONE);
420  CU_ASSERT(geom != NULL);
421  wkt = lwgeom_to_text(geom);
422  CU_ASSERT_STRING_EQUAL(wkt, "POLYGON((0 -1,5 -1,5 -5,0 -5,0 -1))");
423  rtdealloc(wkt);
424  lwgeom_free(geom);
425  geom = NULL;
426 
427  /* column 4 is NODATA */
428  /* pixel 4, 0 already set to NODATA */
429  rt_band_set_pixel(band, 4, 1, 0, NULL);
430  rt_band_set_pixel(band, 4, 2, 0, NULL);
431  rt_band_set_pixel(band, 4, 3, 0, NULL);
432  rt_band_set_pixel(band, 4, 4, 0, NULL);
433 
434  err = rt_raster_get_perimeter(rast, 0, &geom);
435  CU_ASSERT_EQUAL(err, ES_NONE);
436  CU_ASSERT(geom != NULL);
437  wkt = lwgeom_to_text(geom);
438  CU_ASSERT_STRING_EQUAL(wkt, "POLYGON((0 -1,4 -1,4 -5,0 -5,0 -1))");
439  rtdealloc(wkt);
440  lwgeom_free(geom);
441  geom = NULL;
442 
443  /* row 4 is NODATA */
444  rt_band_set_pixel(band, 0, 4, 0, NULL);
445  rt_band_set_pixel(band, 1, 4, 0, NULL);
446  rt_band_set_pixel(band, 2, 4, 0, NULL);
447  rt_band_set_pixel(band, 3, 4, 0, NULL);
448  /* pixel 4, 4 already set to NODATA */
449 
450  err = rt_raster_get_perimeter(rast, 0, &geom);
451  CU_ASSERT_EQUAL(err, ES_NONE);
452  CU_ASSERT(geom != NULL);
453  wkt = lwgeom_to_text(geom);
454  CU_ASSERT_STRING_EQUAL(wkt, "POLYGON((0 -1,4 -1,4 -4,0 -4,0 -1))");
455  rtdealloc(wkt);
456  lwgeom_free(geom);
457  geom = NULL;
458 
459  /* column 0 is NODATA */
460  /* pixel 0, 0 already set to NODATA*/
461  rt_band_set_pixel(band, 0, 1, 0, NULL);
462  rt_band_set_pixel(band, 0, 2, 0, NULL);
463  rt_band_set_pixel(band, 0, 3, 0, NULL);
464  /* pixel 0, 4 already set to NODATA*/
465 
466  err = rt_raster_get_perimeter(rast, 0, &geom);
467  CU_ASSERT_EQUAL(err, ES_NONE);
468  CU_ASSERT(geom != NULL);
469  wkt = lwgeom_to_text(geom);
470  CU_ASSERT_STRING_EQUAL(wkt, "POLYGON((1 -1,4 -1,4 -4,1 -4,1 -1))");
471  rtdealloc(wkt);
472  lwgeom_free(geom);
473  geom = NULL;
474 
475  /* columns 1 and 3 are NODATA */
476  /* pixel 1, 0 already set to NODATA */
477  rt_band_set_pixel(band, 1, 1, 0, NULL);
478  rt_band_set_pixel(band, 1, 2, 0, NULL);
479  rt_band_set_pixel(band, 1, 3, 0, NULL);
480  /* pixel 1, 4 already set to NODATA */
481  /* pixel 3, 0 already set to NODATA */
482  rt_band_set_pixel(band, 3, 1, 0, NULL);
483  rt_band_set_pixel(band, 3, 2, 0, NULL);
484  rt_band_set_pixel(band, 3, 3, 0, NULL);
485  /* pixel 3, 4 already set to NODATA */
486 
487  err = rt_raster_get_perimeter(rast, 0, &geom);
488  CU_ASSERT_EQUAL(err, ES_NONE);
489  CU_ASSERT(geom != NULL);
490  wkt = lwgeom_to_text(geom);
491  CU_ASSERT_STRING_EQUAL(wkt, "POLYGON((2 -1,3 -1,3 -4,2 -4,2 -1))");
492  rtdealloc(wkt);
493  lwgeom_free(geom);
494  geom = NULL;
495 
496  /* more pixels are NODATA */
497  rt_band_set_pixel(band, 2, 1, 0, NULL);
498  rt_band_set_pixel(band, 2, 3, 0, NULL);
499 
500  err = rt_raster_get_perimeter(rast, 0, &geom);
501  CU_ASSERT_EQUAL(err, ES_NONE);
502  CU_ASSERT(geom != NULL);
503  wkt = lwgeom_to_text(geom);
504  CU_ASSERT_STRING_EQUAL(wkt, "POLYGON((2 -2,3 -2,3 -3,2 -3,2 -2))");
505  rtdealloc(wkt);
506  lwgeom_free(geom);
507  geom = NULL;
508 
509  /* second band */
510  band = cu_add_band(rast, PT_32BUI, 1, 0);
511  CU_ASSERT(band != NULL);
512 
513  for (y = 0; y < maxY; y++) {
514  for (x = 0; x < maxX; x++) {
515  rt_band_set_pixel(band, x, y, 1, NULL);
516  }
517  }
518 
519  err = rt_raster_get_perimeter(rast, -1, &geom);
520  CU_ASSERT_EQUAL(err, ES_NONE);
521  CU_ASSERT(geom != NULL);
522  wkt = lwgeom_to_text(geom);
523  CU_ASSERT_STRING_EQUAL(wkt, "POLYGON((0 0,5 0,5 -5,0 -5,0 0))");
524  rtdealloc(wkt);
525  lwgeom_free(geom);
526  geom = NULL;
527 
529 }
static char * lwgeom_to_text(const LWGEOM *lwgeom)
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1144
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_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 rtdealloc(void *mem)
Definition: rt_context.c:186
rt_errorstate rt_raster_get_perimeter(rt_raster raster, int nband, LWGEOM **perimeter)
Get raster perimeter.
Definition: rt_geometry.c:182
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, lwgeom_free(), lwgeom_to_text(), PT_32BUI, rtpixdump::rast, rt_band_set_pixel(), rt_raster_get_perimeter(), rt_raster_new(), rt_raster_set_offsets(), rt_raster_set_scale(), rtdealloc(), 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: