Return palloc'ed list of contours.
129{
130 CPLErr cplerr;
131 OGRErr ogrerr;
132 GDALRasterBandH hBand;
133 int nfeatures = 0, i = 0;
134 OGRFeatureH hFeat;
135
136
138 char **papszOptList = NULL;
139 const char* elev_field = polygonize ? "ELEV_FIELD_MIN" : "ELEV_FIELD";
140
143
144
146
147 hBand = GDALGetRasterBand(arg.
src.
ds, src_band);
148
149
151 arg.
dst.
drv = OGRGetDriverByName(
"Memory");
154
155 arg.
dst.
ds = OGR_Dr_CreateDataSource(arg.
dst.
drv,
"contour_ds", NULL);
158
159
160#if POSTGIS_GDAL_VERSION >= 20400
161 arg.
dst.
gtype = polygonize ? wkbPolygon : wkbLineString;
162#else
164#endif
165
166
170
171
172 OGRFieldDefnH hFldId = OGR_Fld_Create("id", OFTInteger);
173 ogrerr = OGR_L_CreateField(arg.
dst.
lyr, hFldId,
TRUE);
174 if (ogrerr != OGRERR_NONE)
176
177
178 OGRFieldDefnH hFldElevation = OGR_Fld_Create("elevation", OFTReal);
179 ogrerr = OGR_L_CreateField(arg.
dst.
lyr, hFldElevation,
TRUE);
180 if (ogrerr != OGRERR_NONE)
182
183 int use_no_data = 0;
184 double no_data_value = GDALGetRasterNoDataValue(hBand, &use_no_data);
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
208
209 if (use_no_data)
211
212 if (fixed_level_count > 0) {
213 int i = 0;
215 for (i = 0; i < fixed_level_count; i++) {
218 }
220 }
221 else {
224 }
225
228
230
232
233
234
235
236 cplerr = GDALContourGenerateEx(
237 hBand,
239 papszOptList,
241 (void*)"GDALContourGenerateEx"
242 );
243
244
245
246
247
248
249
250
251
252
253
254
255 if (cplerr >= CE_Failure) {
257 }
258
259
260 nfeatures = OGR_L_GetFeatureCount(arg.
dst.
lyr,
TRUE);
261 if (nfeatures < 0)
263
265 OGR_L_ResetReading(arg.
dst.
lyr);
266 while ((hFeat = OGR_L_GetNextFeature(arg.
dst.
lyr))) {
267 size_t szWkb;
268 unsigned char *bufWkb;
270 OGRGeometryH hGeom;
272
273
274 if(i >= nfeatures) break;
275
276
277 contour.id = OGR_F_GetFieldAsInteger(hFeat, 0);
278 contour.elevation = OGR_F_GetFieldAsDouble(hFeat, 1);
279
280 if (!(hGeom = OGR_F_GetGeometryRef(hFeat))) continue;
281 szWkb = OGR_G_WkbSize(hGeom);
283 if (OGR_G_ExportToWkb(hGeom, wkbNDR, bufWkb) != OGRERR_NONE) continue;
284
285 OGR_F_Destroy(hFeat);
292 (*contours)[i++] = contour;
293 }
294
295
296 *ncontours = i;
297
298
301
302
304}
GSERIALIZED * gserialized_from_lwgeom(LWGEOM *geom, size_t *size)
Allocate a new GSERIALIZED from an LWGEOM.
void lwgeom_set_srid(LWGEOM *geom, int32_t srid)
Set the SRID on an LWGEOM For collections, only the parent gets an SRID, all the children get SRID_UN...
void lwgeom_free(LWGEOM *geom)
#define LW_PARSER_CHECK_NONE
LWGEOM * lwgeom_from_wkb(const uint8_t *wkb, const size_t wkb_size, const char check)
WKB inputs must have a declared size, to prevent malformed WKB from reading off the end of the memory...
void rterror(const char *fmt,...) __attribute__((format(printf
Wrappers used for reporting errors and info.
void * rtalloc(size_t size)
Wrappers used for managing memory.
void rtdealloc(void *mem)
GDALDatasetH rt_raster_to_gdal_mem(rt_raster raster, const char *srs, uint32_t *bandNums, int *excludeNodataValues, int count, GDALDriverH *rtn_drv, int *destroy_rtn_drv)
Return GDAL dataset using GDAL MEM driver from raster.
static int _rti_contour_arg_destroy(_rti_contour_arg *arg)
static int rt_util_gdal_progress_func(double dfComplete, const char *pszMessage, void *pProgressArg)
static void _rti_contour_arg_init(_rti_contour_arg *arg)
void stringbuffer_release(stringbuffer_t *s)
int stringbuffer_aprintf(stringbuffer_t *s, const char *fmt,...)
Appends a formatted string to the current string buffer, using the format and argument list provided.
const char * stringbuffer_getstring(stringbuffer_t *s)
Returns a reference to the internal string being managed by the stringbuffer.
void stringbuffer_init(stringbuffer_t *s)
static void stringbuffer_append(stringbuffer_t *s, const char *a)
Append the specified string to the stringbuffer_t.
static void stringbuffer_append_char(stringbuffer_t *s, char c)
struct _rti_contour_arg::@14 src
struct _rti_contour_arg::@15 dst