PostGIS 3.6.2dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ test_gdal_polygonize()

static void test_gdal_polygonize ( )
static

Definition at line 154 of file cu_gdal.c.

154 {
155 int i;
157 int nPols = 0;
158 double total_area = 0;
159 double total_val = 0;
160 rt_geomval gv = NULL;
161 LWGEOM *gobserved;
162 //char *wkt = NULL;
163
164 rt = fillRasterToPolygonize(1, -1.0);
165 CU_ASSERT(rt_raster_has_band(rt, 0));
166
167 nPols = 0;
168 gv = rt_raster_gdal_polygonize(rt, 0, TRUE, &nPols);
169 CU_ASSERT_DOUBLE_EQUAL(nPols, 4, FLT_EPSILON);
170 total_area = 0; total_val = 0;
171 for (i = 0; i < nPols; i++) {
172 total_val += gv[i].val;
173 gobserved = (LWGEOM *) gv[i].geom;
174 total_area += lwgeom_area(gobserved);
175 lwgeom_free((LWGEOM *) gv[i].geom);
176 }
177 printf("total area, total val, nPols = %f, %f, %i\n", total_area, total_val, nPols);
178 CU_ASSERT_DOUBLE_EQUAL(total_val, 1.8 + 0.0 + 2.8 + 0, FLT_EPSILON);
179 CU_ASSERT_DOUBLE_EQUAL(total_area, 81, FLT_EPSILON);
180
181 rtdealloc(gv);
182 cu_free_raster(rt);
183
184 /* Second test: NODATA value = 1.8 */
185 rt = fillRasterToPolygonize(1, 1.8);
186
187 /* We can check rt_raster_has_band here too */
188 CU_ASSERT(rt_raster_has_band(rt, 0));
189
190 nPols = 0;
191 gv = rt_raster_gdal_polygonize(rt, 0, TRUE, &nPols);
192 CU_ASSERT_DOUBLE_EQUAL(nPols, 4, FLT_EPSILON);
193 total_area = 0; total_val = 0;
194 for (i = 0; i < nPols; i++) {
195 total_val += gv[i].val;
196 gobserved = (LWGEOM *) gv[i].geom;
197 total_area += lwgeom_area(gobserved);
198 lwgeom_free((LWGEOM *) gv[i].geom);
199 }
200 printf("total area, total_val, polys = %f, %f, %i\n", total_area, total_val, nPols);
201 CU_ASSERT_DOUBLE_EQUAL(total_val, 4.6, FLT_EPSILON);
202 CU_ASSERT_DOUBLE_EQUAL(total_area, 81, FLT_EPSILON);
203
204
205 rtdealloc(gv);
206 cu_free_raster(rt);
207
208 /* Third test: NODATA value = 2.8 */
209 rt = fillRasterToPolygonize(1, 2.8);
210
211 /* We can check rt_raster_has_band here too */
212 CU_ASSERT(rt_raster_has_band(rt, 0));
213
214 nPols = 0;
215 gv = rt_raster_gdal_polygonize(rt, 0, TRUE, &nPols);
216 CU_ASSERT_DOUBLE_EQUAL(nPols, 4, FLT_EPSILON);
217 total_area = 0; total_val = 0;
218 for (i = 0; i < nPols; i++) {
219 total_val += gv[i].val;
220 gobserved = (LWGEOM *) gv[i].geom;
221 total_area += lwgeom_area(gobserved);
222 lwgeom_free((LWGEOM *) gv[i].geom);
223 }
224
225 printf("total area, total_val, polys = %f, %f, %i\n", total_area, total_val, nPols);
226 CU_ASSERT_DOUBLE_EQUAL(total_val, 4.6, FLT_EPSILON);
227 CU_ASSERT_DOUBLE_EQUAL(total_area, 81, FLT_EPSILON);
228
229 rtdealloc(gv);
230 cu_free_raster(rt);
231
232 /* Fourth test: NODATA value = 0 */
233 rt = fillRasterToPolygonize(1, 0.0);
234 /* We can check rt_raster_has_band here too */
235 CU_ASSERT(rt_raster_has_band(rt, 0));
236
237 nPols = 0;
238 gv = rt_raster_gdal_polygonize(rt, 0, TRUE, &nPols);
239
240 CU_ASSERT_DOUBLE_EQUAL(nPols, 2, FLT_EPSILON);
241 total_area = 0; total_val = 0;
242 for (i = 0; i < nPols; i++) {
243 total_val += gv[i].val;
244 gobserved = (LWGEOM *) gv[i].geom;
245 total_area += lwgeom_area(gobserved);
246 lwgeom_free((LWGEOM *) gv[i].geom);
247 }
248
249 printf("total area, total_val, polys = %f, %f, %i\n", total_area, total_val, nPols);
250 CU_ASSERT_DOUBLE_EQUAL(total_val, 4.6, FLT_EPSILON);
251 CU_ASSERT_DOUBLE_EQUAL(total_area, 28, FLT_EPSILON);
252
253 rtdealloc(gv);
254 cu_free_raster(rt);
255
256 /* Last test: There is no NODATA value (all values are valid) */
257 rt = fillRasterToPolygonize(0, 0.0);
258 /* We can check rt_raster_has_band here too */
259 CU_ASSERT(rt_raster_has_band(rt, 0));
260
261 nPols = 0;
262 gv = rt_raster_gdal_polygonize(rt, 0, TRUE, &nPols);
263
264 CU_ASSERT_DOUBLE_EQUAL(nPols, 4, FLT_EPSILON);
265 total_area = 0; total_val = 0;
266 for (i = 0; i < nPols; i++) {
267 total_val += gv[i].val;
268 gobserved = (LWGEOM *) gv[i].geom;
269 total_area += lwgeom_area(gobserved);
270 lwgeom_free((LWGEOM *) gv[i].geom);
271 }
272
273 printf("total area, total_val, polys = %f, %f, %i\n", total_area, total_val, nPols);
274 CU_ASSERT_DOUBLE_EQUAL(total_val, 1.8 + 0.0 + 2.8 + 0.0, FLT_EPSILON);
275 CU_ASSERT_DOUBLE_EQUAL(total_area, 81, FLT_EPSILON);
276 rtdealloc(gv);
277 cu_free_raster(rt);
278}
static rt_raster fillRasterToPolygonize(int hasnodata, double nodataval)
Definition cu_gdal.c:101
#define TRUE
Definition dbfopen.c:73
void lwgeom_free(LWGEOM *geom)
Definition lwgeom.c:1218
double lwgeom_area(const LWGEOM *geom)
Definition lwgeom.c:1971
int rt_raster_has_band(rt_raster raster, int nband)
Return TRUE if the raster has a band of this number.
Definition rt_raster.c:1253
rt_geomval rt_raster_gdal_polygonize(rt_raster raster, int nband, int exclude_nodata_value, int *pnElements)
Returns a set of "geomval" value, one for each group of pixel sharing the same value for the provided...
void rtdealloc(void *mem)
Definition rt_context.c:206
void cu_free_raster(rt_raster raster)

References cu_free_raster(), fillRasterToPolygonize(), lwgeom_area(), lwgeom_free(), rt_raster_gdal_polygonize(), rt_raster_has_band(), rtdealloc(), TRUE, and rt_geomval_t::val.

Referenced by gdal_suite_setup().

Here is the call graph for this function:
Here is the caller graph for this function: