662 uint32_t out_rast_bands[1] = {0};
666 uint16_t in_band_width, in_band_height;
669 GDALDataType in_band_gdaltype;
670 size_t in_band_gdaltype_size;
674 GDALGridAlgorithm algorithm;
675 text *options_txt = NULL;
676 void *options_struct = NULL;
684 size_t coord_count = 0;
686 double *xcoords, *ycoords, *zcoords;
692 elog(ERROR,
"%s: input geometry does not have Z values", __func__);
698 in_pgrast = (
rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(2));
701 elog(ERROR,
"%s: Could not deserialize raster", __func__);
706 elog(ERROR,
"%s: Cannot generate a grid into a skewed raster",__func__);
710 options_txt = PG_GETARG_TEXT_P(1);
712 band_number = PG_GETARG_INT32(3);
714 elog(ERROR,
"%s: Invalid band number %d", __func__, band_number);
720 elog(ERROR,
"%s: Geometry has no points", __func__);
724 elog(ERROR,
"%s: Cannot access raster band %d", __func__, band_number);
729 elog(ERROR,
"%s: Unable to calculate envelope", __func__);
736 in_band_gdaltype_size = GDALGetDataTypeSizeBytes(in_band_gdaltype);
770 out_data = palloc(in_band_gdaltype_size * in_band_width * in_band_height);
773 xcoords = palloc(
sizeof(
double) * npoints);
774 ycoords = palloc(
sizeof(
double) * npoints);
775 zcoords = palloc(
sizeof(
double) * npoints);
780 if (coord_count >= npoints)
781 elog(ERROR,
"%s: More points from iterator than expected", __func__);
782 xcoords[coord_count] = pt.
x;
783 ycoords[coord_count] = pt.
y;
784 zcoords[coord_count] = pt.
z;
791 err = ParseAlgorithmAndOptions(
792 text_to_cstring(options_txt),
795 if (err != CE_None) {
796 if (options_struct)
free(options_struct);
797 elog(ERROR,
"%s: Unable to parse options string: %s", __func__, CPLGetLastErrorMsg());
801 err = GDALGridCreate(
802 algorithm, options_struct,
803 npoints, xcoords, ycoords, zcoords,
805 in_band_width, in_band_height,
806 in_band_gdaltype, out_data,
813 free(options_struct);
815 if (err != CE_None) {
816 elog(ERROR,
"%s: GDALGridCreate failed: %s", __func__, CPLGetLastErrorMsg());
819 out_rast_bands[0] = band_number-1;
823 elog(ERROR,
"%s: Cannot access output raster band", __func__);
826 for (uint32_t
y = 0;
y < in_band_height;
y++) {
827 size_t offset = (in_band_height-
y-1) * (in_band_gdaltype_size * in_band_width);
835 if (NULL == out_pgrast) PG_RETURN_NULL();
837 SET_VARSIZE(out_pgrast, out_pgrast->
size);
838 PG_RETURN_POINTER(out_pgrast);
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
int gserialized_has_z(const GSERIALIZED *g)
Check if a GSERIALIZED has a Z ordinate.
LWPOINTITERATOR * lwpointiterator_create(const LWGEOM *g)
Create a new LWPOINTITERATOR over supplied LWGEOM*.
int lwpointiterator_next(LWPOINTITERATOR *s, POINT4D *p)
Attempts to assign the next point in the iterator to p, and advances the iterator to the next point.
void lwpointiterator_destroy(LWPOINTITERATOR *s)
Free all memory associated with the iterator.
uint32_t lwgeom_count_vertices(const LWGEOM *geom)
Count the total number of vertices in any LWGEOM.
uint16_t rt_band_get_width(rt_band band)
Return width of this band.
double rt_raster_get_x_skew(rt_raster raster)
Get skew about the X axis.
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
GDALDataType rt_util_pixtype_to_gdal_datatype(rt_pixtype pt)
Convert rt_pixtype to GDALDataType.
void * rt_raster_serialize(rt_raster raster)
Return this raster in serialized form.
rt_errorstate
Enum definitions.
rt_errorstate rt_band_set_pixel_line(rt_band band, int x, int y, void *vals, uint32_t len)
Set values of multiple pixels.
rt_raster rt_raster_from_band(rt_raster raster, uint32_t *bandNums, int count)
Construct a new rt_raster from an existing rt_raster and an array of band numbers.
rt_pixtype rt_band_get_pixtype(rt_band band)
Return pixeltype of this band.
rt_errorstate rt_raster_get_envelope(rt_raster raster, rt_envelope *env)
Get raster's envelope.
double rt_raster_get_y_skew(rt_raster raster)
Get skew about the Y axis.
uint16_t rt_band_get_height(rt_band band)
Return height of this band.
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.
rt_band rt_raster_get_band(rt_raster raster, int bandNum)
Return Nth band, or NULL if unavailable.
static int rtpg_util_gdal_progress_func(double dfComplete, const char *pszMessage, void *pProgressArg)