PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ RASTER_rasterToWorldCoord()

Datum RASTER_rasterToWorldCoord ( PG_FUNCTION_ARGS  )

Definition at line 693 of file rtpg_raster_properties.c.

694 {
695  rt_pgraster *pgraster = NULL;
696  rt_raster raster = NULL;
697  int i = 0;
698  int cr[2] = {0};
699  bool skewed[2] = {false, false};
700  double cw[2] = {0};
701 
702  TupleDesc tupdesc;
703  Datum values[VALUES_LENGTH];
704  bool nulls[VALUES_LENGTH];
705  HeapTuple tuple;
706  Datum result;
707 
708  POSTGIS_RT_DEBUG(3, "RASTER_rasterToWorldCoord: Starting");
709 
710  /* pgraster is null, return null */
711  if (PG_ARGISNULL(0))
712  PG_RETURN_NULL();
713  pgraster = (rt_pgraster *) PG_DETOAST_DATUM_SLICE(PG_GETARG_DATUM(0), 0, sizeof(struct rt_raster_serialized_t));
714 
715  /* raster */
716  raster = rt_raster_deserialize(pgraster, TRUE);
717  if (!raster) {
718  PG_FREE_IF_COPY(pgraster, 0);
719  elog(ERROR, "RASTER_rasterToWorldCoord: Could not deserialize raster");
720  PG_RETURN_NULL();
721  }
722 
723  /* raster skewed? */
724  skewed[0] = FLT_NEQ(rt_raster_get_x_skew(raster), 0) ? true : false;
725  skewed[1] = FLT_NEQ(rt_raster_get_y_skew(raster), 0) ? true : false;
726 
727  /* column and row */
728  for (i = 1; i <= 2; i++) {
729  if (PG_ARGISNULL(i)) {
730  /* if skewed on same axis, parameter is required */
731  if (skewed[i - 1]) {
732  elog(NOTICE, "Pixel row and column required for computing longitude and latitude of a rotated raster");
734  PG_FREE_IF_COPY(pgraster, 0);
735  PG_RETURN_NULL();
736  }
737 
738  continue;
739  }
740 
741  cr[i - 1] = PG_GETARG_INT32(i);
742  }
743 
744  /* user-provided value is 1-based but needs to be 0-based */
746  raster,
747  (double) cr[0] - 1, (double) cr[1] - 1,
748  &(cw[0]), &(cw[1]),
749  NULL
750  ) != ES_NONE) {
752  PG_FREE_IF_COPY(pgraster, 0);
753  elog(ERROR, "RASTER_rasterToWorldCoord: Could not compute longitude and latitude from pixel row and column");
754  PG_RETURN_NULL();
755  }
757  PG_FREE_IF_COPY(pgraster, 0);
758 
759  /* Build a tuple descriptor for our result type */
760  if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE) {
761  ereport(ERROR, (
762  errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
763  errmsg(
764  "function returning record called in context "
765  "that cannot accept type record"
766  )
767  ));
768  }
769 
770  BlessTupleDesc(tupdesc);
771 
772  values[0] = Float8GetDatum(cw[0]);
773  values[1] = Float8GetDatum(cw[1]);
774 
775  memset(nulls, FALSE, sizeof(bool) * VALUES_LENGTH);
776 
777  /* build a tuple */
778  tuple = heap_form_tuple(tupdesc, values, nulls);
779 
780  /* make the tuple into a datum */
781  result = HeapTupleGetDatum(tuple);
782 
783  PG_RETURN_DATUM(result);
784 }
#define TRUE
Definition: dbfopen.c:169
#define FALSE
Definition: dbfopen.c:168
#define FLT_NEQ(x, y)
Definition: librtcore.h:2233
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.
Definition: rt_raster.c:755
double rt_raster_get_x_skew(rt_raster raster)
Get skew about the X axis.
Definition: rt_raster.c:181
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
Definition: rt_raster.c:82
@ ES_NONE
Definition: librtcore.h:180
double rt_raster_get_y_skew(rt_raster raster)
Get skew about the Y axis.
Definition: rt_raster.c:190
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.
Definition: rt_serialize.c:725
raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
Definition: rtrowdump.py:121
#define VALUES_LENGTH
#define POSTGIS_RT_DEBUG(level, msg)
Definition: rtpostgis.h:61
Struct definitions.
Definition: librtcore.h:2250

References ES_NONE, FALSE, FLT_NEQ, POSTGIS_RT_DEBUG, rtrowdump::raster, rt_raster_cell_to_geopoint(), rt_raster_deserialize(), rt_raster_destroy(), rt_raster_get_x_skew(), rt_raster_get_y_skew(), TRUE, and VALUES_LENGTH.

Here is the call graph for this function: