24 #include "../../postgis_config.h"
60 const char *pszMessage,
87 if(arg->
src.
ds != NULL)
88 GDALClose(arg->
src.
ds);
91 GDALDeregisterDriver(arg->
src.
drv);
92 GDALDestroyDriver(arg->
src.
drv);
95 if (arg->
dst.
ds != NULL)
96 OGR_DS_Destroy(arg->
dst.
ds);
120 double contour_interval,
122 int fixed_level_count,
123 double *fixed_levels,
132 GDALRasterBandH hBand;
133 int nfeatures = 0, i = 0;
138 char **papszOptList = NULL;
150 arg.
dst.
drv = OGRGetDriverByName(
"Memory");
154 arg.
dst.
ds = OGR_Dr_CreateDataSource(arg.
dst.
drv,
"contour_ds", NULL);
159 #if POSTGIS_GDAL_VERSION >= 24
160 arg.
dst.
gtype = polygonize ? wkbPolygon : wkbLineString;
171 OGRFieldDefnH hFldId = OGR_Fld_Create(
"id", OFTInteger);
172 ogrerr = OGR_L_CreateField(arg.
dst.
lyr, hFldId,
TRUE);
173 if (ogrerr != OGRERR_NONE)
177 OGRFieldDefnH hFldElevation = OGR_Fld_Create(
"elevation", OFTReal);
178 ogrerr = OGR_L_CreateField(arg.
dst.
lyr, hFldElevation,
TRUE);
179 if (ogrerr != OGRERR_NONE)
183 double no_data_value = GDALGetRasterNoDataValue(hBand, &use_no_data);
211 if (fixed_level_count > 0) {
214 for (i = 0; i < fixed_level_count; i++) {
234 cplerr = GDALContourGenerateEx(
239 (
void*)
"GDALContourGenerateEx"
253 if (cplerr >= CE_Failure) {
258 nfeatures = OGR_L_GetFeatureCount(arg.
dst.
lyr,
TRUE);
263 OGR_L_ResetReading(arg.
dst.
lyr);
264 while ((hFeat = OGR_L_GetNextFeature(arg.
dst.
lyr))) {
266 unsigned char *bufWkb;
272 if(i >= nfeatures)
break;
275 contour.
id = OGR_F_GetFieldAsInteger(hFeat, 0);
276 contour.
elevation = OGR_F_GetFieldAsDouble(hFeat, 1);
278 if (!(hGeom = OGR_F_GetGeometryRef(hFeat)))
continue;
279 szWkb = OGR_G_WkbSize(hGeom);
281 if (OGR_G_ExportToWkb(hGeom, wkbNDR, bufWkb) != OGRERR_NONE)
continue;
283 OGR_F_Destroy(hFeat);
289 (*contours)[i++] = contour;
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...
int _lwgeom_interrupt_requested
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.
This library is the generic raster handling section of PostGIS.
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)
int rt_raster_gdal_contour(rt_raster src_raster, int src_band, int src_srid, const char *src_srs, double contour_interval, double contour_base, int fixed_level_count, double *fixed_levels, int polygonize, size_t *ncontours, struct rt_contour_t **contours)
Return palloc'ed list of contours.
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.
void stringbuffer_init(stringbuffer_t *s)
const char * stringbuffer_getstring(stringbuffer_t *s)
Returns a reference to the internal string being managed by the stringbuffer.
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 dst
struct _rti_contour_arg::@13 src