25#include "../../postgis_config.h"
92 if(arg->
src.
ds != NULL)
93 GDALClose(arg->
src.
ds);
96 GDALDeregisterDriver(arg->
src.
drv);
97 GDALDestroyDriver(arg->
src.
drv);
100 if (arg->
dst.
ds != NULL)
101 OGR_DS_Destroy(arg->
dst.
ds);
125 double contour_interval,
127 int fixed_level_count,
128 double *fixed_levels,
137 GDALRasterBandH hBand;
138 int nfeatures = 0, i = 0;
143 char **papszOptList = NULL;
144 const char* elev_field = polygonize ?
"ELEV_FIELD_MIN" :
"ELEV_FIELD";
152 hBand = GDALGetRasterBand(arg.
src.
ds, src_band);
156 arg.
dst.
drv = OGRGetDriverByName(
"Memory");
160 arg.
dst.
ds = OGR_Dr_CreateDataSource(arg.
dst.
drv,
"contour_ds", NULL);
165#if POSTGIS_GDAL_VERSION >= 20400
166 arg.
dst.
gtype = polygonize ? wkbPolygon : wkbLineString;
177 OGRFieldDefnH hFldId = OGR_Fld_Create(
"id", OFTInteger);
178 ogrerr = OGR_L_CreateField(arg.
dst.
lyr, hFldId,
TRUE);
179 if (ogrerr != OGRERR_NONE)
183 OGRFieldDefnH hFldElevation = OGR_Fld_Create(
"elevation", OFTReal);
184 ogrerr = OGR_L_CreateField(arg.
dst.
lyr, hFldElevation,
TRUE);
185 if (ogrerr != OGRERR_NONE)
189 double no_data_value = GDALGetRasterNoDataValue(hBand, &use_no_data);
217 if (fixed_level_count > 0) {
220 for (i = 0; i < fixed_level_count; i++) {
241 cplerr = GDALContourGenerateEx(
246 (
void*)
"GDALContourGenerateEx"
260 if (cplerr >= CE_Failure) {
265 nfeatures = OGR_L_GetFeatureCount(arg.
dst.
lyr,
TRUE);
270 OGR_L_ResetReading(arg.
dst.
lyr);
271 while ((hFeat = OGR_L_GetNextFeature(arg.
dst.
lyr))) {
273 unsigned char *bufWkb;
279 if(i >= nfeatures)
break;
282 contour.
id = OGR_F_GetFieldAsInteger(hFeat, 0);
283 contour.
elevation = OGR_F_GetFieldAsDouble(hFeat, 1);
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;
290 OGR_F_Destroy(hFeat);
297 (*contours)[i++] = contour;
GSERIALIZED * gserialized_from_lwgeom(LWGEOM *geom, size_t *size)
Allocate a new GSERIALIZED from an LWGEOM.
void lwgeom_cancel_interrupt(void)
Cancel any interruption request.
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 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.
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.
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