PostGIS  2.5.0dev-r@@SVN_REVISION@@
LWGEOM* lwgeom_clip_by_rect ( const LWGEOM geom1,
double  x0,
double  y0,
double  x1,
double  y1 
)

Definition at line 1069 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(), mvt_geom(), ST_ClipByBox2d(), and test_lwgeom_clip_by_rect().

1070 {
1071 #if POSTGIS_GEOS_VERSION < 35
1072  lwerror("The GEOS version this postgis binary "
1073  "was compiled against (%d) doesn't support "
1074  "'GEOSClipByRect' function (3.5.0+ required)",
1076  return NULL;
1077 #else /* POSTGIS_GEOS_VERSION >= 35 */
1078  LWGEOM *result ;
1079  GEOSGeometry *g1, *g3 ;
1080  int is3d ;
1081 
1082  /* A.Intersection(Empty) == Empty */
1083  if ( lwgeom_is_empty(geom1) )
1084  return lwgeom_clone_deep(geom1);
1085 
1086  is3d = FLAGS_GET_Z(geom1->flags);
1087 
1088  initGEOS(lwnotice, lwgeom_geos_error);
1089 
1090  LWDEBUG(3, "clip_by_rect() START");
1091 
1092  g1 = LWGEOM2GEOS(geom1, 1); /* auto-fix structure */
1093  if ( 0 == g1 ) /* exception thrown at construction */
1094  {
1095  lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
1096  return NULL ;
1097  }
1098 
1099  LWDEBUG(3, " constructed geometrys - calling geos");
1100  LWDEBUGF(3, " g1 = %s", GEOSGeomToWKT(g1));
1101  /*LWDEBUGF(3, "g1 is valid = %i",GEOSisvalid(g1)); */
1102 
1103  g3 = GEOSClipByRect(g1,x0,y0,x1,y1);
1104  GEOSGeom_destroy(g1);
1105 
1106  LWDEBUG(3, " clip_by_rect finished");
1107 
1108  if (g3 == NULL)
1109  {
1110  lwnotice("Error performing rectangular clipping: %s", lwgeom_geos_errmsg);
1111  return NULL;
1112  }
1113 
1114  LWDEBUGF(3, "result: %s", GEOSGeomToWKT(g3) ) ;
1115 
1116  result = GEOS2LWGEOM(g3, is3d);
1117  GEOSGeom_destroy(g3);
1118 
1119  if (result == NULL)
1120  {
1121  lwerror("Error performing intersection: GEOS2LWGEOM: %s", lwgeom_geos_errmsg);
1122  return NULL ; /* never get here */
1123  }
1124 
1125  result->srid = geom1->srid;
1126 
1127  return result ;
1128 #endif /* POSTGIS_GEOS_VERSION >= 35 */
1129 }
#define POSTGIS_GEOS_VERSION
Definition: sqldefines.h:10
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
Definition: lwutil.c:177
uint8_t flags
Definition: liblwgeom.h:396
char lwgeom_geos_errmsg[LWGEOM_GEOS_ERRMSG_MAXSIZE]
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
LWGEOM * lwgeom_clone_deep(const LWGEOM *lwgeom)
Deep clone an LWGEOM, everything is copied.
Definition: lwgeom.c:513
int32_t srid
Definition: liblwgeom.h:398
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, 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:1386
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190

Here is the call graph for this function:

Here is the caller graph for this function: