PostGIS  2.2.7dev-r@@SVN_REVISION@@
Datum RASTER_rasterToWorldCoord ( PG_FUNCTION_ARGS  )

Definition at line 685 of file rtpg_raster_properties.c.

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(), and TRUE.

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