/* efficient way to do this? */
LWGEOM *clipped = lwgeom_clip_by_rect(geom, clip->xmin, clip->ymin, clip->xmax, clip->ymax);
/* Hm, clipping left nothing behind, skip it */
- if ( lwgeom_is_empty(clipped) )
+ if ( (!clipped) || lwgeom_is_empty(clipped) )
{
return 0;
}
{
LWGEOM *clipped = lwgeom_clip_by_rect(geom, clip->xmin, clip->ymin, clip->xmax, clip->ymax);
/* Hm, clipping left nothing behind, skip it */
- if ( lwgeom_is_empty(clipped) )
+ if ( (!clipped) || lwgeom_is_empty(clipped) )
{
return 0;
}
if (g3 == NULL)
{
- lwerror("Error performing rectangular clipping: %s",
- lwgeom_geos_errmsg);
- return NULL; /* never get here */
+ lwnotice("Error performing rectangular clipping: %s", lwgeom_geos_errmsg);
+ return NULL;
}
LWDEBUGF(3, "result: %s", GEOSGeomToWKT(g3) ) ;
if (result == NULL)
{
- lwerror("Error performing intersection: GEOS2LWGEOM: %s",
- lwgeom_geos_errmsg);
+ lwerror("Error performing intersection: GEOS2LWGEOM: %s", lwgeom_geos_errmsg);
return NULL ; /* never get here */
}
GSERIALIZED *result;
LWGEOM *lwgeom1, *lwresult ;
const GBOX *bbox1;
- const GBOX *bbox2;
+ GBOX *bbox2;
geom1 = PG_GETARG_GSERIALIZED_P(0);
lwgeom1 = lwgeom_from_gserialized(geom1) ;
/* WARNING: this is really a BOX2DF, use only xmin and ymin fields */
bbox2 = (GBOX *)PG_GETARG_POINTER(1);
+ bbox2->flags = 0;
/* If bbox1 outside of bbox2, return empty */
- if ( bbox1->xmin > bbox2->xmax || bbox1->xmax < bbox2->xmin ||
- bbox1->ymin > bbox2->ymax || bbox1->ymax < bbox2->ymin )
+ if ( ! gbox_overlaps_2d(bbox1, bbox2) )
{
lwresult = lwgeom_construct_empty(lwgeom1->type, lwgeom1->srid, 0, 0);
lwgeom_free(lwgeom1);
}
/* if bbox1 is covered by bbox2, return lwgeom1 */
- if ( bbox1->xmax <= bbox2->xmax && bbox1->xmin >= bbox2->xmin &&
- bbox1->ymax <= bbox2->ymax && bbox1->ymin >= bbox2->ymin )
+ if ( gbox_contains_2d(bbox2, bbox1) )
{
lwgeom_free(lwgeom1);
PG_RETURN_POINTER(geom1);
lwresult = lwgeom_clip_by_rect(lwgeom1, bbox2->xmin, bbox2->ymin,
bbox2->xmax, bbox2->ymax);
- lwgeom_free(lwgeom1) ;
-
- result = geometry_serialize(lwresult) ;
- lwgeom_free(lwresult) ;
+ lwgeom_free(lwgeom1);
PG_FREE_IF_COPY(geom1, 0);
+ if ( lwresult == NULL )
+ PG_RETURN_NULL();
+
+ result = geometry_serialize(lwresult) ;
+ lwgeom_free(lwresult) ;
PG_RETURN_POINTER(result);
+
#endif /* POSTGIS_GEOS_VERSION >= 35 */
}