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

Definition at line 2157 of file gserialized_estimate.c.

References ND_STATS_T::extent, GBOX::flags, FLAGS_SET_GEODETIC, FLAGS_SET_M, FLAGS_SET_Z, ND_BOX_T::max, ND_BOX_T::min, pg_get_nd_stats_by_name(), text2cstring(), GBOX::xmax, GBOX::xmin, GBOX::ymax, and GBOX::ymin.

Referenced by geometry_estimated_extent().

2158 {
2159  char *nsp = NULL;
2160  char *tbl = NULL;
2161  text *col = NULL;
2162  char *nsp_tbl = NULL;
2163  Oid tbl_oid;
2164  ND_STATS *nd_stats;
2165  GBOX *gbox;
2166 
2167  if ( PG_NARGS() == 3 )
2168  {
2169  nsp = text2cstring(PG_GETARG_TEXT_P(0));
2170  tbl = text2cstring(PG_GETARG_TEXT_P(1));
2171  col = PG_GETARG_TEXT_P(2);
2172  nsp_tbl = palloc(strlen(nsp) + strlen(tbl) + 6);
2173  sprintf(nsp_tbl, "\"%s\".\"%s\"", nsp, tbl);
2174  tbl_oid = DatumGetObjectId(DirectFunctionCall1(regclassin, CStringGetDatum(nsp_tbl)));
2175  pfree(nsp_tbl);
2176  }
2177  else if ( PG_NARGS() == 2 )
2178  {
2179  tbl = text2cstring(PG_GETARG_TEXT_P(0));
2180  col = PG_GETARG_TEXT_P(1);
2181  nsp_tbl = palloc(strlen(tbl) + 3);
2182  sprintf(nsp_tbl, "\"%s\"", tbl);
2183  tbl_oid = DatumGetObjectId(DirectFunctionCall1(regclassin, CStringGetDatum(nsp_tbl)));
2184  pfree(nsp_tbl);
2185  }
2186  else
2187  {
2188  elog(ERROR, "estimated_extent() called with wrong number of arguments");
2189  PG_RETURN_NULL();
2190  }
2191 
2192  /* Estimated extent only returns 2D bounds, so use mode 2 */
2193  nd_stats = pg_get_nd_stats_by_name(tbl_oid, col, 2);
2194 
2195  /* Error out on no stats */
2196  if ( ! nd_stats )
2197  elog(ERROR, "stats for \"%s.%s\" do not exist", tbl, text2cstring(col));
2198 
2199  /* Construct the box */
2200  gbox = palloc(sizeof(GBOX));
2201  FLAGS_SET_GEODETIC(gbox->flags, 0);
2202  FLAGS_SET_Z(gbox->flags, 0);
2203  FLAGS_SET_M(gbox->flags, 0);
2204  gbox->xmin = nd_stats->extent.min[0];
2205  gbox->xmax = nd_stats->extent.max[0];
2206  gbox->ymin = nd_stats->extent.min[1];
2207  gbox->ymax = nd_stats->extent.max[1];
2208 
2209  pfree(nd_stats);
2210  PG_RETURN_POINTER(gbox);
2211 }
double xmax
Definition: liblwgeom.h:249
#define FLAGS_SET_GEODETIC(flags, value)
Definition: liblwgeom.h:115
#define FLAGS_SET_Z(flags, value)
Definition: liblwgeom.h:112
double ymin
Definition: liblwgeom.h:250
double xmin
Definition: liblwgeom.h:248
char * text2cstring(const text *textptr)
double ymax
Definition: liblwgeom.h:251
uint8_t flags
Definition: liblwgeom.h:247
float4 max[ND_DIMS]
float4 min[ND_DIMS]
static ND_STATS * pg_get_nd_stats_by_name(const Oid table_oid, const text *att_text, int mode)
Pull the stats object from the PgSQL system catalogs.
N-dimensional statistics structure.
#define FLAGS_SET_M(flags, value)
Definition: liblwgeom.h:113

Here is the call graph for this function:

Here is the caller graph for this function: