PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ RASTER_rasterToWorldCoord()

Datum RASTER_rasterToWorldCoord ( PG_FUNCTION_ARGS  )

Definition at line 691 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(), TRUE, and VALUES_LENGTH.

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