PostGIS  2.2.7dev-r@@SVN_REVISION@@
static int PrepGeomCacheBuilder ( const LWGEOM lwgeom,
GeomCache *  cache 
)
static

Given a generic GeomCache, and a geometry to prepare, prepare a PrepGeomCache and stick it into the GeomCache->index slot.

The PrepGeomCache includes the original GEOS geometry, and the GEOS prepared geometry, and a pointer to the MemoryContext where the callback functions are registered.

This function is passed into the generic GetGeomCache function so that it can build an appropriate indexed structure in the case of a cache hit when there is no indexed structure yet available to return.

Definition at line 284 of file lwgeom_geos_prepared.c.

References AddPrepGeomHashEntry(), PrepGeomCache::argnum, PrepGeomHashEntry::context, PrepGeomCache::context_callback, PrepGeomCache::context_statement, CreatePrepGeomHash(), PrepGeomCache::geom, PrepGeomHashEntry::geom, GetPrepGeomHashEntry(), LW_FAILURE, LW_SUCCESS, LWGEOM2GEOS(), lwgeom_get_type(), MULTIPOINTTYPE, POINTTYPE, PrepGeomCache::prepared_geom, PrepGeomHashEntry::prepared_geom, PreparedCacheContextMethods, and PrepGeomHash.

285 {
286  PrepGeomCache* prepcache = (PrepGeomCache*)cache;
287  PrepGeomHashEntry* pghe;
288 
289  /*
290  * First time through? allocate the global hash.
291  */
292  if (!PrepGeomHash)
294 
295  /*
296  * No callback entry for this statement context yet? Set it up
297  */
298  if ( ! prepcache->context_callback )
299  {
300  PrepGeomHashEntry pghe;
301  prepcache->context_callback = MemoryContextCreate(T_AllocSetContext, 8192,
303  prepcache->context_statement,
304  "PostGIS Prepared Geometry Context");
305  pghe.context = prepcache->context_callback;
306  pghe.geom = 0;
307  pghe.prepared_geom = 0;
308  AddPrepGeomHashEntry( pghe );
309  }
310 
311  /*
312  * Hum, we shouldn't be asked to build a new cache on top of
313  * an existing one. Error.
314  */
315  if ( prepcache->argnum || prepcache->geom || prepcache->prepared_geom )
316  {
317  lwpgerror("PrepGeomCacheBuilder asked to build new prepcache where one already exists.");
318  return LW_FAILURE;
319  }
320 
321  /*
322  * Avoid creating a PreparedPoint around a Point or a MultiPoint.
323  * Consider changing this behavior in the future if supported GEOS
324  * versions correctly handle prepared points and multipoints and
325  * provide a performance benefit.
326  * See https://trac.osgeo.org/postgis/ticket/3437
327  */
328  if (lwgeom_get_type(lwgeom) == POINTTYPE || lwgeom_get_type(lwgeom) == MULTIPOINTTYPE)
329  return LW_FAILURE;
330 
331  prepcache->geom = LWGEOM2GEOS( lwgeom , 0);
332  if ( ! prepcache->geom ) return LW_FAILURE;
333  prepcache->prepared_geom = GEOSPrepare( prepcache->geom );
334  if ( ! prepcache->prepared_geom ) return LW_FAILURE;
335  prepcache->argnum = cache->argnum;
336 
337  /*
338  * In order to find the objects we need to destroy, we keep
339  * extra references in a global hash object.
340  */
341  pghe = GetPrepGeomHashEntry(prepcache->context_callback);
342  if ( ! pghe )
343  {
344  lwpgerror("PrepGeomCacheBuilder failed to find hash entry for context %p", prepcache->context_callback);
345  return LW_FAILURE;
346  }
347 
348  pghe->geom = prepcache->geom;
349  pghe->prepared_geom = prepcache->prepared_geom;
350 
351  return LW_SUCCESS;
352 }
const GEOSPreparedGeometry * prepared_geom
uint32_t lwgeom_get_type(const LWGEOM *geom)
Return LWTYPE number.
Definition: lwgeom.c:829
#define MULTIPOINTTYPE
Definition: liblwgeom.h:73
#define LW_SUCCESS
Definition: liblwgeom.h:65
#define LW_FAILURE
Definition: liblwgeom.h:64
const GEOSPreparedGeometry * prepared_geom
MemoryContext context_statement
const GEOSGeometry * geom
static void AddPrepGeomHashEntry(PrepGeomHashEntry pghe)
const GEOSGeometry * geom
GEOSGeometry * LWGEOM2GEOS(const LWGEOM *lwgeom, int autofix)
static void CreatePrepGeomHash(void)
static MemoryContextMethods PreparedCacheContextMethods
static PrepGeomHashEntry * GetPrepGeomHashEntry(MemoryContext mcxt)
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:70
MemoryContext context_callback
static HTAB * PrepGeomHash

Here is the call graph for this function: