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

Definition at line 13108 of file rt_pg.c.

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

13109 {
13110  rt_pgraster *pgraster = NULL;
13111  rt_raster raster = NULL;
13112  int i = 0;
13113  int cr[2] = {0};
13114  bool skewed[2] = {false, false};
13115  double cw[2] = {0};
13116 
13117  TupleDesc tupdesc;
13118  int values_length = 2;
13119  Datum values[values_length];
13120  bool nulls[values_length];
13121  HeapTuple tuple;
13122  Datum result;
13123 
13124  POSTGIS_RT_DEBUG(3, "RASTER_rasterToWorldCoord: Starting");
13125 
13126  /* pgraster is null, return null */
13127  if (PG_ARGISNULL(0))
13128  PG_RETURN_NULL();
13129  pgraster = (rt_pgraster *) PG_DETOAST_DATUM_SLICE(PG_GETARG_DATUM(0), 0, sizeof(struct rt_raster_serialized_t));
13130 
13131  /* raster */
13132  raster = rt_raster_deserialize(pgraster, TRUE);
13133  if (!raster) {
13134  PG_FREE_IF_COPY(pgraster, 0);
13135  elog(ERROR, "RASTER_rasterToWorldCoord: Could not deserialize raster");
13136  PG_RETURN_NULL();
13137  }
13138 
13139  /* raster skewed? */
13140  skewed[0] = FLT_NEQ(rt_raster_get_x_skew(raster), 0) ? true : false;
13141  skewed[1] = FLT_NEQ(rt_raster_get_y_skew(raster), 0) ? true : false;
13142 
13143  /* column and row */
13144  for (i = 1; i <= 2; i++) {
13145  if (PG_ARGISNULL(i)) {
13146  /* if skewed on same axis, parameter is required */
13147  if (skewed[i - 1]) {
13148  elog(NOTICE, "Pixel row and column required for computing longitude and latitude of a rotated raster");
13149  rt_raster_destroy(raster);
13150  PG_FREE_IF_COPY(pgraster, 0);
13151  PG_RETURN_NULL();
13152  }
13153 
13154  continue;
13155  }
13156 
13157  cr[i - 1] = PG_GETARG_INT32(i);
13158  }
13159 
13160  /* user-provided value is 1-based but needs to be 0-based */
13162  raster,
13163  (double) cr[0] - 1, (double) cr[1] - 1,
13164  &(cw[0]), &(cw[1]),
13165  NULL
13166  ) != ES_NONE) {
13167  rt_raster_destroy(raster);
13168  PG_FREE_IF_COPY(pgraster, 0);
13169  elog(ERROR, "RASTER_rasterToWorldCoord: Could not compute longitude and latitude from pixel row and column");
13170  PG_RETURN_NULL();
13171  }
13172  rt_raster_destroy(raster);
13173  PG_FREE_IF_COPY(pgraster, 0);
13174 
13175  /* Build a tuple descriptor for our result type */
13176  if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE) {
13177  ereport(ERROR, (
13178  errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
13179  errmsg(
13180  "function returning record called in context "
13181  "that cannot accept type record"
13182  )
13183  ));
13184  }
13185 
13186  BlessTupleDesc(tupdesc);
13187 
13188  values[0] = Float8GetDatum(cw[0]);
13189  values[1] = Float8GetDatum(cw[1]);
13190 
13191  memset(nulls, FALSE, sizeof(bool) * values_length);
13192 
13193  /* build a tuple */
13194  tuple = heap_form_tuple(tupdesc, values, nulls);
13195 
13196  /* make the tuple into a datum */
13197  result = HeapTupleGetDatum(tuple);
13198 
13199  PG_RETURN_DATUM(result);
13200 }
#define FLT_NEQ(x, y)
Definition: rt_api.h:2158
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
Definition: rt_api.c:5387
double rt_raster_get_x_skew(rt_raster raster)
Get skew about the X axis.
Definition: rt_api.c:5486
double rt_raster_get_y_skew(rt_raster raster)
Get skew about the Y axis.
Definition: rt_api.c:5495
tuple raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
Definition: rtrowdump.py:123
char ** result
Definition: liblwgeom.h:218
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_api.c:6054
#define POSTGIS_RT_DEBUG(level, msg)
Definition: rt_pg.h:58
#define FALSE
Definition: dbfopen.c:169
Struct definitions.
Definition: rt_api.h:2175
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.
Definition: rt_api.c:8350
#define TRUE
Definition: dbfopen.c:170

Here is the call graph for this function: