649 uint32_t out_rast_bands[1] = {0};
653 uint16_t in_band_width, in_band_height;
656 GDALDataType in_band_gdaltype;
657 size_t in_band_gdaltype_size;
661 GDALGridAlgorithm algorithm;
662 text *options_txt = NULL;
663 void *options_struct = NULL;
671 size_t coord_count = 0;
673 double *xcoords, *ycoords, *zcoords;
679 elog(ERROR,
"%s: input geometry does not have Z values", __func__);
685 in_pgrast = (
rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(2));
688 elog(ERROR,
"%s: Could not deserialize raster", __func__);
693 elog(ERROR,
"%s: Cannot generate a grid into a skewed raster",__func__);
697 options_txt = PG_GETARG_TEXT_P(1);
699 band_number = PG_GETARG_INT32(3);
701 elog(ERROR,
"%s: Invalid band number %d", __func__, band_number);
707 elog(ERROR,
"%s: Geometry has no points", __func__);
711 elog(ERROR,
"%s: Cannot access raster band %d", __func__, band_number);
716 elog(ERROR,
"%s: Unable to calculate envelope", __func__);
723 in_band_gdaltype_size = GDALGetDataTypeSize(in_band_gdaltype) / 8;
757 out_data = palloc(in_band_gdaltype_size * in_band_width * in_band_height);
760 xcoords = palloc(
sizeof(
double) * npoints);
761 ycoords = palloc(
sizeof(
double) * npoints);
762 zcoords = palloc(
sizeof(
double) * npoints);
767 if (coord_count >= npoints)
768 elog(ERROR,
"%s: More points from iterator than expected", __func__);
769 xcoords[coord_count] = pt.
x;
770 ycoords[coord_count] = pt.
y;
771 zcoords[coord_count] = pt.
z;
778 err = ParseAlgorithmAndOptions(
779 text_to_cstring(options_txt),
782 if (err != CE_None) {
783 if (options_struct)
free(options_struct);
784 elog(ERROR,
"%s: Unable to parse options string: %s", __func__, CPLGetLastErrorMsg());
788 err = GDALGridCreate(
789 algorithm, options_struct,
790 npoints, xcoords, ycoords, zcoords,
792 in_band_width, in_band_height,
793 in_band_gdaltype, out_data,
800 free(options_struct);
802 if (err != CE_None) {
803 elog(ERROR,
"%s: GDALGridCreate failed: %s", __func__, CPLGetLastErrorMsg());
806 out_rast_bands[0] = band_number-1;
810 elog(ERROR,
"%s: Cannot access output raster band", __func__);
813 for (uint32_t
y = 0;
y < in_band_height;
y++) {
814 size_t offset = (in_band_height-
y-1) * (in_band_gdaltype_size * in_band_width);
822 if (NULL == out_pgrast) PG_RETURN_NULL();
824 SET_VARSIZE(out_pgrast, out_pgrast->
size);
825 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.