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;
139 const char* elev_field = polygonize ?
"ELEV_FIELD_MIN" :
"ELEV_FIELD";
151 arg.
dst.
drv = OGRGetDriverByName(
"Memory");
155 arg.
dst.
ds = OGR_Dr_CreateDataSource(arg.
dst.
drv,
"contour_ds", NULL);
160 #if POSTGIS_GDAL_VERSION >= 20400
161 arg.
dst.
gtype = polygonize ? wkbPolygon : wkbLineString;
172 OGRFieldDefnH hFldId = OGR_Fld_Create(
"id", OFTInteger);
173 ogrerr = OGR_L_CreateField(arg.
dst.
lyr, hFldId,
TRUE);
174 if (ogrerr != OGRERR_NONE)
178 OGRFieldDefnH hFldElevation = OGR_Fld_Create(
"elevation", OFTReal);
179 ogrerr = OGR_L_CreateField(arg.
dst.
lyr, hFldElevation,
TRUE);
180 if (ogrerr != OGRERR_NONE)
184 double no_data_value = GDALGetRasterNoDataValue(hBand, &use_no_data);
212 if (fixed_level_count > 0) {
215 for (i = 0; i < fixed_level_count; i++) {
236 cplerr = GDALContourGenerateEx(
241 (
void*)
"GDALContourGenerateEx"
255 if (cplerr >= CE_Failure) {
260 nfeatures = OGR_L_GetFeatureCount(arg.
dst.
lyr,
TRUE);
265 OGR_L_ResetReading(arg.
dst.
lyr);
266 while ((hFeat = OGR_L_GetNextFeature(arg.
dst.
lyr))) {
268 unsigned char *bufWkb;
274 if(i >= nfeatures)
break;
277 contour.
id = OGR_F_GetFieldAsInteger(hFeat, 0);
278 contour.
elevation = OGR_F_GetFieldAsDouble(hFeat, 1);
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;
285 OGR_F_Destroy(hFeat);
292 (*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 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)
static 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 src
struct _rti_contour_arg::@15 dst