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

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

2170 {
2171  char *nsp = NULL;
2172  char *tbl = NULL;
2173  text *col = NULL;
2174  char *nsp_tbl = NULL;
2175  Oid tbl_oid;
2176  ND_STATS *nd_stats;
2177  GBOX *gbox;
2178 
2179  if ( PG_NARGS() == 3 )
2180  {
2181  nsp = text2cstring(PG_GETARG_TEXT_P(0));
2182  tbl = text2cstring(PG_GETARG_TEXT_P(1));
2183  col = PG_GETARG_TEXT_P(2);
2184  nsp_tbl = palloc(strlen(nsp) + strlen(tbl) + 6);
2185  sprintf(nsp_tbl, "\"%s\".\"%s\"", nsp, tbl);
2186  tbl_oid = DatumGetObjectId(DirectFunctionCall1(regclassin, CStringGetDatum(nsp_tbl)));
2187  pfree(nsp_tbl);
2188  }
2189  else if ( PG_NARGS() == 2 )
2190  {
2191  tbl = text2cstring(PG_GETARG_TEXT_P(0));
2192  col = PG_GETARG_TEXT_P(1);
2193  nsp_tbl = palloc(strlen(tbl) + 3);
2194  sprintf(nsp_tbl, "\"%s\"", tbl);
2195  tbl_oid = DatumGetObjectId(DirectFunctionCall1(regclassin, CStringGetDatum(nsp_tbl)));
2196  pfree(nsp_tbl);
2197  }
2198  else
2199  {
2200  elog(ERROR, "estimated_extent() called with wrong number of arguments");
2201  PG_RETURN_NULL();
2202  }
2203 
2204  /* Estimated extent only returns 2D bounds, so use mode 2 */
2205  nd_stats = pg_get_nd_stats_by_name(tbl_oid, col, 2);
2206 
2207  /* Error out on no stats */
2208  if ( ! nd_stats )
2209  elog(ERROR, "stats for \"%s.%s\" do not exist", tbl, text2cstring(col));
2210 
2211  /* Construct the box */
2212  gbox = palloc(sizeof(GBOX));
2213  FLAGS_SET_GEODETIC(gbox->flags, 0);
2214  FLAGS_SET_Z(gbox->flags, 0);
2215  FLAGS_SET_M(gbox->flags, 0);
2216  gbox->xmin = nd_stats->extent.min[0];
2217  gbox->xmax = nd_stats->extent.max[0];
2218  gbox->ymin = nd_stats->extent.min[1];
2219  gbox->ymax = nd_stats->extent.max[1];
2220 
2221  pfree(nd_stats);
2222  PG_RETURN_POINTER(gbox);
2223 }
double xmax
Definition: liblwgeom.h:277
#define FLAGS_SET_GEODETIC(flags, value)
Definition: liblwgeom.h:133
#define FLAGS_SET_Z(flags, value)
Definition: liblwgeom.h:130
double ymin
Definition: liblwgeom.h:278
double xmin
Definition: liblwgeom.h:276
char * text2cstring(const text *textptr)
double ymax
Definition: liblwgeom.h:279
uint8_t flags
Definition: liblwgeom.h:275
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:131

Here is the call graph for this function:

Here is the caller graph for this function: