PostGIS  2.3.8dev-r@@SVN_REVISION@@

◆ test_raster_perimeter()

static void test_raster_perimeter ( )
static

Definition at line 371 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().

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