PostGIS  2.5.1dev-r@@SVN_REVISION@@

◆ RASTER_worldToRasterCoord()

Datum RASTER_worldToRasterCoord ( PG_FUNCTION_ARGS  )

Definition at line 787 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(), TRUE, and VALUES_LENGTH.

Referenced by RASTER_rasterToWorldCoord().

788 {
789  rt_pgraster *pgraster = NULL;
790  rt_raster raster = NULL;
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;
798  Datum values[VALUES_LENGTH];
799  bool nulls[VALUES_LENGTH];
800  HeapTuple tuple;
801  Datum result;
802 
803  POSTGIS_RT_DEBUG(3, "RASTER_worldToRasterCoord: Starting");
804 
805  /* pgraster is null, return null */
806  if (PG_ARGISNULL(0))
807  PG_RETURN_NULL();
808  pgraster = (rt_pgraster *) PG_DETOAST_DATUM_SLICE(PG_GETARG_DATUM(0), 0, sizeof(struct rt_raster_serialized_t));
809 
810  /* raster */
811  raster = rt_raster_deserialize(pgraster, TRUE);
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  /* raster skewed? */
819  skewed = FLT_NEQ(rt_raster_get_x_skew(raster), 0) ? true : false;
820  if (!skewed)
821  skewed = FLT_NEQ(rt_raster_get_y_skew(raster), 0) ? true : false;
822 
823  /* longitude and latitude */
824  for (i = 1; i <= 2; i++) {
825  if (PG_ARGISNULL(i)) {
826  /* if skewed, parameter is required */
827  if (skewed) {
828  elog(NOTICE, "Latitude and longitude required for computing pixel row and column of a rotated raster");
829  rt_raster_destroy(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  /* return pixel row and column values are 0-based */
842  raster,
843  cw[0], cw[1],
844  &(_cr[0]), &(_cr[1]),
845  NULL
846  ) != ES_NONE) {
847  rt_raster_destroy(raster);
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  }
852  rt_raster_destroy(raster);
853  PG_FREE_IF_COPY(pgraster, 0);
854 
855  /* force to integer and add one to make 1-based */
856  cr[0] = ((int) _cr[0]) + 1;
857  cr[1] = ((int) _cr[1]) + 1;
858 
859  /* Build a tuple descriptor for our result type */
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 
875  memset(nulls, FALSE, sizeof(bool) * VALUES_LENGTH);
876 
877  /* build a tuple */
878  tuple = heap_form_tuple(tupdesc, values, nulls);
879 
880  /* make the tuple into a datum */
881  result = HeapTupleGetDatum(tuple);
882 
883  PG_RETURN_DATUM(result);
884 }
#define VALUES_LENGTH
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:2233
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:2250
#define POSTGIS_RT_DEBUG(level, msg)
Definition: rtpostgis.h:61
#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:725
Here is the call graph for this function:
Here is the caller graph for this function: