PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ test_raster_perimeter()

static void test_raster_perimeter ( )
static

Definition at line 375 of file cu_raster_geometry.c.

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().

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