PostGIS  2.5.0beta2dev-r@@SVN_REVISION@@

◆ RASTER_worldToRasterCoord()

Datum RASTER_worldToRasterCoord ( PG_FUNCTION_ARGS  )

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

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