24 #include "../../postgis_config.h"
64 if(arg->
src.
ds != NULL)
65 GDALClose(arg->
src.
ds);
68 GDALDeregisterDriver(arg->
src.
drv);
69 GDALDestroyDriver(arg->
src.
drv);
72 if (arg->
dst.
ds != NULL)
73 OGR_DS_Destroy(arg->
dst.
ds);
95 double contour_interval,
97 int fixed_level_count,
107 GDALRasterBandH hBand;
108 int nfeatures = 0, i = 0;
121 arg.
dst.
drv = OGRGetDriverByName(
"Memory");
125 arg.
dst.
ds = OGR_Dr_CreateDataSource(arg.
dst.
drv,
"contour_ds", NULL);
130 #if POSTGIS_GDAL_VERSION >= 24
131 arg.
dst.
gtype = polygonize ? wkbPolygon : wkbLineString;
142 OGRFieldDefnH hFldId = OGR_Fld_Create(
"id", OFTInteger);
143 ogrerr = OGR_L_CreateField(arg.
dst.
lyr, hFldId,
TRUE);
144 if (ogrerr != OGRERR_NONE)
148 OGRFieldDefnH hFldElevation = OGR_Fld_Create(
"elevation", OFTReal);
149 ogrerr = OGR_L_CreateField(arg.
dst.
lyr, hFldElevation,
TRUE);
150 if (ogrerr != OGRERR_NONE)
161 double no_data_value = GDALGetRasterNoDataValue(hBand, &use_no_data);;
164 cplerr = GDALContourGenerate(
166 contour_interval, contour_base,
167 fixed_level_count, fixed_levels,
168 use_no_data, no_data_value,
174 if (cplerr != CE_None)
178 nfeatures = OGR_L_GetFeatureCount(arg.
dst.
lyr,
TRUE);
183 OGR_L_ResetReading(arg.
dst.
lyr);
184 while ((hFeat = OGR_L_GetNextFeature(arg.
dst.
lyr))) {
186 unsigned char *bufWkb;
192 if(i >= nfeatures)
break;
195 contour.
id = OGR_F_GetFieldAsInteger(hFeat, 0);
196 contour.
elevation = OGR_F_GetFieldAsDouble(hFeat, 1);
198 if (!(hGeom = OGR_F_GetGeometryRef(hFeat)))
continue;
199 szWkb = OGR_G_WkbSize(hGeom);
201 if (OGR_G_ExportToWkb(hGeom, wkbNDR, bufWkb) != OGRERR_NONE)
continue;
203 OGR_F_Destroy(hFeat);
210 (*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...
void rterror(const char *fmt,...)
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 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.
struct _rti_contour_arg::@12 dst
struct _rti_contour_arg::@11 src