PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ RASTER_worldToRasterCoord()

Datum RASTER_worldToRasterCoord ( PG_FUNCTION_ARGS  )

Definition at line 785 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().

786 {
787  rt_pgraster *pgraster = NULL;
788  rt_raster raster = NULL;
789  int i = 0;
790  double cw[2] = {0};
791  double _cr[2] = {0};
792  int cr[2] = {0};
793  bool skewed = false;
794 
795  TupleDesc tupdesc;
796  Datum values[VALUES_LENGTH];
797  bool nulls[VALUES_LENGTH];
798  HeapTuple tuple;
799  Datum result;
800 
801  POSTGIS_RT_DEBUG(3, "RASTER_worldToRasterCoord: Starting");
802 
803  /* pgraster is null, return null */
804  if (PG_ARGISNULL(0))
805  PG_RETURN_NULL();
806  pgraster = (rt_pgraster *) PG_DETOAST_DATUM_SLICE(PG_GETARG_DATUM(0), 0, sizeof(struct rt_raster_serialized_t));
807 
808  /* raster */
809  raster = rt_raster_deserialize(pgraster, TRUE);
810  if (!raster) {
811  PG_FREE_IF_COPY(pgraster, 0);
812  elog(ERROR, "RASTER_worldToRasterCoord: Could not deserialize raster");
813  PG_RETURN_NULL();
814  }
815 
816  /* raster skewed? */
817  skewed = FLT_NEQ(rt_raster_get_x_skew(raster), 0) ? true : false;
818  if (!skewed)
819  skewed = FLT_NEQ(rt_raster_get_y_skew(raster), 0) ? true : false;
820 
821  /* longitude and latitude */
822  for (i = 1; i <= 2; i++) {
823  if (PG_ARGISNULL(i)) {
824  /* if skewed, parameter is required */
825  if (skewed) {
826  elog(NOTICE, "Latitude and longitude required for computing pixel row and column of a rotated raster");
827  rt_raster_destroy(raster);
828  PG_FREE_IF_COPY(pgraster, 0);
829  PG_RETURN_NULL();
830  }
831 
832  continue;
833  }
834 
835  cw[i - 1] = PG_GETARG_FLOAT8(i);
836  }
837 
838  /* return pixel row and column values are 0-based */
840  raster,
841  cw[0], cw[1],
842  &(_cr[0]), &(_cr[1]),
843  NULL
844  ) != ES_NONE) {
845  rt_raster_destroy(raster);
846  PG_FREE_IF_COPY(pgraster, 0);
847  elog(ERROR, "RASTER_worldToRasterCoord: Could not compute pixel row and column from longitude and latitude");
848  PG_RETURN_NULL();
849  }
850  rt_raster_destroy(raster);
851  PG_FREE_IF_COPY(pgraster, 0);
852 
853  /* force to integer and add one to make 1-based */
854  cr[0] = ((int) _cr[0]) + 1;
855  cr[1] = ((int) _cr[1]) + 1;
856 
857  /* Build a tuple descriptor for our result type */
858  if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE) {
859  ereport(ERROR, (
860  errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
861  errmsg(
862  "function returning record called in context "
863  "that cannot accept type record"
864  )
865  ));
866  }
867 
868  BlessTupleDesc(tupdesc);
869 
870  values[0] = Int32GetDatum(cr[0]);
871  values[1] = Int32GetDatum(cr[1]);
872 
873  memset(nulls, FALSE, sizeof(bool) * VALUES_LENGTH);
874 
875  /* build a tuple */
876  tuple = heap_form_tuple(tupdesc, values, nulls);
877 
878  /* make the tuple into a datum */
879  result = HeapTupleGetDatum(tuple);
880 
881  PG_RETURN_DATUM(result);
882 }
#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:2184
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:2201
#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:717
Here is the call graph for this function:
Here is the caller graph for this function: