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

References LWGEOM::flags, FLAGS_GET_Z, GEOS2LWGEOM(), LWDEBUG, LWDEBUGF, lwerror(), LWGEOM2GEOS(), lwgeom_clone_deep(), lwgeom_geos_errmsg, lwgeom_geos_error(), lwgeom_is_empty(), lwnotice(), POSTGIS_GEOS_VERSION, and LWGEOM::srid.

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

966 {
967 #if POSTGIS_GEOS_VERSION < 35
968  lwerror("The GEOS version this postgis binary "
969  "was compiled against (%d) doesn't support "
970  "'GEOSClipByRect' function (3.5.0+ required)",
972  return NULL;
973 #else /* POSTGIS_GEOS_VERSION >= 35 */
974  LWGEOM *result ;
975  GEOSGeometry *g1, *g3 ;
976  int is3d ;
977 
978  /* A.Intersection(Empty) == Empty */
979  if ( lwgeom_is_empty(geom1) )
980  return lwgeom_clone_deep(geom1);
981 
982  is3d = FLAGS_GET_Z(geom1->flags);
983 
984  initGEOS(lwnotice, lwgeom_geos_error);
985 
986  LWDEBUG(3, "clip_by_rect() START");
987 
988  g1 = LWGEOM2GEOS(geom1, 1); /* auto-fix structure */
989  if ( 0 == g1 ) /* exception thrown at construction */
990  {
991  lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
992  return NULL ;
993  }
994 
995  LWDEBUG(3, " constructed geometrys - calling geos");
996  LWDEBUGF(3, " g1 = %s", GEOSGeomToWKT(g1));
997  /*LWDEBUGF(3, "g1 is valid = %i",GEOSisvalid(g1)); */
998 
999  g3 = GEOSClipByRect(g1,x0,y0,x1,y1);
1000  GEOSGeom_destroy(g1);
1001 
1002  LWDEBUG(3, " clip_by_rect finished");
1003 
1004  if (g3 == NULL)
1005  {
1006  lwnotice("Error performing rectangular clipping: %s", lwgeom_geos_errmsg);
1007  return NULL;
1008  }
1009 
1010  LWDEBUGF(3, "result: %s", GEOSGeomToWKT(g3) ) ;
1011 
1012  result = GEOS2LWGEOM(g3, is3d);
1013  GEOSGeom_destroy(g3);
1014 
1015  if (result == NULL)
1016  {
1017  lwerror("Error performing intersection: GEOS2LWGEOM: %s", lwgeom_geos_errmsg);
1018  return NULL ; /* never get here */
1019  }
1020 
1021  result->srid = geom1->srid;
1022 
1023  return result ;
1024 #endif /* POSTGIS_GEOS_VERSION >= 35 */
1025 }
#define POSTGIS_GEOS_VERSION
Definition: sqldefines.h:10
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
Definition: lwutil.c:61
uint8_t flags
Definition: liblwgeom.h:381
char lwgeom_geos_errmsg[LWGEOM_GEOS_ERRMSG_MAXSIZE]
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:50
LWGEOM * lwgeom_clone_deep(const LWGEOM *lwgeom)
Deep clone an LWGEOM, everything is copied.
Definition: lwgeom.c:433
int32_t srid
Definition: liblwgeom.h:383
void lwgeom_geos_error(const char *fmt,...)
#define FLAGS_GET_Z(flags)
Macros for manipulating the &#39;flags&#39; byte.
Definition: liblwgeom.h:124
GEOSGeometry * LWGEOM2GEOS(const LWGEOM *lwgeom, int autofix)
LWGEOM * GEOS2LWGEOM(const GEOSGeometry *geom, char want3d)
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:1297
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:55
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:74
Here is the call graph for this function:
Here is the caller graph for this function: