34 #include "../../postgis_config.h" 37 #include "access/htup_details.h" 88 if (PG_ARGISNULL(0)) PG_RETURN_NULL();
93 PG_FREE_IF_COPY(pgraster, 0);
94 elog(ERROR,
"RASTER_getSRID: Could not deserialize raster");
101 PG_FREE_IF_COPY(pgraster, 0);
103 PG_RETURN_INT32(srid);
116 if (PG_ARGISNULL(0)) PG_RETURN_NULL();
121 PG_FREE_IF_COPY(pgraster, 0);
122 elog(ERROR,
"RASTER_getWidth: Could not deserialize raster");
129 PG_FREE_IF_COPY(pgraster, 0);
131 PG_RETURN_INT32(width);
144 if (PG_ARGISNULL(0)) PG_RETURN_NULL();
149 PG_FREE_IF_COPY(pgraster, 0);
150 elog(ERROR,
"RASTER_getHeight: Could not deserialize raster");
157 PG_FREE_IF_COPY(pgraster, 0);
159 PG_RETURN_INT32(height);
172 if (PG_ARGISNULL(0)) PG_RETURN_NULL();
177 PG_FREE_IF_COPY(pgraster, 0);
178 elog(ERROR,
"RASTER_getNumBands: Could not deserialize raster");
185 PG_FREE_IF_COPY(pgraster, 0);
187 PG_RETURN_INT32(num_bands);
200 if (PG_ARGISNULL(0)) PG_RETURN_NULL();
205 PG_FREE_IF_COPY(pgraster, 0);
206 elog(ERROR,
"RASTER_getXScale: Could not deserialize raster");
213 PG_FREE_IF_COPY(pgraster, 0);
215 PG_RETURN_FLOAT8(xsize);
228 if (PG_ARGISNULL(0)) PG_RETURN_NULL();
233 PG_FREE_IF_COPY(pgraster, 0);
234 elog(ERROR,
"RASTER_getYScale: Could not deserialize raster");
241 PG_FREE_IF_COPY(pgraster, 0);
243 PG_RETURN_FLOAT8(ysize);
256 if (PG_ARGISNULL(0)) PG_RETURN_NULL();
261 PG_FREE_IF_COPY(pgraster, 0);
262 elog(ERROR,
"RASTER_getXSkew: Could not deserialize raster");
269 PG_FREE_IF_COPY(pgraster, 0);
271 PG_RETURN_FLOAT8(xskew);
284 if (PG_ARGISNULL(0)) PG_RETURN_NULL();
289 PG_FREE_IF_COPY(pgraster, 0);
290 elog(ERROR,
"RASTER_getYSkew: Could not deserialize raster");
297 PG_FREE_IF_COPY(pgraster, 0);
299 PG_RETURN_FLOAT8(yskew);
312 if (PG_ARGISNULL(0)) PG_RETURN_NULL();
317 PG_FREE_IF_COPY(pgraster, 0);
318 elog(ERROR,
"RASTER_getXUpperLeft: Could not deserialize raster");
325 PG_FREE_IF_COPY(pgraster, 0);
327 PG_RETURN_FLOAT8(xul);
340 if (PG_ARGISNULL(0)) PG_RETURN_NULL();
345 PG_FREE_IF_COPY(pgraster, 0);
346 elog(ERROR,
"RASTER_getYUpperLeft: Could not deserialize raster");
353 PG_FREE_IF_COPY(pgraster, 0);
355 PG_RETURN_FLOAT8(yul);
374 if (PG_ARGISNULL(0)) PG_RETURN_NULL();
379 PG_FREE_IF_COPY(pgraster, 0);
380 elog(ERROR,
"RASTER_getPixelWidth: Could not deserialize raster");
386 pwidth = sqrt(xscale*xscale + yskew*yskew);
389 PG_FREE_IF_COPY(pgraster, 0);
391 PG_RETURN_FLOAT8(pwidth);
410 if (PG_ARGISNULL(0)) PG_RETURN_NULL();
415 PG_FREE_IF_COPY(pgraster, 0);
416 elog(ERROR,
"RASTER_getPixelHeight: Could not deserialize raster");
422 pheight = sqrt(yscale*yscale + xskew*xskew);
425 PG_FREE_IF_COPY(pgraster, 0);
427 PG_RETURN_FLOAT8(pheight);
430 #define VALUES_LENGTH 6 451 TupleDesc result_tuple;
454 HeapTuple heap_tuple ;
467 PG_FREE_IF_COPY(pgraster, 0);
468 elog(ERROR,
"RASTER_getGeotransform: Could not deserialize raster");
478 &imag, &jmag, &theta_i, &theta_ij) ;
481 PG_FREE_IF_COPY(pgraster, 0);
484 if (get_call_result_type(fcinfo, NULL, &result_tuple) != TYPEFUNC_COMPOSITE) {
486 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
487 errmsg(
"RASTER_getGeotransform(): function returning record called in context that cannot accept type record" 493 BlessTupleDesc(result_tuple);
498 values[0] = Float8GetDatum(imag);
499 values[1] = Float8GetDatum(jmag);
500 values[2] = Float8GetDatum(theta_i);
501 values[3] = Float8GetDatum(theta_ij);
508 heap_tuple = heap_form_tuple(result_tuple, values, nulls);
511 result = HeapTupleGetDatum(heap_tuple);
513 PG_RETURN_DATUM(result);
524 bool isempty =
FALSE;
527 if (PG_ARGISNULL(0)) PG_RETURN_NULL();
534 (errcode(ERRCODE_OUT_OF_MEMORY),
535 errmsg(
"RASTER_isEmpty: Could not deserialize raster")));
536 PG_FREE_IF_COPY(pgraster, 0);
543 PG_FREE_IF_COPY(pgraster, 0);
545 PG_RETURN_BOOL(isempty);
557 bool hasnoband =
FALSE;
560 if (PG_ARGISNULL(0)) PG_RETURN_NULL();
567 (errcode(ERRCODE_OUT_OF_MEMORY),
568 errmsg(
"RASTER_hasNoBand: Could not deserialize raster")));
569 PG_FREE_IF_COPY(pgraster, 0);
574 bandindex = PG_GETARG_INT32(1);
578 PG_FREE_IF_COPY(pgraster, 0);
580 PG_RETURN_BOOL(hasnoband);
584 #define VALUES_LENGTH 10 622 PG_FREE_IF_COPY(pgraster, 0);
623 elog(ERROR,
"RASTER_metadata; Could not deserialize raster");
650 PG_FREE_IF_COPY(pgraster, 0);
653 if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE) {
655 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
657 "function returning record called in context " 658 "that cannot accept type record" 663 BlessTupleDesc(tupdesc);
665 values[0] = Float8GetDatum(ipX);
666 values[1] = Float8GetDatum(ipY);
667 values[2] = UInt32GetDatum(width);
668 values[3] = UInt32GetDatum(height);
669 values[4] = Float8GetDatum(scaleX);
670 values[5] = Float8GetDatum(scaleY);
671 values[6] = Float8GetDatum(skewX);
672 values[7] = Float8GetDatum(skewY);
673 values[8] = Int32GetDatum(srid);
674 values[9] = UInt32GetDatum(numBands);
679 tuple = heap_form_tuple(tupdesc, values, nulls);
682 result = HeapTupleGetDatum(tuple);
684 PG_RETURN_DATUM(result);
688 #define VALUES_LENGTH 2 697 bool skewed[2] = {
false,
false};
716 PG_FREE_IF_COPY(pgraster, 0);
717 elog(ERROR,
"RASTER_rasterToWorldCoord: Could not deserialize raster");
726 for (i = 1; i <= 2; i++) {
727 if (PG_ARGISNULL(i)) {
730 elog(NOTICE,
"Pixel row and column required for computing longitude and latitude of a rotated raster");
732 PG_FREE_IF_COPY(pgraster, 0);
739 cr[i - 1] = PG_GETARG_INT32(i);
745 (
double) cr[0] - 1, (
double) cr[1] - 1,
750 PG_FREE_IF_COPY(pgraster, 0);
751 elog(ERROR,
"RASTER_rasterToWorldCoord: Could not compute longitude and latitude from pixel row and column");
755 PG_FREE_IF_COPY(pgraster, 0);
758 if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE) {
760 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
762 "function returning record called in context " 763 "that cannot accept type record" 768 BlessTupleDesc(tupdesc);
770 values[0] = Float8GetDatum(cw[0]);
771 values[1] = Float8GetDatum(cw[1]);
776 tuple = heap_form_tuple(tupdesc, values, nulls);
779 result = HeapTupleGetDatum(tuple);
781 PG_RETURN_DATUM(result);
811 PG_FREE_IF_COPY(pgraster, 0);
812 elog(ERROR,
"RASTER_worldToRasterCoord: Could not deserialize raster");
822 for (i = 1; i <= 2; i++) {
823 if (PG_ARGISNULL(i)) {
826 elog(NOTICE,
"Latitude and longitude required for computing pixel row and column of a rotated raster");
828 PG_FREE_IF_COPY(pgraster, 0);
835 cw[i - 1] = PG_GETARG_FLOAT8(i);
842 &(_cr[0]), &(_cr[1]),
846 PG_FREE_IF_COPY(pgraster, 0);
847 elog(ERROR,
"RASTER_worldToRasterCoord: Could not compute pixel row and column from longitude and latitude");
851 PG_FREE_IF_COPY(pgraster, 0);
854 cr[0] = ((int) _cr[0]) + 1;
855 cr[1] = ((int) _cr[1]) + 1;
858 if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE) {
860 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
862 "function returning record called in context " 863 "that cannot accept type record" 868 BlessTupleDesc(tupdesc);
870 values[0] = Int32GetDatum(cr[0]);
871 values[1] = Int32GetDatum(cr[1]);
876 tuple = heap_form_tuple(tupdesc, values, nulls);
879 result = HeapTupleGetDatum(tuple);
881 PG_RETURN_DATUM(result);
893 int32_t newSRID = PG_GETARG_INT32(1);
895 if (PG_ARGISNULL(0)) PG_RETURN_NULL();
896 pgraster = (
rt_pgraster *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
900 PG_FREE_IF_COPY(pgraster, 0);
901 elog(ERROR,
"RASTER_setSRID: Could not deserialize raster");
909 PG_FREE_IF_COPY(pgraster, 0);
910 if (!pgrtn) PG_RETURN_NULL();
912 SET_VARSIZE(pgrtn, pgrtn->
size);
914 PG_RETURN_POINTER(pgrtn);
926 double size = PG_GETARG_FLOAT8(1);
930 pgraster = (
rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
933 PG_FREE_IF_COPY(pgraster, 0);
934 elog(ERROR,
"RASTER_setScale: Could not deserialize raster");
942 PG_FREE_IF_COPY(pgraster, 0);
946 SET_VARSIZE(pgrtn, pgrtn->
size);
947 PG_RETURN_POINTER(pgrtn);
959 double xscale = PG_GETARG_FLOAT8(1);
960 double yscale = PG_GETARG_FLOAT8(2);
964 pgraster = (
rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
967 PG_FREE_IF_COPY(pgraster, 0);
968 elog(ERROR,
"RASTER_setScaleXY: Could not deserialize raster");
975 PG_FREE_IF_COPY(pgraster, 0);
979 SET_VARSIZE(pgrtn, pgrtn->
size);
980 PG_RETURN_POINTER(pgrtn);
992 double skew = PG_GETARG_FLOAT8(1);
996 pgraster = (
rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
999 PG_FREE_IF_COPY(pgraster, 0);
1000 elog(ERROR,
"RASTER_setSkew: Could not deserialize raster");
1008 PG_FREE_IF_COPY(pgraster, 0);
1012 SET_VARSIZE(pgrtn, pgrtn->
size);
1013 PG_RETURN_POINTER(pgrtn);
1025 double xskew = PG_GETARG_FLOAT8(1);
1026 double yskew = PG_GETARG_FLOAT8(2);
1028 if (PG_ARGISNULL(0))
1030 pgraster = (
rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
1033 PG_FREE_IF_COPY(pgraster, 0);
1034 elog(ERROR,
"RASTER_setSkewXY: Could not deserialize raster");
1042 PG_FREE_IF_COPY(pgraster, 0);
1046 SET_VARSIZE(pgrtn, pgrtn->
size);
1047 PG_RETURN_POINTER(pgrtn);
1059 double xoffset = PG_GETARG_FLOAT8(1);
1060 double yoffset = PG_GETARG_FLOAT8(2);
1062 if (PG_ARGISNULL(0))
1064 pgraster = (
rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
1067 PG_FREE_IF_COPY(pgraster, 0);
1068 elog(ERROR,
"RASTER_setUpperLeftXY: Could not deserialize raster");
1076 PG_FREE_IF_COPY(pgraster, 0);
1080 SET_VARSIZE(pgrtn, pgrtn->
size);
1081 PG_RETURN_POINTER(pgrtn);
1093 float8 imag, jmag, theta_i, theta_ij, xoffset, yoffset;
1096 PG_ARGISNULL(0) || PG_ARGISNULL(1) || PG_ARGISNULL(2) ||
1097 PG_ARGISNULL(3) || PG_ARGISNULL(4) ||
1098 PG_ARGISNULL(5) || PG_ARGISNULL(6)
1104 pgraster = (
rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
1105 imag = PG_GETARG_FLOAT8(1);
1106 jmag = PG_GETARG_FLOAT8(2);
1107 theta_i = PG_GETARG_FLOAT8(3);
1108 theta_ij = PG_GETARG_FLOAT8(4);
1109 xoffset = PG_GETARG_FLOAT8(5);
1110 yoffset = PG_GETARG_FLOAT8(6);
1114 PG_FREE_IF_COPY(pgraster, 0);
1115 elog(ERROR,
"RASTER_setGeotransform: Could not deserialize raster");
1126 PG_FREE_IF_COPY(pgraster, 0);
1130 SET_VARSIZE(pgrtn, pgrtn->
size);
1131 PG_RETURN_POINTER(pgrtn);
1151 double rotation = PG_GETARG_FLOAT8(1);
1152 double imag, jmag, theta_i, theta_ij;
1154 if (PG_ARGISNULL(0))
1156 pgraster = (
rt_pgraster *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
1160 PG_FREE_IF_COPY(pgraster, 0);
1161 elog(ERROR,
"RASTER_setRotation: Could not deserialize raster");
1171 PG_FREE_IF_COPY(pgraster, 0);
1175 SET_VARSIZE(pgrtn, pgrtn->
size);
1176 PG_RETURN_POINTER(pgrtn);
Datum RASTER_setUpperLeftXY(PG_FUNCTION_ARGS)
void * rt_raster_serialize(rt_raster raster)
Return this raster in serialized form.
double rt_raster_get_x_offset(rt_raster raster)
Get raster x offset, in projection units.
int rt_raster_get_num_bands(rt_raster raster)
double rt_raster_get_y_skew(rt_raster raster)
Get skew about the Y axis.
Datum RASTER_getYScale(PG_FUNCTION_ARGS)
Datum RASTER_setScale(PG_FUNCTION_ARGS)
Datum RASTER_getYUpperLeft(PG_FUNCTION_ARGS)
raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
Datum RASTER_getSRID(PG_FUNCTION_ARGS)
void rt_raster_set_skews(rt_raster raster, double skewX, double skewY)
Set skews about the X and Y axis.
Datum RASTER_getYSkew(PG_FUNCTION_ARGS)
Datum RASTER_metadata(PG_FUNCTION_ARGS)
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...
Datum RASTER_isEmpty(PG_FUNCTION_ARGS)
Datum RASTER_setSRID(PG_FUNCTION_ARGS)
Datum RASTER_getHeight(PG_FUNCTION_ARGS)
Datum RASTER_setGeotransform(PG_FUNCTION_ARGS)
Datum RASTER_getXSkew(PG_FUNCTION_ARGS)
Datum RASTER_setRotation(PG_FUNCTION_ARGS)
int rt_raster_is_empty(rt_raster raster)
Return TRUE if the raster is empty.
Datum RASTER_getWidth(PG_FUNCTION_ARGS)
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.
Datum RASTER_getPixelWidth(PG_FUNCTION_ARGS)
PG_FUNCTION_INFO_V1(RASTER_getSRID)
Return the SRID associated with the raster.
Datum RASTER_getNumBands(PG_FUNCTION_ARGS)
void rt_raster_set_scale(rt_raster raster, double scaleX, double scaleY)
Set scale in projection units.
void rt_raster_set_offsets(rt_raster raster, double x, double y)
Set insertion points in projection units.
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. ...
Datum RASTER_setSkewXY(PG_FUNCTION_ARGS)
double rt_raster_get_x_scale(rt_raster raster)
Get scale X in projection units.
Datum RASTER_getXScale(PG_FUNCTION_ARGS)
int rt_raster_has_band(rt_raster raster, int nband)
Return TRUE if the raster has a band of this number.
Datum RASTER_setSkew(PG_FUNCTION_ARGS)
Datum RASTER_getXUpperLeft(PG_FUNCTION_ARGS)
void rt_raster_set_srid(rt_raster raster, int32_t srid)
Set raster's SRID.
int32_t rt_raster_get_srid(rt_raster raster)
Get raster's SRID.
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
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.
double rt_raster_get_y_scale(rt_raster raster)
Get scale Y in projection units.
double rt_raster_get_x_skew(rt_raster raster)
Get skew about the X axis.
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.
uint16_t rt_raster_get_width(rt_raster raster)
Datum RASTER_worldToRasterCoord(PG_FUNCTION_ARGS)
Datum RASTER_getPixelHeight(PG_FUNCTION_ARGS)
Datum RASTER_setScaleXY(PG_FUNCTION_ARGS)
uint16_t rt_raster_get_height(rt_raster raster)
#define POSTGIS_RT_DEBUG(level, msg)
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.
Datum RASTER_rasterToWorldCoord(PG_FUNCTION_ARGS)
double rt_raster_get_y_offset(rt_raster raster)
Get raster y offset, in projection units.
Datum RASTER_getGeotransform(PG_FUNCTION_ARGS)
Datum RASTER_hasNoBand(PG_FUNCTION_ARGS)