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

Definition at line 116 of file cu_raster_geometry.c.

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

Referenced by raster_geometry_suite_setup().

116  {
117  rt_raster rast;
118  rt_band band;
119  const int maxX = 5;
120  const int maxY = 5;
121  int x, y;
122  char *wkt = NULL;
123  LWMPOLY *mpoly = NULL;
124  int err;
125 
126  rast = rt_raster_new(maxX, maxY);
127  CU_ASSERT(rast != NULL);
128 
129  rt_raster_set_offsets(rast, 0, 0);
130  rt_raster_set_scale(rast, 1, -1);
131 
132  band = cu_add_band(rast, PT_32BUI, 1, 0);
133  CU_ASSERT(band != NULL);
134 
135  for (y = 0; y < maxY; y++) {
136  for (x = 0; x < maxX; x++) {
137  rt_band_set_pixel(band, x, y, 1, NULL);
138  }
139  }
140 
141  err = rt_raster_surface(rast, 0, &mpoly);
142  CU_ASSERT_EQUAL(err, ES_NONE);
143  CU_ASSERT(mpoly != NULL);
144  wkt = lwgeom_to_text(lwmpoly_as_lwgeom(mpoly));
145  CU_ASSERT_STRING_EQUAL(wkt, "MULTIPOLYGON(((0 0,0 -5,5 -5,5 0,0 0)))");
146  rtdealloc(wkt);
147  lwmpoly_free(mpoly);
148  mpoly = NULL;
149 
150  /* 0,0 NODATA */
151  rt_band_set_pixel(band, 0, 0, 0, NULL);
152 
153  err = rt_raster_surface(rast, 0, &mpoly);
154  CU_ASSERT_EQUAL(err, ES_NONE);
155  CU_ASSERT(mpoly != NULL);
156  wkt = lwgeom_to_text(lwmpoly_as_lwgeom(mpoly));
157  CU_ASSERT_STRING_EQUAL(wkt, "MULTIPOLYGON(((1 0,1 -1,0 -1,0 -5,4 -5,5 -5,5 0,1 0)))");
158  rtdealloc(wkt);
159  lwmpoly_free(mpoly);
160  mpoly = NULL;
161 
162  /* plus 1,1 NODATA */
163  rt_band_set_pixel(band, 1, 1, 0, NULL);
164 
165  err = rt_raster_surface(rast, 0, &mpoly);
166  CU_ASSERT_EQUAL(err, ES_NONE);
167  CU_ASSERT(mpoly != NULL);
168  wkt = lwgeom_to_text(lwmpoly_as_lwgeom(mpoly));
169  CU_ASSERT_STRING_EQUAL(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)))");
170  rtdealloc(wkt);
171  lwmpoly_free(mpoly);
172  mpoly = NULL;
173 
174  /* plus 2,2 NODATA */
175  rt_band_set_pixel(band, 2, 2, 0, NULL);
176 
177  err = rt_raster_surface(rast, 0, &mpoly);
178  CU_ASSERT_EQUAL(err, ES_NONE);
179  CU_ASSERT(mpoly != NULL);
180  wkt = lwgeom_to_text(lwmpoly_as_lwgeom(mpoly));
181 #if POSTGIS_GEOS_VERSION >= 33
182  CU_ASSERT_STRING_EQUAL(wkt, "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)))");
183 #else
184  CU_ASSERT_STRING_EQUAL(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 -3,3 -3,3 -2,2 -2,2 -1,1 -1)))");
185 #endif
186  rtdealloc(wkt);
187  lwmpoly_free(mpoly);
188  mpoly = NULL;
189 
190  /* plus 3,3 NODATA */
191  rt_band_set_pixel(band, 3, 3, 0, NULL);
192 
193  err = rt_raster_surface(rast, 0, &mpoly);
194  CU_ASSERT_EQUAL(err, ES_NONE);
195  CU_ASSERT(mpoly != NULL);
196  wkt = lwgeom_to_text(lwmpoly_as_lwgeom(mpoly));
197 #if POSTGIS_GEOS_VERSION >= 33
198  CU_ASSERT_STRING_EQUAL(wkt, "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)))");
199 #else
200  CU_ASSERT_STRING_EQUAL(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 -3,3 -3,3 -4,4 -4,4 -3,3 -3,3 -2,2 -2,2 -1,1 -1)))");
201 #endif
202  rtdealloc(wkt);
203  lwmpoly_free(mpoly);
204  mpoly = NULL;
205 
206  /* plus 4,4 NODATA */
207  rt_band_set_pixel(band, 4, 4, 0, NULL);
208 
209  err = rt_raster_surface(rast, 0, &mpoly);
210  CU_ASSERT_EQUAL(err, ES_NONE);
211  CU_ASSERT(mpoly != NULL);
212  wkt = lwgeom_to_text(lwmpoly_as_lwgeom(mpoly));
213  CU_ASSERT_STRING_EQUAL(wkt, "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)))");
214  rtdealloc(wkt);
215  lwmpoly_free(mpoly);
216  mpoly = NULL;
217 
218  /* a whole lot more NODATA */
219  rt_band_set_pixel(band, 4, 0, 0, NULL);
220  rt_band_set_pixel(band, 3, 1, 0, NULL);
221  rt_band_set_pixel(band, 1, 3, 0, NULL);
222  rt_band_set_pixel(band, 0, 4, 0, NULL);
223 
224  err = rt_raster_surface(rast, 0, &mpoly);
225  CU_ASSERT_EQUAL(err, ES_NONE);
226  CU_ASSERT(mpoly != NULL);
227  wkt = lwgeom_to_text(lwmpoly_as_lwgeom(mpoly));
228  CU_ASSERT_STRING_EQUAL(wkt, "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)))");
229  rtdealloc(wkt);
230  lwmpoly_free(mpoly);
231  mpoly = NULL;
232 
233  cu_free_raster(rast);
234 }
void rtdealloc(void *mem)
Definition: rt_api.c:882
tuple band
Definition: ovdump.py:57
tuple rast
Definition: rtpixdump.py:62
void cu_free_raster(rt_raster raster)
rt_band cu_add_band(rt_raster raster, rt_pixtype pixtype, int hasnodata, double nodataval)
void lwmpoly_free(LWMPOLY *mpoly)
Definition: lwmpoly.c:40
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_errorstate rt_raster_surface(rt_raster raster, int nband, LWMPOLY **surface)
Get a raster as a surface (multipolygon).
Definition: rt_api.c:13242
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)
LWGEOM * lwmpoly_as_lwgeom(const LWMPOLY *obj)
Definition: lwgeom.c:204
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: