PostGIS  2.4.9dev-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 1074 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().

1075 {
1076 #if POSTGIS_GEOS_VERSION < 35
1077  lwerror("The GEOS version this postgis binary "
1078  "was compiled against (%d) doesn't support "
1079  "'GEOSClipByRect' function (3.5.0+ required)",
1081  return NULL;
1082 #else /* POSTGIS_GEOS_VERSION >= 35 */
1083  LWGEOM *result ;
1084  GEOSGeometry *g1, *g3 ;
1085  int is3d ;
1086 
1087  /* A.Intersection(Empty) == Empty */
1088  if ( lwgeom_is_empty(geom1) )
1089  return lwgeom_clone_deep(geom1);
1090 
1091  is3d = FLAGS_GET_Z(geom1->flags);
1092 
1093  initGEOS(lwnotice, lwgeom_geos_error);
1094 
1095  LWDEBUG(3, "clip_by_rect() START");
1096 
1097  g1 = LWGEOM2GEOS(geom1, 1); /* auto-fix structure */
1098  if ( 0 == g1 ) /* exception thrown at construction */
1099  {
1100  lwerror("First argument geometry could not be converted to GEOS: %s", lwgeom_geos_errmsg);
1101  return NULL ;
1102  }
1103 
1104  LWDEBUG(3, " constructed geometrys - calling geos");
1105  LWDEBUGF(3, " g1 = %s", GEOSGeomToWKT(g1));
1106  /*LWDEBUGF(3, "g1 is valid = %i",GEOSisvalid(g1)); */
1107 
1108  g3 = GEOSClipByRect(g1,x0,y0,x1,y1);
1109  GEOSGeom_destroy(g1);
1110 
1111  LWDEBUG(3, " clip_by_rect finished");
1112 
1113  if (g3 == NULL)
1114  {
1115  lwnotice("Error performing rectangular clipping: %s", lwgeom_geos_errmsg);
1116  return NULL;
1117  }
1118 
1119  LWDEBUGF(3, "result: %s", GEOSGeomToWKT(g3) ) ;
1120 
1121  result = GEOS2LWGEOM(g3, is3d);
1122  GEOSGeom_destroy(g3);
1123 
1124  if (result == NULL)
1125  {
1126  lwerror("Error performing intersection: GEOS2LWGEOM: %s", lwgeom_geos_errmsg);
1127  return NULL ; /* never get here */
1128  }
1129 
1130  result->srid = geom1->srid;
1131 
1132  return result ;
1133 #endif /* POSTGIS_GEOS_VERSION >= 35 */
1134 }
#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:397
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:482
int32_t srid
Definition: liblwgeom.h:399
void lwgeom_geos_error(const char *fmt,...)
#define FLAGS_GET_Z(flags)
Macros for manipulating the &#39;flags&#39; byte.
Definition: liblwgeom.h:140
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:1346
#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: