657{
662 uint32_t out_rast_bands[1] = {0};
665 int band_number;
666 uint16_t in_band_width, in_band_height;
667 uint32_t npoints;
669 GDALDataType in_band_gdaltype;
670 size_t in_band_gdaltype_size;
671
673
674 GDALGridAlgorithm algorithm;
675 text *options_txt = NULL;
676 void *options_struct = NULL;
677 CPLErr err;
678 uint8_t *out_data;
680
681
684 size_t coord_count = 0;
686 double *xcoords, *ycoords, *zcoords;
687
689
690
692 elog(ERROR, "%s: input geometry does not have Z values", __func__);
693
694
696 PG_RETURN_NULL();
697
698 in_pgrast = (
rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(2));
700 if (!in_rast)
701 elog(ERROR, "%s: Could not deserialize raster", __func__);
702
703
706 elog(ERROR, "%s: Cannot generate a grid into a skewed raster",__func__);
707 }
708
709
710 options_txt = PG_GETARG_TEXT_P(1);
711
712 band_number = PG_GETARG_INT32(3);
713 if (band_number < 1)
714 elog(ERROR, "%s: Invalid band number %d", __func__, band_number);
715
718
719 if (npoints < 1)
720 elog(ERROR, "%s: Geometry has no points", __func__);
721
723 if (!in_band)
724 elog(ERROR, "%s: Cannot access raster band %d", __func__, band_number);
725
726
729 elog(ERROR, "%s: Unable to calculate envelope", __func__);
730
731
736 in_band_gdaltype_size = GDALGetDataTypeSizeBytes(in_band_gdaltype);
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770 out_data = palloc(in_band_gdaltype_size * in_band_width * in_band_height);
771
772
773 xcoords = palloc(sizeof(double) * npoints);
774 ycoords = palloc(sizeof(double) * npoints);
775 zcoords = palloc(sizeof(double) * npoints);
776
777
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;
785 coord_count++;
786 }
788
789
790
791 err = ParseAlgorithmAndOptions(
792 text_to_cstring(options_txt),
793 &algorithm,
794 &options_struct);
795 if (err != CE_None) {
796 if (options_struct)
free(options_struct);
797 elog(ERROR, "%s: Unable to parse options string: %s", __func__, CPLGetLastErrorMsg());
798 }
799
800
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,
808 NULL
809 );
810
811
812 if (options_struct)
813 free(options_struct);
814
815 if (err != CE_None) {
816 elog(ERROR, "%s: GDALGridCreate failed: %s", __func__, CPLGetLastErrorMsg());
817 }
818
819 out_rast_bands[0] = band_number-1;
822 if (!out_band)
823 elog(ERROR, "%s: Cannot access output raster band", __func__);
824
825
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);
829 }
830
834
835 if (NULL == out_pgrast) PG_RETURN_NULL();
836
837 SET_VARSIZE(out_pgrast, out_pgrast->
size);
838 PG_RETURN_POINTER(out_pgrast);
839}
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.
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.
void * rt_raster_serialize(rt_raster raster)
Return this raster in serialized form.
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)