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

Definition at line 12746 of file rt_pg.c.

References FALSE, POSTGIS_RT_DEBUG, rtrowdump::raster, result, rt_raster_deserialize(), rt_raster_destroy(), rt_raster_get_height(), rt_raster_get_num_bands(), rt_raster_get_srid(), rt_raster_get_width(), rt_raster_get_x_offset(), rt_raster_get_x_scale(), rt_raster_get_x_skew(), rt_raster_get_y_offset(), rt_raster_get_y_scale(), rt_raster_get_y_skew(), and TRUE.

12747 {
12748  rt_pgraster *pgraster = NULL;
12749  rt_raster raster = NULL;
12750 
12751  uint32_t numBands;
12752  double scaleX;
12753  double scaleY;
12754  double ipX;
12755  double ipY;
12756  double skewX;
12757  double skewY;
12758  int32_t srid;
12759  uint32_t width;
12760  uint32_t height;
12761 
12762  TupleDesc tupdesc;
12763  int values_length = 10;
12764  Datum values[values_length];
12765  bool nulls[values_length];
12766  HeapTuple tuple;
12767  Datum result;
12768 
12769  POSTGIS_RT_DEBUG(3, "RASTER_metadata: Starting");
12770 
12771  /* pgraster is null, return null */
12772  if (PG_ARGISNULL(0))
12773  PG_RETURN_NULL();
12774  pgraster = (rt_pgraster *) PG_DETOAST_DATUM_SLICE(PG_GETARG_DATUM(0), 0, sizeof(struct rt_raster_serialized_t));
12775 
12776  /* raster */
12777  raster = rt_raster_deserialize(pgraster, TRUE);
12778  if (!raster) {
12779  PG_FREE_IF_COPY(pgraster, 0);
12780  elog(ERROR, "RASTER_metadata; Could not deserialize raster");
12781  PG_RETURN_NULL();
12782  }
12783 
12784  /* upper left x, y */
12785  ipX = rt_raster_get_x_offset(raster);
12786  ipY = rt_raster_get_y_offset(raster);
12787 
12788  /* width, height */
12789  width = rt_raster_get_width(raster);
12790  height = rt_raster_get_height(raster);
12791 
12792  /* scale x, y */
12793  scaleX = rt_raster_get_x_scale(raster);
12794  scaleY = rt_raster_get_y_scale(raster);
12795 
12796  /* skew x, y */
12797  skewX = rt_raster_get_x_skew(raster);
12798  skewY = rt_raster_get_y_skew(raster);
12799 
12800  /* srid */
12801  srid = rt_raster_get_srid(raster);
12802 
12803  /* numbands */
12804  numBands = rt_raster_get_num_bands(raster);
12805 
12806  rt_raster_destroy(raster);
12807  PG_FREE_IF_COPY(pgraster, 0);
12808 
12809  /* Build a tuple descriptor for our result type */
12810  if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE) {
12811  ereport(ERROR, (
12812  errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
12813  errmsg(
12814  "function returning record called in context "
12815  "that cannot accept type record"
12816  )
12817  ));
12818  }
12819 
12820  BlessTupleDesc(tupdesc);
12821 
12822  values[0] = Float8GetDatum(ipX);
12823  values[1] = Float8GetDatum(ipY);
12824  values[2] = UInt32GetDatum(width);
12825  values[3] = UInt32GetDatum(height);
12826  values[4] = Float8GetDatum(scaleX);
12827  values[5] = Float8GetDatum(scaleY);
12828  values[6] = Float8GetDatum(skewX);
12829  values[7] = Float8GetDatum(skewY);
12830  values[8] = Int32GetDatum(srid);
12831  values[9] = UInt32GetDatum(numBands);
12832 
12833  memset(nulls, FALSE, sizeof(bool) * values_length);
12834 
12835  /* build a tuple */
12836  tuple = heap_form_tuple(tupdesc, values, nulls);
12837 
12838  /* make the tuple into a datum */
12839  result = HeapTupleGetDatum(tuple);
12840 
12841  PG_RETURN_DATUM(result);
12842 }
int rt_raster_get_num_bands(rt_raster raster)
Definition: rt_api.c:5677
double rt_raster_get_y_offset(rt_raster raster)
Get raster y offset, in projection units.
Definition: rt_api.c:5527
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
double rt_raster_get_x_offset(rt_raster raster)
Get raster x offset, in projection units.
Definition: rt_api.c:5518
tuple raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
Definition: rtrowdump.py:123
int32_t rt_raster_get_srid(rt_raster raster)
Get raster's SRID.
Definition: rt_api.c:5661
char ** result
Definition: liblwgeom.h:218
#define POSTGIS_RT_DEBUG(level, msg)
Definition: rt_pg.h:58
double rt_raster_get_x_scale(rt_raster raster)
Get scale X in projection units.
Definition: rt_api.c:5455
uint16_t rt_raster_get_height(rt_raster raster)
Definition: rt_api.c:5434
#define FALSE
Definition: dbfopen.c:169
Struct definitions.
Definition: rt_api.h:2175
double rt_raster_get_y_scale(rt_raster raster)
Get scale Y in projection units.
Definition: rt_api.c:5464
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
uint16_t rt_raster_get_width(rt_raster raster)
Definition: rt_api.c:5426

Here is the call graph for this function: