PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ RASTER_worldToRasterCoord()

Datum RASTER_worldToRasterCoord ( PG_FUNCTION_ARGS  )

Definition at line 780 of file rtpg_raster_properties.c.

References ES_NONE, FALSE, FLT_NEQ, PG_FUNCTION_INFO_V1(), POSTGIS_RT_DEBUG, rtrowdump::raster, RASTER_setSRID(), rt_raster_deserialize(), rt_raster_destroy(), rt_raster_geopoint_to_cell(), rt_raster_get_x_skew(), rt_raster_get_y_skew(), and TRUE.

Referenced by RASTER_rasterToWorldCoord().

781 {
782  rt_pgraster *pgraster = NULL;
783  rt_raster raster = NULL;
784  int i = 0;
785  double cw[2] = {0};
786  double _cr[2] = {0};
787  int cr[2] = {0};
788  bool skewed = false;
789 
790  TupleDesc tupdesc;
791  int values_length = 2;
792  Datum values[values_length];
793  bool nulls[values_length];
794  HeapTuple tuple;
795  Datum result;
796 
797  POSTGIS_RT_DEBUG(3, "RASTER_worldToRasterCoord: Starting");
798 
799  /* pgraster is null, return null */
800  if (PG_ARGISNULL(0))
801  PG_RETURN_NULL();
802  pgraster = (rt_pgraster *) PG_DETOAST_DATUM_SLICE(PG_GETARG_DATUM(0), 0, sizeof(struct rt_raster_serialized_t));
803 
804  /* raster */
805  raster = rt_raster_deserialize(pgraster, TRUE);
806  if (!raster) {
807  PG_FREE_IF_COPY(pgraster, 0);
808  elog(ERROR, "RASTER_worldToRasterCoord: Could not deserialize raster");
809  PG_RETURN_NULL();
810  }
811 
812  /* raster skewed? */
813  skewed = FLT_NEQ(rt_raster_get_x_skew(raster), 0) ? true : false;
814  if (!skewed)
815  skewed = FLT_NEQ(rt_raster_get_y_skew(raster), 0) ? true : false;
816 
817  /* longitude and latitude */
818  for (i = 1; i <= 2; i++) {
819  if (PG_ARGISNULL(i)) {
820  /* if skewed, parameter is required */
821  if (skewed) {
822  elog(NOTICE, "Latitude and longitude required for computing pixel row and column of a rotated raster");
823  rt_raster_destroy(raster);
824  PG_FREE_IF_COPY(pgraster, 0);
825  PG_RETURN_NULL();
826  }
827 
828  continue;
829  }
830 
831  cw[i - 1] = PG_GETARG_FLOAT8(i);
832  }
833 
834  /* return pixel row and column values are 0-based */
836  raster,
837  cw[0], cw[1],
838  &(_cr[0]), &(_cr[1]),
839  NULL
840  ) != ES_NONE) {
841  rt_raster_destroy(raster);
842  PG_FREE_IF_COPY(pgraster, 0);
843  elog(ERROR, "RASTER_worldToRasterCoord: Could not compute pixel row and column from longitude and latitude");
844  PG_RETURN_NULL();
845  }
846  rt_raster_destroy(raster);
847  PG_FREE_IF_COPY(pgraster, 0);
848 
849  /* force to integer and add one to make 1-based */
850  cr[0] = ((int) _cr[0]) + 1;
851  cr[1] = ((int) _cr[1]) + 1;
852 
853  /* Build a tuple descriptor for our result type */
854  if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE) {
855  ereport(ERROR, (
856  errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
857  errmsg(
858  "function returning record called in context "
859  "that cannot accept type record"
860  )
861  ));
862  }
863 
864  BlessTupleDesc(tupdesc);
865 
866  values[0] = Int32GetDatum(cr[0]);
867  values[1] = Int32GetDatum(cr[1]);
868 
869  memset(nulls, FALSE, sizeof(bool) * values_length);
870 
871  /* build a tuple */
872  tuple = heap_form_tuple(tupdesc, values, nulls);
873 
874  /* make the tuple into a datum */
875  result = HeapTupleGetDatum(tuple);
876 
877  PG_RETURN_DATUM(result);
878 }
double rt_raster_get_y_skew(rt_raster raster)
Get skew about the Y axis.
Definition: rt_raster.c:190
raster
Be careful!! Zeros function&#39;s input parameter can be a (height x width) array, not (width x height): ...
Definition: rtrowdump.py:121
#define FLT_NEQ(x, y)
Definition: librtcore.h:2196
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
Definition: rt_raster.c:82
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.
Definition: rt_raster.c:806
double rt_raster_get_x_skew(rt_raster raster)
Get skew about the X axis.
Definition: rt_raster.c:181
#define FALSE
Definition: dbfopen.c:168
Struct definitions.
Definition: librtcore.h:2213
#define POSTGIS_RT_DEBUG(level, msg)
Definition: rtpostgis.h:53
#define TRUE
Definition: dbfopen.c:169
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.
Definition: rt_serialize.c:717
Here is the call graph for this function:
Here is the caller graph for this function: