PostGIS  2.1.10dev-r@@SVN_REVISION@@
static void test_raster_perimeter ( )
static

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

236  {
237  rt_raster rast;
238  rt_band band;
239  const int maxX = 5;
240  const int maxY = 5;
241  int x, y;
242  char *wkt = NULL;
243  LWGEOM *geom = NULL;
244  int err;
245 
246  rast = rt_raster_new(maxX, maxY);
247  CU_ASSERT(rast != NULL);
248 
249  rt_raster_set_offsets(rast, 0, 0);
250  rt_raster_set_scale(rast, 1, -1);
251 
252  band = cu_add_band(rast, PT_32BUI, 1, 0);
253  CU_ASSERT(band != NULL);
254 
255  for (y = 0; y < maxY; y++) {
256  for (x = 0; x < maxX; x++) {
257  rt_band_set_pixel(band, x, y, 1, NULL);
258  }
259  }
260 
261  err = rt_raster_get_perimeter(rast, -1, &geom);
262  CU_ASSERT_EQUAL(err, ES_NONE);
263  CU_ASSERT(geom != NULL);
264  wkt = lwgeom_to_text(geom);
265  CU_ASSERT_STRING_EQUAL(wkt, "POLYGON((0 0,5 0,5 -5,0 -5,0 0))");
266  rtdealloc(wkt);
267  lwgeom_free(geom);
268  geom = NULL;
269 
270  /* row 0 is NODATA */
271  rt_band_set_pixel(band, 0, 0, 0, NULL);
272  rt_band_set_pixel(band, 1, 0, 0, NULL);
273  rt_band_set_pixel(band, 2, 0, 0, NULL);
274  rt_band_set_pixel(band, 3, 0, 0, NULL);
275  rt_band_set_pixel(band, 4, 0, 0, NULL);
276 
277  err = rt_raster_get_perimeter(rast, 0, &geom);
278  CU_ASSERT_EQUAL(err, ES_NONE);
279  CU_ASSERT(geom != NULL);
280  wkt = lwgeom_to_text(geom);
281  CU_ASSERT_STRING_EQUAL(wkt, "POLYGON((0 -1,5 -1,5 -5,0 -5,0 -1))");
282  rtdealloc(wkt);
283  lwgeom_free(geom);
284  geom = NULL;
285 
286  /* column 4 is NODATA */
287  /* pixel 4, 0 already set to NODATA */
288  rt_band_set_pixel(band, 4, 1, 0, NULL);
289  rt_band_set_pixel(band, 4, 2, 0, NULL);
290  rt_band_set_pixel(band, 4, 3, 0, NULL);
291  rt_band_set_pixel(band, 4, 4, 0, NULL);
292 
293  err = rt_raster_get_perimeter(rast, 0, &geom);
294  CU_ASSERT_EQUAL(err, ES_NONE);
295  CU_ASSERT(geom != NULL);
296  wkt = lwgeom_to_text(geom);
297  CU_ASSERT_STRING_EQUAL(wkt, "POLYGON((0 -1,4 -1,4 -5,0 -5,0 -1))");
298  rtdealloc(wkt);
299  lwgeom_free(geom);
300  geom = NULL;
301 
302  /* row 4 is NODATA */
303  rt_band_set_pixel(band, 0, 4, 0, NULL);
304  rt_band_set_pixel(band, 1, 4, 0, NULL);
305  rt_band_set_pixel(band, 2, 4, 0, NULL);
306  rt_band_set_pixel(band, 3, 4, 0, NULL);
307  /* pixel 4, 4 already set to NODATA */
308 
309  err = rt_raster_get_perimeter(rast, 0, &geom);
310  CU_ASSERT_EQUAL(err, ES_NONE);
311  CU_ASSERT(geom != NULL);
312  wkt = lwgeom_to_text(geom);
313  CU_ASSERT_STRING_EQUAL(wkt, "POLYGON((0 -1,4 -1,4 -4,0 -4,0 -1))");
314  rtdealloc(wkt);
315  lwgeom_free(geom);
316  geom = NULL;
317 
318  /* column 0 is NODATA */
319  /* pixel 0, 0 already set to NODATA*/
320  rt_band_set_pixel(band, 0, 1, 0, NULL);
321  rt_band_set_pixel(band, 0, 2, 0, NULL);
322  rt_band_set_pixel(band, 0, 3, 0, NULL);
323  /* pixel 0, 4 already set to NODATA*/
324 
325  err = rt_raster_get_perimeter(rast, 0, &geom);
326  CU_ASSERT_EQUAL(err, ES_NONE);
327  CU_ASSERT(geom != NULL);
328  wkt = lwgeom_to_text(geom);
329  CU_ASSERT_STRING_EQUAL(wkt, "POLYGON((1 -1,4 -1,4 -4,1 -4,1 -1))");
330  rtdealloc(wkt);
331  lwgeom_free(geom);
332  geom = NULL;
333 
334  /* columns 1 and 3 are NODATA */
335  /* pixel 1, 0 already set to NODATA */
336  rt_band_set_pixel(band, 1, 1, 0, NULL);
337  rt_band_set_pixel(band, 1, 2, 0, NULL);
338  rt_band_set_pixel(band, 1, 3, 0, NULL);
339  /* pixel 1, 4 already set to NODATA */
340  /* pixel 3, 0 already set to NODATA */
341  rt_band_set_pixel(band, 3, 1, 0, NULL);
342  rt_band_set_pixel(band, 3, 2, 0, NULL);
343  rt_band_set_pixel(band, 3, 3, 0, NULL);
344  /* pixel 3, 4 already set to NODATA */
345 
346  err = rt_raster_get_perimeter(rast, 0, &geom);
347  CU_ASSERT_EQUAL(err, ES_NONE);
348  CU_ASSERT(geom != NULL);
349  wkt = lwgeom_to_text(geom);
350  CU_ASSERT_STRING_EQUAL(wkt, "POLYGON((2 -1,3 -1,3 -4,2 -4,2 -1))");
351  rtdealloc(wkt);
352  lwgeom_free(geom);
353  geom = NULL;
354 
355  /* more pixels are NODATA */
356  rt_band_set_pixel(band, 2, 1, 0, NULL);
357  rt_band_set_pixel(band, 2, 3, 0, NULL);
358 
359  err = rt_raster_get_perimeter(rast, 0, &geom);
360  CU_ASSERT_EQUAL(err, ES_NONE);
361  CU_ASSERT(geom != NULL);
362  wkt = lwgeom_to_text(geom);
363  CU_ASSERT_STRING_EQUAL(wkt, "POLYGON((2 -2,3 -2,3 -3,2 -3,2 -2))");
364  rtdealloc(wkt);
365  lwgeom_free(geom);
366  geom = NULL;
367 
368  /* second band */
369  band = cu_add_band(rast, PT_32BUI, 1, 0);
370  CU_ASSERT(band != NULL);
371 
372  for (y = 0; y < maxY; y++) {
373  for (x = 0; x < maxX; x++) {
374  rt_band_set_pixel(band, x, y, 1, NULL);
375  }
376  }
377 
378  err = rt_raster_get_perimeter(rast, -1, &geom);
379  CU_ASSERT_EQUAL(err, ES_NONE);
380  CU_ASSERT(geom != NULL);
381  wkt = lwgeom_to_text(geom);
382  CU_ASSERT_STRING_EQUAL(wkt, "POLYGON((0 0,5 0,5 -5,0 -5,0 0))");
383  rtdealloc(wkt);
384  lwgeom_free(geom);
385  geom = NULL;
386 
387  cu_free_raster(rast);
388 }
void rtdealloc(void *mem)
Definition: rt_api.c:882
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1006
tuple band
Definition: ovdump.py:57
tuple rast
Definition: rtpixdump.py:62
rt_errorstate rt_raster_get_perimeter(rt_raster raster, int nband, LWGEOM **perimeter)
Get raster perimeter.
Definition: rt_api.c:14683
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_api.c:5442
tuple x
Definition: pixval.py:53
rt_raster rt_raster_new(uint32_t width, uint32_t height)
Construct a raster with given dimensions.
Definition: rt_api.c:5353
static char * lwgeom_to_text(const LWGEOM *lwgeom)
void rt_raster_set_offsets(rt_raster raster, double x, double y)
Set insertion points in projection units.
Definition: rt_api.c:5504
tuple y
Definition: pixval.py:54
rt_errorstate rt_band_set_pixel(rt_band band, int x, int y, double val, int *converted)
Set single pixel's value.
Definition: rt_api.c:2302

Here is the call graph for this function:

Here is the caller graph for this function: