PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ RASTER_metadata()

Datum RASTER_metadata ( PG_FUNCTION_ARGS  )

Definition at line 590 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().

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