PostGIS  2.5.0beta2dev-r@@SVN_REVISION@@

◆ RASTER_rasterToWorldCoord()

Datum RASTER_rasterToWorldCoord ( PG_FUNCTION_ARGS  )

Definition at line 687 of file rtpg_raster_properties.c.

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

Referenced by RASTER_metadata().

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