PostGIS  2.1.10dev-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, lwerror(), LWGEOM2GEOS(), 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  lwerror("PrepGeomCacheBuilder asked to build new prepcache where one already exists.");
318  return LW_FAILURE;
319  }
320 
321  prepcache->geom = LWGEOM2GEOS( lwgeom );
322  if ( ! prepcache->geom ) return LW_FAILURE;
323  prepcache->prepared_geom = GEOSPrepare( prepcache->geom );
324  if ( ! prepcache->prepared_geom ) return LW_FAILURE;
325  prepcache->argnum = cache->argnum;
326 
327  /*
328  * In order to find the objects we need to destroy, we keep
329  * extra references in a global hash object.
330  */
331  pghe = GetPrepGeomHashEntry(prepcache->context_callback);
332  if ( ! pghe )
333  {
334  lwerror("PrepGeomCacheBuilder failed to find hash entry for context %p", prepcache->context_callback);
335  return LW_FAILURE;
336  }
337 
338  pghe->geom = prepcache->geom;
339  pghe->prepared_geom = prepcache->prepared_geom;
340 
341  return LW_SUCCESS;
342 }
const GEOSPreparedGeometry * prepared_geom
#define LW_SUCCESS
Definition: liblwgeom.h:55
GEOSGeometry * LWGEOM2GEOS(const LWGEOM *lwgeom)
#define LW_FAILURE
Definition: liblwgeom.h:54
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:67
const GEOSPreparedGeometry * prepared_geom
MemoryContext context_statement
const GEOSGeometry * geom
static void AddPrepGeomHashEntry(PrepGeomHashEntry pghe)
const GEOSGeometry * geom
static void CreatePrepGeomHash(void)
static MemoryContextMethods PreparedCacheContextMethods
static PrepGeomHashEntry * GetPrepGeomHashEntry(MemoryContext mcxt)
MemoryContext context_callback
static HTAB * PrepGeomHash

Here is the call graph for this function: