PostGIS  2.5.1dev-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 858 of file liblwgeom/lwgeom_geos.c.

References AUTOFIX, LWGEOM::flags, FLAGS_GET_Z, GEOS2LWGEOM(), GEOS_FAIL, GEOS_FREE, GEOS_FREE_AND_FAIL, LWGEOM2GEOS(), lwgeom_clone_deep(), lwgeom_geos_error(), lwgeom_is_empty(), lwnotice(), and LWGEOM::srid.

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

859 {
860  LWGEOM *result;
861  GEOSGeometry *g1, *g3;
862  int is3d;
863 
864  /* A.Intersection(Empty) == Empty */
865  if ( lwgeom_is_empty(geom1) )
866  return lwgeom_clone_deep(geom1);
867 
868  is3d = FLAGS_GET_Z(geom1->flags);
869 
870  initGEOS(lwnotice, lwgeom_geos_error);
871 
872  if (!(g1 = LWGEOM2GEOS(geom1, AUTOFIX)))
873  GEOS_FAIL();
874 
875  if (!(g3 = GEOSClipByRect(g1, x1, y1, x2, y2)))
876  GEOS_FREE_AND_FAIL(g1);
877 
878  GEOS_FREE(g1);
879  result = GEOS2LWGEOM(g3, is3d);
880  GEOS_FREE(g3);
881 
882  if (!result)
883  GEOS_FAIL();
884 
885  result->srid = geom1->srid;
886 
887  return result;
888 }
#define GEOS_FAIL()
LWGEOM * GEOS2LWGEOM(const GEOSGeometry *geom, uint8_t want3d)
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
Definition: lwutil.c:177
uint8_t flags
Definition: liblwgeom.h:399
#define GEOS_FREE_AND_FAIL(...)
#define GEOS_FREE(...)
LWGEOM * lwgeom_clone_deep(const LWGEOM *lwgeom)
Deep clone an LWGEOM, everything is copied.
Definition: lwgeom.c:520
int32_t srid
Definition: liblwgeom.h:401
#define AUTOFIX
void lwgeom_geos_error(const char *fmt,...)
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:139
GEOSGeometry * LWGEOM2GEOS(const LWGEOM *lwgeom, uint8_t autofix)
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members) ...
Definition: lwgeom.c:1393
Here is the call graph for this function:
Here is the caller graph for this function: