}
-//#define NO_PREPARED_GEOM
-#ifndef NO_PREPARED_GEOM
+#define PREPARED_GEOM 1
+#ifdef PREPARED_GEOM
Datum containsPrepared(PG_FUNCTION_ARGS);
Datum containsProperlyPrepared(PG_FUNCTION_ARGS);
* get cache
* if cache not exist
* create cache
- * arg1 into cache
- * return test( geom1, geom2)
+ * geom1 into cache
*
* else if geom1 matches cached geom1
* if cached prepared not exist
* geom1 prepared into cache
*
- * prepare geom1get prepared
- *
* else
- * geom1 into cache geom1
+ * geom1 into cache
*/
PREPARED_GEOM_CACHE *
get_prepared_geometry_cache(
PREPARED_GEOM_CACHE * cache,
uchar * serialized_geom,
Size serialized_geom_length)
- //GEOSGeom geom)
{
GEOSGeom g;
if ( !cache || !cache->serialized_geom )
{
- //lwnotice("get_prepared_geometry_cache: creating cache: %x", cache);
-
+ #ifdef PGIS_DEBUG
+ lwnotice( "get_prepared_geometry_cache: creating cache: %x", cache);
+ #endif
+
cache = lwalloc( sizeof( PREPARED_GEOM_CACHE ));
cache->prepared_geom = 0;
{
if ( !cache->prepared_geom )
{
- //lwnotice("get_prepared_geometry_cache: preparing obj");
+ #ifdef PGIS_DEBUG
+ lwnotice("get_prepared_geometry_cache: preparing obj");
+ #endif
+
g = POSTGIS2GEOS( serialized_geom);
cache->prepared_geom = GEOSPrepare( g);
}
else
{
- //lwnotice("get_prepared_geometry_cache: prepared obj in cache");
+ #ifdef PGIS_DEBUG
+ lwnotice("get_prepared_geometry_cache: prepared obj in cache");
+ #endif
}
}
else
{
- //lwnotice("get_prepared_geometry_cache: obj NOT in cache");
+ #ifdef PGIS_DEBUG
+ lwnotice("get_prepared_geometry_cache: obj NOT in cache");
+ #endif
lwfree( cache->serialized_geom);
cache->serialized_geom = 0;
PREPARED_GEOM_CACHE * prep_cache;
MemoryContext old_context;
- //(varattrib *) datum
- //(struct varlena *) DatumGetPointer(datum)
- arg1_length = toast_raw_datum_size(PG_GETARG_DATUM(0)) - VARHDRSZ;
+ /*arg1_length = toast_raw_datum_size(PG_GETARG_DATUM(0)) - VARHDRSZ;*/
geom1 = (PG_LWGEOM *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
geom2 = (PG_LWGEOM *) PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
+ arg1_length = VARSIZE(geom1) - VARHDRSZ;
+
errorIfGeometryCollection(geom1,geom2);
errorIfSRIDMismatch(pglwgeom_getSRID(geom1), pglwgeom_getSRID(geom2));
old_context = MemoryContextSwitchTo(fcinfo->flinfo->fn_mcxt);
prep_cache = fcinfo->flinfo->fn_extra;
- //lwnotice("prep_cache before: %x", prep_cache);
+
prep_cache = get_prepared_geometry_cache( prep_cache, geom1, arg1_length);
- //lwnotice("prep_cache after: %x", prep_cache);
+
fcinfo->flinfo->fn_extra = prep_cache;
MemoryContextSwitchTo(old_context);
+ initGEOS(lwnotice, lwnotice);
+
g2 = POSTGIS2GEOS(geom2);
if ( !prep_cache || !prep_cache->prepared_geom )
{
g1 = POSTGIS2GEOS(geom1);
- //lwnotice("invoking GEOSContains");
+
result = GEOSContains( g1, g2);
GEOSGeom_destroy(g1);
{
pg = prep_cache->prepared_geom;
- //lwnotice("invoking GEOSPreparedContains");
result = GEOSPreparedContains( pg, g2);
}
GEOSGeom_destroy(g2);
PREPARED_GEOM_CACHE * prep_cache;
MemoryContext old_context;
- //(varattrib *) datum
- //(struct varlena *) DatumGetPointer(datum)
- arg1_length = toast_raw_datum_size(PG_GETARG_DATUM(0)) - VARHDRSZ;
+ /*arg1_length = toast_raw_datum_size(PG_GETARG_DATUM(0)) - VARHDRSZ;*/
geom1 = (PG_LWGEOM *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
geom2 = (PG_LWGEOM *) PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
+ arg1_length = VARSIZE(geom1) - VARHDRSZ;
+
errorIfGeometryCollection(geom1,geom2);
errorIfSRIDMismatch(pglwgeom_getSRID(geom1), pglwgeom_getSRID(geom2));
old_context = MemoryContextSwitchTo(fcinfo->flinfo->fn_mcxt);
prep_cache = fcinfo->flinfo->fn_extra;
- //lwnotice("prep_cache before: %x", prep_cache);
+
prep_cache = get_prepared_geometry_cache( prep_cache, geom1, arg1_length);
- //lwnotice("prep_cache after: %x", prep_cache);
+
fcinfo->flinfo->fn_extra = prep_cache;
- MemoryContextSwitchTo(old_context);
+ MemoryContextSwitchTo( old_context);
+ initGEOS(lwnotice, lwnotice);
+
g2 = POSTGIS2GEOS(geom2);
if ( !prep_cache || !prep_cache->prepared_geom )
PREPARED_GEOM_CACHE * prep_cache;
MemoryContext old_context;
- //(varattrib *) datum
- //(struct varlena *) DatumGetPointer(datum)
- arg1_length = toast_raw_datum_size(PG_GETARG_DATUM(0)) - VARHDRSZ;
+ /*arg1_length = toast_raw_datum_size(PG_GETARG_DATUM(0)) - VARHDRSZ;*/
geom1 = (PG_LWGEOM *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
geom2 = (PG_LWGEOM *) PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
+ arg1_length = VARSIZE(geom1) - VARHDRSZ;
+
errorIfGeometryCollection(geom1,geom2);
errorIfSRIDMismatch(pglwgeom_getSRID(geom1), pglwgeom_getSRID(geom2));
old_context = MemoryContextSwitchTo(fcinfo->flinfo->fn_mcxt);
prep_cache = fcinfo->flinfo->fn_extra;
- //lwnotice("prep_cache before: %x", prep_cache);
+
prep_cache = get_prepared_geometry_cache( prep_cache, geom1, arg1_length);
- //lwnotice("prep_cache after: %x", prep_cache);
+
fcinfo->flinfo->fn_extra = prep_cache;
MemoryContextSwitchTo(old_context);
+ initGEOS(lwnotice, lwnotice);
+
g2 = POSTGIS2GEOS(geom2);
if ( !prep_cache || !prep_cache->prepared_geom )
{
pg = prep_cache->prepared_geom;
- //lwnotice("invoking GEOSPreparedContains");
result = GEOSPreparedCovers( pg, g2);
}
GEOSGeom_destroy(g2);
PREPARED_GEOM_CACHE * prep_cache;
MemoryContext old_context;
- //(varattrib *) datum
- //(struct varlena *) DatumGetPointer(datum)
- arg1_length = toast_raw_datum_size(PG_GETARG_DATUM(0)) - VARHDRSZ;
+ /*arg1_length = toast_raw_datum_size(PG_GETARG_DATUM(0)) - VARHDRSZ;*/
geom1 = (PG_LWGEOM *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
geom2 = (PG_LWGEOM *) PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
+ arg1_length = VARSIZE(geom1) - VARHDRSZ;
+
errorIfGeometryCollection(geom1,geom2);
errorIfSRIDMismatch(pglwgeom_getSRID(geom1), pglwgeom_getSRID(geom2));
old_context = MemoryContextSwitchTo(fcinfo->flinfo->fn_mcxt);
prep_cache = fcinfo->flinfo->fn_extra;
- //lwnotice("prep_cache before: %x", prep_cache);
+
prep_cache = get_prepared_geometry_cache( prep_cache, geom1, arg1_length);
- //lwnotice("prep_cache after: %x", prep_cache);
+
fcinfo->flinfo->fn_extra = prep_cache;
MemoryContextSwitchTo(old_context);
+ initGEOS(lwnotice, lwnotice);
+
g2 = POSTGIS2GEOS(geom2);
if ( !prep_cache || !prep_cache->prepared_geom )