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

Definition at line 1045 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().

1046 {
1047 #if POSTGIS_GEOS_VERSION < 35
1048  lwerror("The GEOS version this postgis binary "
1049  "was compiled against (%d) doesn't support "
1050  "'GEOSClipByRect' function (3.5.0+ required)",
1052  return NULL;
1053 #else /* POSTGIS_GEOS_VERSION >= 35 */
1054  LWGEOM *result ;
1055  GEOSGeometry *g1, *g3 ;
1056  int is3d ;
1057 
1058  /* A.Intersection(Empty) == Empty */
1059  if ( lwgeom_is_empty(geom1) )
1060  return lwgeom_clone_deep(geom1);
1061 
1062  is3d = FLAGS_GET_Z(geom1->flags);
1063 
1064  initGEOS(lwnotice, lwgeom_geos_error);
1065 
1066  LWDEBUG(3, "clip_by_rect() START");
1067 
1068  g1 = LWGEOM2GEOS(geom1, 1); /* auto-fix structure */
1069  if ( 0 == g1 ) /* exception thrown at construction */
1070  {
1071  lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
1072  return NULL ;
1073  }
1074 
1075  LWDEBUG(3, " constructed geometrys - calling geos");
1076  LWDEBUGF(3, " g1 = %s", GEOSGeomToWKT(g1));
1077  /*LWDEBUGF(3, "g1 is valid = %i",GEOSisvalid(g1)); */
1078 
1079  g3 = GEOSClipByRect(g1,x0,y0,x1,y1);
1080  GEOSGeom_destroy(g1);
1081 
1082  LWDEBUG(3, " clip_by_rect finished");
1083 
1084  if (g3 == NULL)
1085  {
1086  lwnotice("Error performing rectangular clipping: %s", lwgeom_geos_errmsg);
1087  return NULL;
1088  }
1089 
1090  LWDEBUGF(3, "result: %s", GEOSGeomToWKT(g3) ) ;
1091 
1092  result = GEOS2LWGEOM(g3, is3d);
1093  GEOSGeom_destroy(g3);
1094 
1095  if (result == NULL)
1096  {
1097  lwerror("Error performing intersection: GEOS2LWGEOM: %s", lwgeom_geos_errmsg);
1098  return NULL ; /* never get here */
1099  }
1100 
1101  result->srid = geom1->srid;
1102 
1103  return result ;
1104 #endif /* POSTGIS_GEOS_VERSION >= 35 */
1105 }
#define POSTGIS_GEOS_VERSION
Definition: sqldefines.h:10
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
Definition: lwutil.c:89
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:446
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:1310
#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:102

Here is the call graph for this function:

Here is the caller graph for this function: