Clips an input geometry using GEOSIntersection It used to try to use GEOSClipByRect (as mvt_unsafe_clip_by_box) but since that produces invalid output when an invalid geometry is given and detecting it resulted to be impossible, we use intersection instead and, upon error, force validation of the input and retry.
884{
885 LWGEOM *geom_clipped, *envelope;
887 GEOSGeometry *geos_input, *geos_box, *geos_result;
888
892
894 {
895 POSTGIS_DEBUG(3, "mvt_geom: geometry outside clip box");
896 return NULL;
897 }
898
900 {
901 POSTGIS_DEBUG(3, "mvt_geom: geometry contained fully inside the box");
902 return lwg_in;
903 }
904
907 return NULL;
908
913 if (!geos_box)
914 {
915 GEOSGeom_destroy(geos_input);
916 return NULL;
917 }
918
919 geos_result = GEOSIntersection(geos_input, geos_box);
920 if (!geos_result)
921 {
922 POSTGIS_DEBUG(3, "mvt_geom: no geometry after intersection. Retrying after validation");
923 GEOSGeom_destroy(geos_input);
926 {
927 GEOSGeom_destroy(geos_box);
928 return NULL;
929 }
930 geos_result = GEOSIntersection(geos_input, geos_box);
931 if (!geos_result)
932 {
933 GEOSGeom_destroy(geos_box);
934 GEOSGeom_destroy(geos_input);
935 return NULL;
936 }
937 }
938
939 GEOSSetSRID(geos_result, lwg_in->
srid);
941
942 GEOSGeom_destroy(geos_box);
943 GEOSGeom_destroy(geos_input);
944 GEOSGeom_destroy(geos_result);
945
947 {
948 POSTGIS_DEBUG(3, "mvt_geom: no geometry after clipping");
949 return NULL;
950 }
951
952 return geom_clipped;
953}
int gbox_overlaps_2d(const GBOX *g1, const GBOX *g2)
Return LW_TRUE if the GBOX overlaps on the 2d plane, LW_FALSE otherwise.
void gbox_init(GBOX *gbox)
Zero out all the entries in the GBOX.
int gbox_contains_2d(const GBOX *g1, const GBOX *g2)
Return LW_TRUE if the first GBOX contains the second on the 2d plane, LW_FALSE otherwise.
GEOSGeometry * LWGEOM2GEOS(const LWGEOM *lwgeom, uint8_t autofix)
LWGEOM * GEOS2LWGEOM(const GEOSGeometry *geom, uint8_t want3d)
void lwgeom_geos_error(const char *fmt,...)
void lwgeom_free(LWGEOM *geom)
LWPOLY * lwpoly_construct_envelope(int32_t srid, double x1, double y1, double x2, double y2)
int lwgeom_calculate_gbox(const LWGEOM *lwgeom, GBOX *gbox)
Calculate bounding box of a geometry, automatically taking into account whether it is cartesian or ge...
#define FLAGS_SET_GEODETIC(flags, value)
LWGEOM * lwgeom_make_valid(LWGEOM *geom)
Attempts to make an invalid geometries valid w/out losing points.
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)