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

Definition at line 586 of file rtpg_raster_properties.c.

References FALSE, rt_raster_serialized_t::height, rt_raster_serialized_t::ipX, rt_raster_serialized_t::ipY, rt_raster_serialized_t::numBands, POSTGIS_RT_DEBUG, rtrowdump::raster, 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(), rt_raster_serialized_t::scaleX, rt_raster_serialized_t::scaleY, rt_raster_serialized_t::skewX, rt_raster_serialized_t::skewY, rt_raster_serialized_t::srid, TRUE, and rt_raster_serialized_t::width.

587 {
588  rt_pgraster *pgraster = NULL;
589  rt_raster raster = NULL;
590 
592  double scaleX;
593  double scaleY;
594  double ipX;
595  double ipY;
596  double skewX;
597  double skewY;
598  int32_t srid;
599  uint32_t width;
601 
602  TupleDesc tupdesc;
603  int values_length = 10;
604  Datum values[values_length];
605  bool nulls[values_length];
606  HeapTuple tuple;
607  Datum result;
608 
609  POSTGIS_RT_DEBUG(3, "RASTER_metadata: Starting");
610 
611  /* pgraster is null, return null */
612  if (PG_ARGISNULL(0))
613  PG_RETURN_NULL();
614  pgraster = (rt_pgraster *) PG_DETOAST_DATUM_SLICE(PG_GETARG_DATUM(0), 0, sizeof(struct rt_raster_serialized_t));
615 
616  /* raster */
617  raster = rt_raster_deserialize(pgraster, TRUE);
618  if (!raster) {
619  PG_FREE_IF_COPY(pgraster, 0);
620  elog(ERROR, "RASTER_metadata; Could not deserialize raster");
621  PG_RETURN_NULL();
622  }
623 
624  /* upper left x, y */
625  ipX = rt_raster_get_x_offset(raster);
626  ipY = rt_raster_get_y_offset(raster);
627 
628  /* width, height */
629  width = rt_raster_get_width(raster);
630  height = rt_raster_get_height(raster);
631 
632  /* scale x, y */
633  scaleX = rt_raster_get_x_scale(raster);
634  scaleY = rt_raster_get_y_scale(raster);
635 
636  /* skew x, y */
637  skewX = rt_raster_get_x_skew(raster);
638  skewY = rt_raster_get_y_skew(raster);
639 
640  /* srid */
641  srid = rt_raster_get_srid(raster);
642 
643  /* numbands */
644  numBands = rt_raster_get_num_bands(raster);
645 
646  rt_raster_destroy(raster);
647  PG_FREE_IF_COPY(pgraster, 0);
648 
649  /* Build a tuple descriptor for our result type */
650  if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE) {
651  ereport(ERROR, (
652  errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
653  errmsg(
654  "function returning record called in context "
655  "that cannot accept type record"
656  )
657  ));
658  }
659 
660  BlessTupleDesc(tupdesc);
661 
662  values[0] = Float8GetDatum(ipX);
663  values[1] = Float8GetDatum(ipY);
664  values[2] = UInt32GetDatum(width);
665  values[3] = UInt32GetDatum(height);
666  values[4] = Float8GetDatum(scaleX);
667  values[5] = Float8GetDatum(scaleY);
668  values[6] = Float8GetDatum(skewX);
669  values[7] = Float8GetDatum(skewY);
670  values[8] = Int32GetDatum(srid);
671  values[9] = UInt32GetDatum(numBands);
672 
673  memset(nulls, FALSE, sizeof(bool) * values_length);
674 
675  /* build a tuple */
676  tuple = heap_form_tuple(tupdesc, values, nulls);
677 
678  /* make the tuple into a datum */
679  result = HeapTupleGetDatum(tuple);
680 
681  PG_RETURN_DATUM(result);
682 }
double rt_raster_get_x_offset(rt_raster raster)
Get raster x offset, in projection units.
Definition: rt_raster.c:213
double rt_raster_get_y_skew(rt_raster raster)
Get skew about the Y axis.
Definition: rt_raster.c:190
uint16_t rt_raster_get_num_bands(rt_raster raster)
Definition: rt_raster.c:372
tuple raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
Definition: rtrowdump.py:121
unsigned int uint32_t
Definition: uthash.h:78
double rt_raster_get_x_scale(rt_raster raster)
Get scale X in projection units.
Definition: rt_raster.c:150
int32_t rt_raster_get_srid(rt_raster raster)
Get raster's SRID.
Definition: rt_raster.c:356
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
Definition: rt_raster.c:82
double rt_raster_get_y_scale(rt_raster raster)
Get scale Y in projection units.
Definition: rt_raster.c:159
double rt_raster_get_x_skew(rt_raster raster)
Get skew about the X axis.
Definition: rt_raster.c:181
uint16_t rt_raster_get_width(rt_raster raster)
Definition: rt_raster.c:121
#define FALSE
Definition: dbfopen.c:168
Struct definitions.
Definition: librtcore.h:2201
uint16_t rt_raster_get_height(rt_raster raster)
Definition: rt_raster.c:129
#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
double rt_raster_get_y_offset(rt_raster raster)
Get raster y offset, in projection units.
Definition: rt_raster.c:222

Here is the call graph for this function: