648 uint32_t out_rast_bands[1] = {0};
652 uint16_t in_band_width, in_band_height;
655 GDALDataType in_band_gdaltype;
656 size_t in_band_gdaltype_size;
660 GDALGridAlgorithm algorithm;
661 text *options_txt = NULL;
662 void *options_struct = NULL;
670 size_t coord_count = 0;
672 double *xcoords, *ycoords, *zcoords;
678 elog(ERROR,
"%s: input geometry does not have Z values", __func__);
684 in_pgrast = (
rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(2));
687 elog(ERROR,
"%s: Could not deserialize raster", __func__);
692 elog(ERROR,
"%s: Cannot generate a grid into a skewed raster",__func__);
696 options_txt = PG_GETARG_TEXT_P(1);
698 band_number = PG_GETARG_INT32(3);
700 elog(ERROR,
"%s: Invalid band number %d", __func__, band_number);
706 elog(ERROR,
"%s: Geometry has no points", __func__);
710 elog(ERROR,
"%s: Cannot access raster band %d", __func__, band_number);
715 elog(ERROR,
"%s: Unable to calculate envelope", __func__);
722 in_band_gdaltype_size = GDALGetDataTypeSize(in_band_gdaltype) / 8;
756 out_data = palloc(in_band_gdaltype_size * in_band_width * in_band_height);
759 xcoords = palloc(
sizeof(
double) * npoints);
760 ycoords = palloc(
sizeof(
double) * npoints);
761 zcoords = palloc(
sizeof(
double) * npoints);
766 if (coord_count >= npoints)
767 elog(ERROR,
"%s: More points from iterator than expected", __func__);
768 xcoords[coord_count] = pt.
x;
769 ycoords[coord_count] = pt.
y;
770 zcoords[coord_count] = pt.
z;
777 err = ParseAlgorithmAndOptions(
778 text_to_cstring(options_txt),
781 if (err != CE_None) {
782 if (options_struct)
free(options_struct);
783 elog(ERROR,
"%s: Unable to parse options string: %s", __func__, CPLGetLastErrorMsg());
787 err = GDALGridCreate(
788 algorithm, options_struct,
789 npoints, xcoords, ycoords, zcoords,
791 in_band_width, in_band_height,
792 in_band_gdaltype, out_data,
799 free(options_struct);
801 if (err != CE_None) {
802 elog(ERROR,
"%s: GDALGridCreate failed: %s", __func__, CPLGetLastErrorMsg());
805 out_rast_bands[0] = band_number-1;
809 elog(ERROR,
"%s: Cannot access output raster band", __func__);
812 for (uint32_t
y = 0;
y < in_band_height;
y++) {
813 size_t offset = (in_band_height-
y-1) * (in_band_gdaltype_size * in_band_width);
821 if (NULL == out_pgrast) PG_RETURN_NULL();
823 SET_VARSIZE(out_pgrast, out_pgrast->
size);
824 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.