PostGIS  2.5.1dev-r@@SVN_REVISION@@

◆ RASTER_metadata()

Datum RASTER_metadata ( PG_FUNCTION_ARGS  )

Definition at line 592 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, VALUES_LENGTH, and rt_raster_serialized_t::width.

Referenced by RASTER_hasNoBand().

593 {
594  rt_pgraster *pgraster = NULL;
595  rt_raster raster = NULL;
596 
598  double scaleX;
599  double scaleY;
600  double ipX;
601  double ipY;
602  double skewX;
603  double skewY;
604  int32_t srid;
605  uint32_t width;
607 
608  TupleDesc tupdesc;
609  Datum values[VALUES_LENGTH];
610  bool nulls[VALUES_LENGTH];
611  HeapTuple tuple;
612  Datum result;
613 
614  POSTGIS_RT_DEBUG(3, "RASTER_metadata: Starting");
615 
616  /* pgraster is null, return null */
617  if (PG_ARGISNULL(0))
618  PG_RETURN_NULL();
619  pgraster = (rt_pgraster *) PG_DETOAST_DATUM_SLICE(PG_GETARG_DATUM(0), 0, sizeof(struct rt_raster_serialized_t));
620 
621  /* raster */
622  raster = rt_raster_deserialize(pgraster, TRUE);
623  if (!raster) {
624  PG_FREE_IF_COPY(pgraster, 0);
625  elog(ERROR, "RASTER_metadata; Could not deserialize raster");
626  PG_RETURN_NULL();
627  }
628 
629  /* upper left x, y */
630  ipX = rt_raster_get_x_offset(raster);
631  ipY = rt_raster_get_y_offset(raster);
632 
633  /* width, height */
634  width = rt_raster_get_width(raster);
635  height = rt_raster_get_height(raster);
636 
637  /* scale x, y */
638  scaleX = rt_raster_get_x_scale(raster);
639  scaleY = rt_raster_get_y_scale(raster);
640 
641  /* skew x, y */
642  skewX = rt_raster_get_x_skew(raster);
643  skewY = rt_raster_get_y_skew(raster);
644 
645  /* srid */
646  srid = rt_raster_get_srid(raster);
647 
648  /* numbands */
649  numBands = rt_raster_get_num_bands(raster);
650 
651  rt_raster_destroy(raster);
652  PG_FREE_IF_COPY(pgraster, 0);
653 
654  /* Build a tuple descriptor for our result type */
655  if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE) {
656  ereport(ERROR, (
657  errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
658  errmsg(
659  "function returning record called in context "
660  "that cannot accept type record"
661  )
662  ));
663  }
664 
665  BlessTupleDesc(tupdesc);
666 
667  values[0] = Float8GetDatum(ipX);
668  values[1] = Float8GetDatum(ipY);
669  values[2] = UInt32GetDatum(width);
670  values[3] = UInt32GetDatum(height);
671  values[4] = Float8GetDatum(scaleX);
672  values[5] = Float8GetDatum(scaleY);
673  values[6] = Float8GetDatum(skewX);
674  values[7] = Float8GetDatum(skewY);
675  values[8] = Int32GetDatum(srid);
676  values[9] = UInt32GetDatum(numBands);
677 
678  memset(nulls, FALSE, sizeof(bool) * VALUES_LENGTH);
679 
680  /* build a tuple */
681  tuple = heap_form_tuple(tupdesc, values, nulls);
682 
683  /* make the tuple into a datum */
684  result = HeapTupleGetDatum(tuple);
685 
686  PG_RETURN_DATUM(result);
687 }
#define VALUES_LENGTH
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
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:2250
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:725
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:
Here is the caller graph for this function: