34 #include "../../postgis_config.h"
37 #include "access/htup_details.h"
90 if (PG_ARGISNULL(0)) PG_RETURN_NULL();
95 PG_FREE_IF_COPY(pgraster, 0);
96 elog(ERROR,
"RASTER_getSRID: Could not deserialize raster");
103 PG_FREE_IF_COPY(pgraster, 0);
105 PG_RETURN_INT32(
srid);
118 if (PG_ARGISNULL(0)) PG_RETURN_NULL();
123 PG_FREE_IF_COPY(pgraster, 0);
124 elog(ERROR,
"RASTER_getWidth: Could not deserialize raster");
131 PG_FREE_IF_COPY(pgraster, 0);
133 PG_RETURN_INT32(
width);
146 if (PG_ARGISNULL(0)) PG_RETURN_NULL();
151 PG_FREE_IF_COPY(pgraster, 0);
152 elog(ERROR,
"RASTER_getHeight: Could not deserialize raster");
159 PG_FREE_IF_COPY(pgraster, 0);
174 if (PG_ARGISNULL(0)) PG_RETURN_NULL();
179 PG_FREE_IF_COPY(pgraster, 0);
180 elog(ERROR,
"RASTER_getNumBands: Could not deserialize raster");
187 PG_FREE_IF_COPY(pgraster, 0);
189 PG_RETURN_INT32(num_bands);
202 if (PG_ARGISNULL(0)) PG_RETURN_NULL();
207 PG_FREE_IF_COPY(pgraster, 0);
208 elog(ERROR,
"RASTER_getXScale: Could not deserialize raster");
215 PG_FREE_IF_COPY(pgraster, 0);
217 PG_RETURN_FLOAT8(
xsize);
230 if (PG_ARGISNULL(0)) PG_RETURN_NULL();
235 PG_FREE_IF_COPY(pgraster, 0);
236 elog(ERROR,
"RASTER_getYScale: Could not deserialize raster");
243 PG_FREE_IF_COPY(pgraster, 0);
245 PG_RETURN_FLOAT8(
ysize);
258 if (PG_ARGISNULL(0)) PG_RETURN_NULL();
263 PG_FREE_IF_COPY(pgraster, 0);
264 elog(ERROR,
"RASTER_getXSkew: Could not deserialize raster");
271 PG_FREE_IF_COPY(pgraster, 0);
273 PG_RETURN_FLOAT8(xskew);
286 if (PG_ARGISNULL(0)) PG_RETURN_NULL();
291 PG_FREE_IF_COPY(pgraster, 0);
292 elog(ERROR,
"RASTER_getYSkew: Could not deserialize raster");
299 PG_FREE_IF_COPY(pgraster, 0);
301 PG_RETURN_FLOAT8(yskew);
314 if (PG_ARGISNULL(0)) PG_RETURN_NULL();
319 PG_FREE_IF_COPY(pgraster, 0);
320 elog(ERROR,
"RASTER_getXUpperLeft: Could not deserialize raster");
327 PG_FREE_IF_COPY(pgraster, 0);
329 PG_RETURN_FLOAT8(xul);
342 if (PG_ARGISNULL(0)) PG_RETURN_NULL();
347 PG_FREE_IF_COPY(pgraster, 0);
348 elog(ERROR,
"RASTER_getYUpperLeft: Could not deserialize raster");
355 PG_FREE_IF_COPY(pgraster, 0);
357 PG_RETURN_FLOAT8(yul);
376 if (PG_ARGISNULL(0)) PG_RETURN_NULL();
381 PG_FREE_IF_COPY(pgraster, 0);
382 elog(ERROR,
"RASTER_getPixelWidth: Could not deserialize raster");
388 pwidth = sqrt(xscale*xscale + yskew*yskew);
391 PG_FREE_IF_COPY(pgraster, 0);
393 PG_RETURN_FLOAT8(pwidth);
412 if (PG_ARGISNULL(0)) PG_RETURN_NULL();
417 PG_FREE_IF_COPY(pgraster, 0);
418 elog(ERROR,
"RASTER_getPixelHeight: Could not deserialize raster");
424 pheight = sqrt(yscale*yscale + xskew*xskew);
427 PG_FREE_IF_COPY(pgraster, 0);
429 PG_RETURN_FLOAT8(pheight);
432 #define VALUES_LENGTH 6
453 TupleDesc result_tuple;
456 HeapTuple heap_tuple ;
469 PG_FREE_IF_COPY(pgraster, 0);
470 elog(ERROR,
"RASTER_getGeotransform: Could not deserialize raster");
480 &imag, &jmag, &theta_i, &theta_ij) ;
483 PG_FREE_IF_COPY(pgraster, 0);
486 if (get_call_result_type(fcinfo, NULL, &result_tuple) != TYPEFUNC_COMPOSITE) {
488 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
489 errmsg(
"RASTER_getGeotransform(): function returning record called in context that cannot accept type record"
495 BlessTupleDesc(result_tuple);
500 values[0] = Float8GetDatum(imag);
501 values[1] = Float8GetDatum(jmag);
502 values[2] = Float8GetDatum(theta_i);
503 values[3] = Float8GetDatum(theta_ij);
510 heap_tuple = heap_form_tuple(result_tuple, values, nulls);
513 result = HeapTupleGetDatum(heap_tuple);
515 PG_RETURN_DATUM(result);
526 bool isempty =
FALSE;
529 if (PG_ARGISNULL(0)) PG_RETURN_NULL();
536 (errcode(ERRCODE_OUT_OF_MEMORY),
537 errmsg(
"RASTER_isEmpty: Could not deserialize raster")));
538 PG_FREE_IF_COPY(pgraster, 0);
545 PG_FREE_IF_COPY(pgraster, 0);
547 PG_RETURN_BOOL(isempty);
559 bool hasnoband =
FALSE;
562 if (PG_ARGISNULL(0)) PG_RETURN_NULL();
569 (errcode(ERRCODE_OUT_OF_MEMORY),
570 errmsg(
"RASTER_hasNoBand: Could not deserialize raster")));
571 PG_FREE_IF_COPY(pgraster, 0);
576 bandindex = PG_GETARG_INT32(1);
580 PG_FREE_IF_COPY(pgraster, 0);
582 PG_RETURN_BOOL(hasnoband);
586 #define VALUES_LENGTH 10
624 PG_FREE_IF_COPY(pgraster, 0);
625 elog(ERROR,
"RASTER_metadata; Could not deserialize raster");
652 PG_FREE_IF_COPY(pgraster, 0);
655 if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE) {
657 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
659 "function returning record called in context "
660 "that cannot accept type record"
665 BlessTupleDesc(tupdesc);
667 values[0] = Float8GetDatum(
ipX);
668 values[1] = Float8GetDatum(
ipY);
669 values[2] = UInt32GetDatum(
width);
670 values[3] = UInt32GetDatum(
height);
671 values[4] = Float8GetDatum(
scaleX);
672 values[5] = Float8GetDatum(
scaleY);
673 values[6] = Float8GetDatum(
skewX);
674 values[7] = Float8GetDatum(
skewY);
675 values[8] = Int32GetDatum(
srid);
676 values[9] = UInt32GetDatum(
numBands);
681 tuple = heap_form_tuple(tupdesc, values, nulls);
684 result = HeapTupleGetDatum(tuple);
686 PG_RETURN_DATUM(result);
690 #define VALUES_LENGTH 2
699 bool skewed[2] = {
false,
false};
718 PG_FREE_IF_COPY(pgraster, 0);
719 elog(ERROR,
"RASTER_rasterToWorldCoord: Could not deserialize raster");
728 for (i = 1; i <= 2; i++) {
729 if (PG_ARGISNULL(i)) {
732 elog(NOTICE,
"Pixel row and column required for computing longitude and latitude of a rotated raster");
734 PG_FREE_IF_COPY(pgraster, 0);
741 cr[i - 1] = PG_GETARG_INT32(i);
747 (
double) cr[0] - 1, (
double) cr[1] - 1,
752 PG_FREE_IF_COPY(pgraster, 0);
753 elog(ERROR,
"RASTER_rasterToWorldCoord: Could not compute longitude and latitude from pixel row and column");
757 PG_FREE_IF_COPY(pgraster, 0);
760 if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE) {
762 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
764 "function returning record called in context "
765 "that cannot accept type record"
770 BlessTupleDesc(tupdesc);
772 values[0] = Float8GetDatum(cw[0]);
773 values[1] = Float8GetDatum(cw[1]);
778 tuple = heap_form_tuple(tupdesc, values, nulls);
781 result = HeapTupleGetDatum(tuple);
783 PG_RETURN_DATUM(result);
813 PG_FREE_IF_COPY(pgraster, 0);
814 elog(ERROR,
"RASTER_worldToRasterCoord: Could not deserialize raster");
824 for (i = 1; i <= 2; i++) {
825 if (PG_ARGISNULL(i)) {
828 elog(NOTICE,
"Latitude and longitude required for computing pixel row and column of a rotated raster");
830 PG_FREE_IF_COPY(pgraster, 0);
837 cw[i - 1] = PG_GETARG_FLOAT8(i);
844 &(_cr[0]), &(_cr[1]),
848 PG_FREE_IF_COPY(pgraster, 0);
849 elog(ERROR,
"RASTER_worldToRasterCoord: Could not compute pixel row and column from longitude and latitude");
853 PG_FREE_IF_COPY(pgraster, 0);
856 cr[0] = ((int) _cr[0]) + 1;
857 cr[1] = ((int) _cr[1]) + 1;
860 if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE) {
862 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
864 "function returning record called in context "
865 "that cannot accept type record"
870 BlessTupleDesc(tupdesc);
872 values[0] = Int32GetDatum(cr[0]);
873 values[1] = Int32GetDatum(cr[1]);
878 tuple = heap_form_tuple(tupdesc, values, nulls);
881 result = HeapTupleGetDatum(tuple);
883 PG_RETURN_DATUM(result);
895 int32_t newSRID = PG_GETARG_INT32(1);
897 if (PG_ARGISNULL(0)) PG_RETURN_NULL();
898 pgraster = (
rt_pgraster *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
902 PG_FREE_IF_COPY(pgraster, 0);
903 elog(ERROR,
"RASTER_setSRID: Could not deserialize raster");
911 PG_FREE_IF_COPY(pgraster, 0);
912 if (!pgrtn) PG_RETURN_NULL();
914 SET_VARSIZE(pgrtn, pgrtn->
size);
916 PG_RETURN_POINTER(pgrtn);
928 double size = PG_GETARG_FLOAT8(1);
932 pgraster = (
rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
935 PG_FREE_IF_COPY(pgraster, 0);
936 elog(ERROR,
"RASTER_setScale: Could not deserialize raster");
944 PG_FREE_IF_COPY(pgraster, 0);
948 SET_VARSIZE(pgrtn, pgrtn->
size);
949 PG_RETURN_POINTER(pgrtn);
961 double xscale = PG_GETARG_FLOAT8(1);
962 double yscale = PG_GETARG_FLOAT8(2);
966 pgraster = (
rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
969 PG_FREE_IF_COPY(pgraster, 0);
970 elog(ERROR,
"RASTER_setScaleXY: Could not deserialize raster");
977 PG_FREE_IF_COPY(pgraster, 0);
981 SET_VARSIZE(pgrtn, pgrtn->
size);
982 PG_RETURN_POINTER(pgrtn);
994 double skew = PG_GETARG_FLOAT8(1);
998 pgraster = (
rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
1001 PG_FREE_IF_COPY(pgraster, 0);
1002 elog(ERROR,
"RASTER_setSkew: Could not deserialize raster");
1010 PG_FREE_IF_COPY(pgraster, 0);
1014 SET_VARSIZE(pgrtn, pgrtn->
size);
1015 PG_RETURN_POINTER(pgrtn);
1027 double xskew = PG_GETARG_FLOAT8(1);
1028 double yskew = PG_GETARG_FLOAT8(2);
1030 if (PG_ARGISNULL(0))
1032 pgraster = (
rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
1035 PG_FREE_IF_COPY(pgraster, 0);
1036 elog(ERROR,
"RASTER_setSkewXY: Could not deserialize raster");
1044 PG_FREE_IF_COPY(pgraster, 0);
1048 SET_VARSIZE(pgrtn, pgrtn->
size);
1049 PG_RETURN_POINTER(pgrtn);
1061 double xoffset = PG_GETARG_FLOAT8(1);
1062 double yoffset = PG_GETARG_FLOAT8(2);
1064 if (PG_ARGISNULL(0))
1066 pgraster = (
rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
1069 PG_FREE_IF_COPY(pgraster, 0);
1070 elog(ERROR,
"RASTER_setUpperLeftXY: Could not deserialize raster");
1078 PG_FREE_IF_COPY(pgraster, 0);
1082 SET_VARSIZE(pgrtn, pgrtn->
size);
1083 PG_RETURN_POINTER(pgrtn);
1095 float8 imag, jmag, theta_i, theta_ij, xoffset, yoffset;
1098 PG_ARGISNULL(0) || PG_ARGISNULL(1) || PG_ARGISNULL(2) ||
1099 PG_ARGISNULL(3) || PG_ARGISNULL(4) ||
1100 PG_ARGISNULL(5) || PG_ARGISNULL(6)
1106 pgraster = (
rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
1107 imag = PG_GETARG_FLOAT8(1);
1108 jmag = PG_GETARG_FLOAT8(2);
1109 theta_i = PG_GETARG_FLOAT8(3);
1110 theta_ij = PG_GETARG_FLOAT8(4);
1111 xoffset = PG_GETARG_FLOAT8(5);
1112 yoffset = PG_GETARG_FLOAT8(6);
1116 PG_FREE_IF_COPY(pgraster, 0);
1117 elog(ERROR,
"RASTER_setGeotransform: Could not deserialize raster");
1128 PG_FREE_IF_COPY(pgraster, 0);
1132 SET_VARSIZE(pgrtn, pgrtn->
size);
1133 PG_RETURN_POINTER(pgrtn);
1153 double rotation = PG_GETARG_FLOAT8(1);
1154 double imag, jmag, theta_i, theta_ij;
1156 if (PG_ARGISNULL(0))
1158 pgraster = (
rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
1162 PG_FREE_IF_COPY(pgraster, 0);
1163 elog(ERROR,
"RASTER_setRotation: Could not deserialize raster");
1173 PG_FREE_IF_COPY(pgraster, 0);
1177 SET_VARSIZE(pgrtn, pgrtn->
size);
1178 PG_RETURN_POINTER(pgrtn);
rt_errorstate rt_raster_cell_to_geopoint(rt_raster raster, double xr, double yr, double *xw, double *yw, double *gt)
Convert an xr, yr raster point to an xw, yw point on map.
int32_t rt_raster_get_srid(rt_raster raster)
Get raster's SRID.
double rt_raster_get_x_skew(rt_raster raster)
Get skew about the X axis.
double rt_raster_get_x_offset(rt_raster raster)
Get raster x offset, in projection units.
void rt_raster_set_scale(rt_raster raster, double scaleX, double scaleY)
Set scale in projection units.
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.
void rt_raster_set_skews(rt_raster raster, double skewX, double skewY)
Set skews about the X and Y axis.
int rt_raster_has_band(rt_raster raster, int nband)
Return TRUE if the raster has a band of this number.
void * rt_raster_serialize(rt_raster raster)
Return this raster in serialized form.
double rt_raster_get_x_scale(rt_raster raster)
Get scale X in projection units.
void rt_raster_get_phys_params(rt_raster rast, double *i_mag, double *j_mag, double *theta_i, double *theta_ij)
Calculates and returns the physically significant descriptors embodied in the geotransform attached t...
uint16_t rt_raster_get_num_bands(rt_raster raster)
uint16_t rt_raster_get_height(rt_raster raster)
void rt_raster_set_srid(rt_raster raster, int32_t srid)
Set raster's SRID.
void rt_raster_set_phys_params(rt_raster rast, double i_mag, double j_mag, double theta_i, double theta_ij)
Calculates the geotransform coefficients and applies them to the supplied raster.
uint16_t rt_raster_get_width(rt_raster raster)
double rt_raster_get_y_scale(rt_raster raster)
Get scale Y in projection units.
double rt_raster_get_y_skew(rt_raster raster)
Get skew about the Y axis.
void rt_raster_set_offsets(rt_raster raster, double x, double y)
Set insertion points in projection units.
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.
void rt_raster_calc_phys_params(double xscale, double xskew, double yskew, double yscale, double *i_mag, double *j_mag, double *theta_i, double *theta_ij)
Calculates the physically significant descriptors embodied in an arbitrary geotransform.
double rt_raster_get_y_offset(rt_raster raster)
Get raster y offset, in projection units.
int rt_raster_is_empty(rt_raster raster)
Return TRUE if the raster is empty.
raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
Datum RASTER_getGeotransform(PG_FUNCTION_ARGS)
Datum RASTER_getXScale(PG_FUNCTION_ARGS)
Datum RASTER_getFileTimestamp(PG_FUNCTION_ARGS)
Datum RASTER_getPixelWidth(PG_FUNCTION_ARGS)
Datum RASTER_getPixelHeight(PG_FUNCTION_ARGS)
Datum RASTER_getYUpperLeft(PG_FUNCTION_ARGS)
PG_FUNCTION_INFO_V1(RASTER_getSRID)
Return the SRID associated with the raster.
Datum RASTER_setSkew(PG_FUNCTION_ARGS)
Datum RASTER_hasNoBand(PG_FUNCTION_ARGS)
Datum RASTER_setScale(PG_FUNCTION_ARGS)
Datum RASTER_getYSkew(PG_FUNCTION_ARGS)
Datum RASTER_metadata(PG_FUNCTION_ARGS)
Datum RASTER_getYScale(PG_FUNCTION_ARGS)
Datum RASTER_getFileSize(PG_FUNCTION_ARGS)
Datum RASTER_getNumBands(PG_FUNCTION_ARGS)
Datum RASTER_rasterToWorldCoord(PG_FUNCTION_ARGS)
Datum RASTER_setUpperLeftXY(PG_FUNCTION_ARGS)
Datum RASTER_setRotation(PG_FUNCTION_ARGS)
Datum RASTER_isEmpty(PG_FUNCTION_ARGS)
Datum RASTER_setGeotransform(PG_FUNCTION_ARGS)
Datum RASTER_getWidth(PG_FUNCTION_ARGS)
Datum RASTER_setSkewXY(PG_FUNCTION_ARGS)
Datum RASTER_getXSkew(PG_FUNCTION_ARGS)
Datum RASTER_worldToRasterCoord(PG_FUNCTION_ARGS)
Datum RASTER_setScaleXY(PG_FUNCTION_ARGS)
Datum RASTER_getHeight(PG_FUNCTION_ARGS)
Datum RASTER_getSRID(PG_FUNCTION_ARGS)
Datum RASTER_getXUpperLeft(PG_FUNCTION_ARGS)
Datum RASTER_setSRID(PG_FUNCTION_ARGS)
#define POSTGIS_RT_DEBUG(level, msg)