#include <string.h>
#include <assert.h>
+/* Return NULL on GEOS error
+ *
+ * Prints error message only if it was not for interruption, in which
+ * case we let PostgreSQL deal with the error.
+ */
+#define HANDLE_GEOS_ERROR(label) { \
+ if ( ! strstr(lwgeom_geos_errmsg, "InterruptedException") ) \
+ lwerror(label": %s", lwgeom_geos_errmsg); \
+ PG_RETURN_NULL(); \
+}
+
/*
** Prototypes for SQL-bound functions
*/
g1 = (GEOSGeometry *)POSTGIS2GEOS(geom1);
if ( 0 == g1 ) /* exception thrown at construction */
{
- lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
PG_RETURN_NULL();
}
g2 = (GEOSGeometry *)POSTGIS2GEOS(geom2);
if ( 0 == g2 ) /* exception thrown */
{
- lwerror("Second argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("Second argument geometry could not be converted to GEOS");
GEOSGeom_destroy(g1);
PG_RETURN_NULL();
}
if (retcode == 0)
{
- lwerror("GEOSHausdorffDistance: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("GEOSHausdorffDistance");
PG_RETURN_NULL(); /*never get here */
}
g1 = (GEOSGeometry *)POSTGIS2GEOS(geom1);
if ( 0 == g1 ) /* exception thrown at construction */
{
- lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
PG_RETURN_NULL();
}
g2 = (GEOSGeometry *)POSTGIS2GEOS(geom2);
if ( 0 == g2 ) /* exception thrown at construction */
{
- lwerror("Second argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("Second argument geometry could not be converted to GEOS");
GEOSGeom_destroy(g1);
PG_RETURN_NULL();
}
if (retcode == 0)
{
- lwerror("GEOSHausdorffDistanceDensify: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("GEOSHausdorffDistanceDensify");
PG_RETURN_NULL(); /*never get here */
}
g = GEOSGeom_createCollection(GEOS_GEOMETRYCOLLECTION, geoms, curgeom);
if ( ! g )
{
- lwerror("Could not create GEOS COLLECTION from geometry array: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("Could not create GEOS COLLECTION from geometry array");
PG_RETURN_NULL();
}
if ( 0 == g ) /* exception thrown at construction */
{
/* TODO: cleanup all GEOS memory */
- lwerror("Geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("Geometry could not be converted to GEOS");
PG_RETURN_NULL();
}
geoms[curgeom++] = g;
if ( ! g1 )
{
/* TODO: cleanup geoms memory */
- lwerror("Could not create MULTIPOLYGON from geometry array: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("Could not create MULTIPOLYGON from geometry array");
PG_RETURN_NULL();
}
g2 = GEOSUnionCascaded(g1);
geos_result = (GEOSGeometry *)POSTGIS2GEOS(geom);
if ( 0 == geos_result ) /* exception thrown at construction */
{
- lwerror("geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("geometry could not be converted to GEOS");
PG_RETURN_NULL();
}
srid = gserialized_get_srid(geom);
{
GEOSGeom_destroy((GEOSGeometry *)g1);
GEOSGeom_destroy((GEOSGeometry *)geos_result);
- lwerror("GEOSUnion: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("GEOSUnion");
}
GEOSGeom_destroy((GEOSGeometry *)g1);
GEOSGeom_destroy((GEOSGeometry *)geos_result);
if ( 0 == g1 ) /* exception thrown at construction */
{
- lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
PG_RETURN_NULL();
}
if (g3 == NULL)
{
- lwerror("GEOSUnion: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("GEOSUnion");
PG_RETURN_NULL(); /* never get here */
}
if ( 0 == g1 ) /* exception thrown at construction */
{
- lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
PG_RETURN_NULL();
}
if (g3 == NULL)
{
GEOSGeom_destroy(g1);
- lwerror("GEOSBoundary: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("GEOSBoundary");
PG_RETURN_NULL(); /* never get here */
}
if ( 0 == g1 ) /* exception thrown at construction */
{
- lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
PG_RETURN_NULL();
}
if (g3 == NULL)
{
- lwerror("GEOSConvexHull: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("GEOSConvexHull");
PG_RETURN_NULL(); /* never get here */
}
g1 = (GEOSGeometry *)POSTGIS2GEOS(geom1);
if ( 0 == g1 ) /* exception thrown at construction */
{
- lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
PG_RETURN_NULL();
}
if (g3 == NULL)
{
- lwerror("GEOSTopologyPreserveSimplify: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("GEOSTopologyPreserveSimplify");
PG_RETURN_NULL(); /* never get here */
}
g1 = (GEOSGeometry *)POSTGIS2GEOS(geom1);
if ( 0 == g1 ) /* exception thrown at construction */
{
- lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
PG_RETURN_NULL();
}
if (g3 == NULL)
{
- lwerror("GEOSBuffer: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("GEOSBuffer");
PG_RETURN_NULL(); /* never get here */
}
if (g3 == NULL)
{
GEOSGeom_destroy(g1);
- lwerror("GEOSPointOnSurface: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("GEOSPointOnSurface");
PG_RETURN_NULL(); /* never get here */
}
if ( 0 == geosgeom ) /* exception thrown at construction */
{
- lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
PG_RETURN_NULL();
}
if ( geosresult == NULL )
{
GEOSGeom_destroy(geosgeom);
- lwerror("GEOSGetCentroid: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("GEOSGetCentroid");
PG_RETURN_NULL();
}
g1 = (GEOSGeometry *)POSTGIS2GEOS(geom1);
if ( 0 == g1 ) /* exception thrown at construction */
{
- lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
PG_RETURN_NULL();
}
if ( 0 == g2 ) /* exception thrown at construction */
{
GEOSGeom_destroy(g1);
- lwerror("Second argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("Second argument geometry could not be converted to GEOS");
PG_RETURN_NULL();
}
GEOSGeom_destroy(g2);
if (result == 2)
{
- lwerror("GEOSOverlaps: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("GEOSOverlaps");
PG_RETURN_NULL(); /* never get here */
}
g1 = (GEOSGeometry *)POSTGIS2GEOS(geom2);
if ( 0 == g1 ) /* exception thrown at construction */
{
- lwerror("Geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("Geometry could not be converted to GEOS");
PG_RETURN_NULL();
}
POSTGIS_DEBUG(4, "containsPrepared: cache is live, running preparedcontains");
g1 = (GEOSGeometry *)POSTGIS2GEOS(geom1);
if ( 0 == g1 ) /* exception thrown at construction */
{
- lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
PG_RETURN_NULL();
}
g2 = (GEOSGeometry *)POSTGIS2GEOS(geom2);
if ( 0 == g2 ) /* exception thrown at construction */
{
- lwerror("Second argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("Second argument geometry could not be converted to GEOS");
GEOSGeom_destroy(g1);
PG_RETURN_NULL();
}
if (result == 2)
{
- lwerror("GEOSContains: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("GEOSContains");
PG_RETURN_NULL(); /* never get here */
}
GEOSGeometry *g = (GEOSGeometry *)POSTGIS2GEOS(geom2);
if ( 0 == g ) /* exception thrown at construction */
{
- lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
PG_RETURN_NULL();
}
result = GEOSPreparedContainsProperly( prep_cache->prepared_geom, g);
g1 = (GEOSGeometry *)POSTGIS2GEOS(geom1);
if ( 0 == g1 ) /* exception thrown at construction */
{
- lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
PG_RETURN_NULL();
}
g2 = (GEOSGeometry *)POSTGIS2GEOS(geom2);
if ( 0 == g2 ) /* exception thrown at construction */
{
- lwerror("Second argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("Second argument geometry could not be converted to GEOS");
GEOSGeom_destroy(g1);
PG_RETURN_NULL();
}
if (result == 2)
{
- lwerror("GEOSContains: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("GEOSContains");
PG_RETURN_NULL(); /* never get here */
}
GEOSGeometry *g1 = (GEOSGeometry *)POSTGIS2GEOS(geom2);
if ( 0 == g1 ) /* exception thrown at construction */
{
- lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
PG_RETURN_NULL();
}
result = GEOSPreparedCovers( prep_cache->prepared_geom, g1);
g1 = (GEOSGeometry *)POSTGIS2GEOS(geom1);
if ( 0 == g1 ) /* exception thrown at construction */
{
- lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
PG_RETURN_NULL();
}
g2 = (GEOSGeometry *)POSTGIS2GEOS(geom2);
if ( 0 == g2 ) /* exception thrown at construction */
{
- lwerror("Second argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("Second argument geometry could not be converted to GEOS");
GEOSGeom_destroy(g1);
PG_RETURN_NULL();
}
if (result == 2)
{
- lwerror("GEOSCovers: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("GEOSCovers");
PG_RETURN_NULL(); /* never get here */
}
if ( 0 == g1 ) /* exception thrown at construction */
{
- lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
PG_RETURN_NULL();
}
if ( 0 == g2 ) /* exception thrown at construction */
{
- lwerror("Second argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("Second argument geometry could not be converted to GEOS");
GEOSGeom_destroy(g1);
PG_RETURN_NULL();
}
if (result == 2)
{
- lwerror("GEOSCoveredBy: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("GEOSCoveredBy");
PG_RETURN_NULL(); /* never get here */
}
g1 = (GEOSGeometry *)POSTGIS2GEOS(geom1);
if ( 0 == g1 ) /* exception thrown at construction */
{
- lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
PG_RETURN_NULL();
}
g2 = (GEOSGeometry *)POSTGIS2GEOS(geom2);
if ( 0 == g2 ) /* exception thrown at construction */
{
- lwerror("Second argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("Second argument geometry could not be converted to GEOS");
GEOSGeom_destroy(g1);
PG_RETURN_NULL();
}
if (result == 2)
{
- lwerror("GEOSCrosses: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("GEOSCrosses");
PG_RETURN_NULL(); /* never get here */
}
GEOSGeometry *g = (GEOSGeometry *)POSTGIS2GEOS(geom2);
if ( 0 == g ) /* exception thrown at construction */
{
- lwerror("Geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("Geometry could not be converted to GEOS");
PG_RETURN_NULL();
}
result = GEOSPreparedIntersects( prep_cache->prepared_geom, g);
GEOSGeometry *g = (GEOSGeometry *)POSTGIS2GEOS(geom1);
if ( 0 == g ) /* exception thrown at construction */
{
- lwerror("Geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("Geometry could not be converted to GEOS");
PG_RETURN_NULL();
}
result = GEOSPreparedIntersects( prep_cache->prepared_geom, g);
g1 = (GEOSGeometry *)POSTGIS2GEOS(geom1);
if ( 0 == g1 ) /* exception thrown at construction */
{
- lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
PG_RETURN_NULL();
}
g2 = (GEOSGeometry *)POSTGIS2GEOS(geom2);
if ( 0 == g2 ) /* exception thrown at construction */
{
- lwerror("Second argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("Second argument geometry could not be converted to GEOS");
GEOSGeom_destroy(g1);
PG_RETURN_NULL();
}
if (result == 2)
{
- lwerror("GEOSIntersects: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("GEOSIntersects");
PG_RETURN_NULL(); /* never get here */
}
g1 = (GEOSGeometry *)POSTGIS2GEOS(geom1 );
if ( 0 == g1 ) /* exception thrown at construction */
{
- lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
PG_RETURN_NULL();
}
g2 = (GEOSGeometry *)POSTGIS2GEOS(geom2 );
if ( 0 == g2 ) /* exception thrown at construction */
{
- lwerror("Second argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("Second argument geometry could not be converted to GEOS");
GEOSGeom_destroy(g1);
PG_RETURN_NULL();
}
if (result == 2)
{
- lwerror("GEOSTouches: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("GEOSTouches");
PG_RETURN_NULL(); /* never get here */
}
g1 = (GEOSGeometry *)POSTGIS2GEOS(geom1);
if ( 0 == g1 ) /* exception thrown at construction */
{
- lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
PG_RETURN_NULL();
}
g2 = (GEOSGeometry *)POSTGIS2GEOS(geom2);
if ( 0 == g2 ) /* exception thrown at construction */
{
- lwerror("Second argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("Second argument geometry could not be converted to GEOS");
GEOSGeom_destroy(g1);
PG_RETURN_NULL();
}
if (result == 2)
{
- lwerror("GEOSDisjoint: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("GEOSDisjoint");
PG_RETURN_NULL(); /* never get here */
}
g1 = (GEOSGeometry *)POSTGIS2GEOS(geom1);
if ( 0 == g1 ) /* exception thrown at construction */
{
- lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
PG_RETURN_NULL();
}
g2 = (GEOSGeometry *)POSTGIS2GEOS(geom2);
if ( 0 == g2 ) /* exception thrown at construction */
{
- lwerror("Second argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("Second argument geometry could not be converted to GEOS");
GEOSGeom_destroy(g1);
PG_RETURN_NULL();
}
if (result == 2)
{
- lwerror("GEOSRelatePattern: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("GEOSRelatePattern");
PG_RETURN_NULL(); /* never get here */
}
g1 = (GEOSGeometry *)POSTGIS2GEOS(geom1 );
if ( 0 == g1 ) /* exception thrown at construction */
{
- lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
PG_RETURN_NULL();
}
g2 = (GEOSGeometry *)POSTGIS2GEOS(geom2 );
if ( 0 == g2 ) /* exception thrown at construction */
{
- lwerror("Second argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("Second argument geometry could not be converted to GEOS");
GEOSGeom_destroy(g1);
PG_RETURN_NULL();
}
if (relate_str == NULL)
{
- lwerror("GEOSRelate: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("GEOSRelate");
PG_RETURN_NULL(); /* never get here */
}
if ( 0 == g1 ) /* exception thrown at construction */
{
- lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
PG_RETURN_NULL();
}
if ( 0 == g2 ) /* exception thrown at construction */
{
- lwerror("Second argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("Second argument geometry could not be converted to GEOS");
GEOSGeom_destroy(g1);
PG_RETURN_NULL();
}
if (result == 2)
{
- lwerror("GEOSEquals: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("GEOSEquals");
PG_RETURN_NULL(); /*never get here */
}
g1 = (GEOSGeometry *)POSTGIS2GEOS(geom);
if ( 0 == g1 ) /* exception thrown at construction */
{
- lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
PG_RETURN_NULL();
}
result = GEOSisSimple(g1);
if (result == 2)
{
- lwerror("GEOSisSimple: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("GEOSisSimple");
PG_RETURN_NULL(); /*never get here */
}
g1 = (GEOSGeometry *)POSTGIS2GEOS(geom );
if ( 0 == g1 ) /* exception thrown at construction */
{
- lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
PG_RETURN_NULL();
}
result = GEOSisRing(g1);
if (result == 2)
{
- lwerror("GEOSisRing: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("GEOSisRing");
PG_RETURN_NULL();
}
g = (GEOSGeometry *)POSTGIS2GEOS(geom);
if ( 0 == g ) /* exception thrown at construction */
{
- lwerror("Geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("Geometry could not be converted to GEOS");
PG_RETURN_NULL();
}
vgeoms[i] = g;
if ( 0 == g1 ) /* exception thrown at construction */
{
- lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
+ HANDLE_GEOS_ERROR("First argument geometry could not be converted to GEOS");
PG_RETURN_NULL();
}