PostGIS  2.5.0beta2dev-r@@SVN_REVISION@@

◆ lwgeom_clip_by_rect()

LWGEOM* lwgeom_clip_by_rect ( const LWGEOM geom1,
double  x0,
double  y0,
double  x1,
double  y1 
)

Definition at line 947 of file liblwgeom/lwgeom_geos.c.

References COLLECTIONTYPE, LW_TRUE, lwcollection_as_lwgeom(), lwcollection_extract(), lwfree(), lwgeom_as_lwcollection(), lwgeom_dimension(), lwgeom_free(), lwgeom_intersection(), lwgeom_simplify_in_place(), lwpoly_construct_envelope(), LWGEOM::srid, and LWGEOM::type.

Referenced by lwgeom_subdivide_recursive(), mvt_geom(), ST_ClipByBox2d(), and test_lwgeom_clip_by_rect().

948 {
949  LWGEOM *result;
950  LWGEOM *tmp;
951 
952  /* This lwgeom_intersection should be a call to GEOSClipByRect:
953  * g3 = GEOSClipByRect(g1, x1, y1, x2, y2);
954  * Unfortunately as of GEOS 3.7 it chokes on practical inputs.
955  * GEOS ticket: https://trac.osgeo.org/geos/ticket/865
956  */
957 
958  LWGEOM *envelope = (LWGEOM *)lwpoly_construct_envelope(geom1->srid, x1, y1, x2, y2);
959  result = lwgeom_intersection(geom1, envelope);
960  lwgeom_free(envelope);
961 
962  if (!result) return NULL;
963 
964  /* clipping should not produce lower dimension objects */
965  if (
966  /* input has exact dimensionality, isn't a generic collection */
967  geom1->type != COLLECTIONTYPE &&
968  /* output may have different things inside */
969  result->type == COLLECTIONTYPE)
970  {
972  lwfree(result);
973  result = tmp;
974  if (!result) return NULL;
975  }
976 
977  /* clean up stray points on geometry boundary */
978  lwgeom_simplify_in_place(result, 0.0, LW_TRUE);
979 
980  return result;
981 }
LWCOLLECTION * lwcollection_extract(LWCOLLECTION *col, int type)
Takes a potentially heterogeneous collection and returns a homogeneous collection consisting only of ...
Definition: lwcollection.c:386
void lwfree(void *mem)
Definition: lwutil.c:244
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1144
int32_t srid
Definition: liblwgeom.h:401
LWGEOM * lwgeom_intersection(const LWGEOM *geom1, const LWGEOM *geom2)
void lwgeom_simplify_in_place(LWGEOM *igeom, double dist, int preserve_collapsed)
Definition: lwgeom.c:1748
LWPOLY * lwpoly_construct_envelope(int srid, double x1, double y1, double x2, double y2)
Definition: lwpoly.c:98
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:75
LWCOLLECTION * lwgeom_as_lwcollection(const LWGEOM *lwgeom)
Definition: lwgeom.c:224
int lwgeom_dimension(const LWGEOM *geom)
For an LWGEOM, returns 0 for points, 1 for lines, 2 for polygons, 3 for volume, and the max dimension...
Definition: lwgeom.c:1287
uint8_t type
Definition: liblwgeom.h:398
#define COLLECTIONTYPE
Definition: liblwgeom.h:90
LWGEOM * lwcollection_as_lwgeom(const LWCOLLECTION *obj)
Definition: lwgeom.c:300
Here is the call graph for this function:
Here is the caller graph for this function: