788{
791 int i = 0;
792 double cw[2] = {0};
793 double _cr[2] = {0};
794 int cr[2] = {0};
795 bool skewed = false;
796
797 TupleDesc tupdesc;
800 HeapTuple tuple;
802
804
805
806 if (PG_ARGISNULL(0))
807 PG_RETURN_NULL();
809
810
812 if (!raster) {
813 PG_FREE_IF_COPY(pgraster, 0);
814 elog(ERROR, "RASTER_worldToRasterCoord: Could not deserialize raster");
815 PG_RETURN_NULL();
816 }
817
818
820 if (!skewed)
822
823
824 for (i = 1; i <= 2; i++) {
825 if (PG_ARGISNULL(i)) {
826
827 if (skewed) {
828 elog(NOTICE, "Latitude and longitude required for computing pixel row and column of a rotated raster");
830 PG_FREE_IF_COPY(pgraster, 0);
831 PG_RETURN_NULL();
832 }
833
834 continue;
835 }
836
837 cw[i - 1] = PG_GETARG_FLOAT8(i);
838 }
839
840
842 raster,
843 cw[0], cw[1],
844 &(_cr[0]), &(_cr[1]),
845 NULL
848 PG_FREE_IF_COPY(pgraster, 0);
849 elog(ERROR, "RASTER_worldToRasterCoord: Could not compute pixel row and column from longitude and latitude");
850 PG_RETURN_NULL();
851 }
853 PG_FREE_IF_COPY(pgraster, 0);
854
855
856 cr[0] = ((int) _cr[0]) + 1;
857 cr[1] = ((int) _cr[1]) + 1;
858
859
860 if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE) {
861 ereport(ERROR, (
862 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
863 errmsg(
864 "function returning record called in context "
865 "that cannot accept type record"
866 )
867 ));
868 }
869
870 BlessTupleDesc(tupdesc);
871
872 values[0] = Int32GetDatum(cr[0]);
873 values[1] = Int32GetDatum(cr[1]);
874
876
877
878 tuple = heap_form_tuple(tupdesc, values, nulls);
879
880
881 result = HeapTupleGetDatum(tuple);
882
884}
char result[OUT_DOUBLE_BUFFER_SIZE]
double rt_raster_get_x_skew(rt_raster raster)
Get skew about the X axis.
rt_errorstate rt_raster_geopoint_to_cell(rt_raster raster, double xw, double yw, double *xr, double *yr, double *igt)
Convert an xw, yw map point to a xr, yr raster point.
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
double rt_raster_get_y_skew(rt_raster raster)
Get skew about the Y axis.
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.
raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
#define POSTGIS_RT_DEBUG(level, msg)