PostGIS  2.3.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 306 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.

307 {
308  PrepGeomCache* prepcache = (PrepGeomCache*)cache;
309  PrepGeomHashEntry* pghe;
310 
311  /*
312  * First time through? allocate the global hash.
313  */
314  if (!PrepGeomHash)
316 
317  /*
318  * No callback entry for this statement context yet? Set it up
319  */
320  if ( ! prepcache->context_callback )
321  {
322  PrepGeomHashEntry pghe;
323  prepcache->context_callback = MemoryContextCreate(T_AllocSetContext, 8192,
325  prepcache->context_statement,
326  "PostGIS Prepared Geometry Context");
327  pghe.context = prepcache->context_callback;
328  pghe.geom = 0;
329  pghe.prepared_geom = 0;
330  AddPrepGeomHashEntry( pghe );
331  }
332 
333  /*
334  * Hum, we shouldn't be asked to build a new cache on top of
335  * an existing one. Error.
336  */
337  if ( prepcache->argnum || prepcache->geom || prepcache->prepared_geom )
338  {
339  lwpgerror("PrepGeomCacheBuilder asked to build new prepcache where one already exists.");
340  return LW_FAILURE;
341  }
342 
343  /*
344  * Avoid creating a PreparedPoint around a Point or a MultiPoint.
345  * Consider changing this behavior in the future if supported GEOS
346  * versions correctly handle prepared points and multipoints and
347  * provide a performance benefit.
348  * See https://trac.osgeo.org/postgis/ticket/3437
349  */
350  if (lwgeom_get_type(lwgeom) == POINTTYPE || lwgeom_get_type(lwgeom) == MULTIPOINTTYPE)
351  return LW_FAILURE;
352 
353  prepcache->geom = LWGEOM2GEOS( lwgeom , 0);
354  if ( ! prepcache->geom ) return LW_FAILURE;
355  prepcache->prepared_geom = GEOSPrepare( prepcache->geom );
356  if ( ! prepcache->prepared_geom ) return LW_FAILURE;
357  prepcache->argnum = cache->argnum;
358 
359  /*
360  * In order to find the objects we need to destroy, we keep
361  * extra references in a global hash object.
362  */
363  pghe = GetPrepGeomHashEntry(prepcache->context_callback);
364  if ( ! pghe )
365  {
366  lwpgerror("PrepGeomCacheBuilder failed to find hash entry for context %p", prepcache->context_callback);
367  return LW_FAILURE;
368  }
369 
370  pghe->geom = prepcache->geom;
371  pghe->prepared_geom = prepcache->prepared_geom;
372 
373  return LW_SUCCESS;
374 }
const GEOSPreparedGeometry * prepared_geom
uint32_t lwgeom_get_type(const LWGEOM *geom)
Return LWTYPE number.
Definition: lwgeom.c:842
#define MULTIPOINTTYPE
Definition: liblwgeom.h:87
#define LW_SUCCESS
Definition: liblwgeom.h:79
#define LW_FAILURE
Definition: liblwgeom.h:78
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:84
MemoryContext context_callback
static HTAB * PrepGeomHash

Here is the call graph for this function: