Return palloc'ed list of contours.
134{
135 CPLErr cplerr;
136 OGRErr ogrerr;
137 GDALRasterBandH hBand;
138 int nfeatures = 0, i = 0;
139 OGRFeatureH hFeat;
140
141
143 char **papszOptList = NULL;
144 const char* elev_field = polygonize ? "ELEV_FIELD_MIN" : "ELEV_FIELD";
145
148
149
151
152 hBand = GDALGetRasterBand(arg.
src.
ds, src_band);
153
154
156 arg.
dst.
drv = OGRGetDriverByName(
"Memory");
159
160 arg.
dst.
ds = OGR_Dr_CreateDataSource(arg.
dst.
drv,
"contour_ds", NULL);
163
164
165#if POSTGIS_GDAL_VERSION >= 20400
166 arg.
dst.
gtype = polygonize ? wkbPolygon : wkbLineString;
167#else
169#endif
170
171
175
176
177 OGRFieldDefnH hFldId = OGR_Fld_Create("id", OFTInteger);
178 ogrerr = OGR_L_CreateField(arg.
dst.
lyr, hFldId,
TRUE);
179 if (ogrerr != OGRERR_NONE)
181
182
183 OGRFieldDefnH hFldElevation = OGR_Fld_Create("elevation", OFTReal);
184 ogrerr = OGR_L_CreateField(arg.
dst.
lyr, hFldElevation,
TRUE);
185 if (ogrerr != OGRERR_NONE)
187
188 int use_no_data = 0;
189 double no_data_value = GDALGetRasterNoDataValue(hBand, &use_no_data);
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
213
214 if (use_no_data)
216
217 if (fixed_level_count > 0) {
218 int i = 0;
220 for (i = 0; i < fixed_level_count; i++) {
223 }
225 }
226 else {
229 }
230
233
235
237
238
239
240
241 cplerr = GDALContourGenerateEx(
242 hBand,
244 papszOptList,
246 (void*)"GDALContourGenerateEx"
247 );
248
249
250
251
252
253
254
255
256
257
258
259
260 if (cplerr >= CE_Failure) {
262 }
263
264
265 nfeatures = OGR_L_GetFeatureCount(arg.
dst.
lyr,
TRUE);
266 if (nfeatures < 0)
268
270 OGR_L_ResetReading(arg.
dst.
lyr);
271 while ((hFeat = OGR_L_GetNextFeature(arg.
dst.
lyr))) {
272 size_t szWkb;
273 unsigned char *bufWkb;
275 OGRGeometryH hGeom;
277
278
279 if(i >= nfeatures) break;
280
281
282 contour.id = OGR_F_GetFieldAsInteger(hFeat, 0);
283 contour.elevation = OGR_F_GetFieldAsDouble(hFeat, 1);
284
285 if (!(hGeom = OGR_F_GetGeometryRef(hFeat))) continue;
286 szWkb = OGR_G_WkbSize(hGeom);
288 if (OGR_G_ExportToWkb(hGeom, wkbNDR, bufWkb) != OGRERR_NONE) continue;
289
290 OGR_F_Destroy(hFeat);
297 (*contours)[i++] = contour;
298 }
299
300
301 *ncontours = i;
302
303
306
307
309}
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)
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