PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ lwgeom_wrapx()

LWGEOM* lwgeom_wrapx ( const LWGEOM lwgeom_in,
double  cutx,
double  amount 
)

wrap geometry on given cut x value

For a positive amount, shifts anything that is on the left of "cutx" to the right by the given amount.

For a negative amount, shifts anything that is on the right of "cutx" to the left by the given absolute amount.

Parameters
cutxthe X value to perform wrapping on
amountshift amount and wrapping direction

Definition at line 167 of file lwgeom_wrapx.c.

References COLLECTIONTYPE, getPoint4d_p(), LINETYPE, lwcollection_as_lwgeom(), lwcollection_wrapx(), LWDEBUG, LWDEBUGF, lwerror(), lwgeom_as_lwpoint(), lwgeom_clone_deep(), lwgeom_is_empty(), lwgeom_split_wrapx(), lwpoint_as_lwgeom(), lwtype_name(), MULTILINETYPE, MULTIPOINTTYPE, MULTIPOLYGONTYPE, LWPOINT::point, POINTTYPE, POLYGONTYPE, ptarray_set_point4d(), LWGEOM::type, LWCOLLECTION::type, and POINT4D::x.

Referenced by lwcollection_wrapx(), ST_WrapX(), and test_lwgeom_wrapx().

168 {
169  /* Nothing to wrap in an empty geom */
170  if ( lwgeom_is_empty(lwgeom_in) )
171  {
172  LWDEBUG(2, "geom is empty, cloning");
173  return lwgeom_clone_deep(lwgeom_in);
174  }
175 
176  /* Nothing to wrap if shift amount is zero */
177  if ( amount == 0 )
178  {
179  LWDEBUG(2, "amount is zero, cloning");
180  return lwgeom_clone_deep(lwgeom_in);
181  }
182 
183  switch (lwgeom_in->type)
184  {
185  case LINETYPE:
186  case POLYGONTYPE:
187  LWDEBUG(2, "split-wrapping line or polygon");
188  return lwgeom_split_wrapx(lwgeom_in, cutx, amount);
189 
190  case POINTTYPE:
191  {
192  const LWPOINT *pt = lwgeom_as_lwpoint(lwgeom_clone_deep(lwgeom_in));
193  POINT4D pt4d;
194  getPoint4d_p(pt->point, 0, &pt4d);
195 
196  LWDEBUGF(2, "POINT X is %g, cutx:%g, amount:%g", pt4d.x, cutx, amount);
197 
198  if ( ( amount < 0 && pt4d.x > cutx ) || ( amount > 0 && pt4d.x < cutx ) )
199  {
200  pt4d.x += amount;
201  ptarray_set_point4d(pt->point, 0, &pt4d);
202  }
203  return lwpoint_as_lwgeom(pt);
204  }
205 
206  case MULTIPOINTTYPE:
207  case MULTIPOLYGONTYPE:
208  case MULTILINETYPE:
209  case COLLECTIONTYPE:
210  LWDEBUG(2, "collection-wrapping multi");
211  return lwcollection_as_lwgeom(
212  lwcollection_wrapx((const LWCOLLECTION*)lwgeom_in, cutx, amount)
213  );
214 
215  default:
216  lwerror("Wrapping of %s geometries is unsupported",
217  lwtype_name(lwgeom_in->type));
218  return NULL;
219  }
220 
221 }
void ptarray_set_point4d(POINTARRAY *pa, int n, const POINT4D *p4d)
Definition: lwgeom_api.c:437
double x
Definition: liblwgeom.h:352
#define LINETYPE
Definition: liblwgeom.h:86
#define POLYGONTYPE
Definition: liblwgeom.h:87
#define MULTIPOINTTYPE
Definition: liblwgeom.h:88
#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
LWPOINT * lwgeom_as_lwpoint(const LWGEOM *lwgeom)
Definition: lwgeom.c:129
POINTARRAY * point
Definition: liblwgeom.h:411
static LWCOLLECTION * lwcollection_wrapx(const LWCOLLECTION *lwcoll_in, double cutx, double amount)
Definition: lwgeom_wrapx.c:121
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:218
static LWGEOM * lwgeom_split_wrapx(const LWGEOM *geom_in, double cutx, double amount)
Definition: lwgeom_wrapx.c:37
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:90
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:85
uint8_t type
Definition: liblwgeom.h:396
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
Definition: lwgeom.c:303
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 MULTILINETYPE
Definition: liblwgeom.h:89
#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
int getPoint4d_p(const POINTARRAY *pa, int n, POINT4D *point)
Definition: lwgeom_api.c:122
#define COLLECTIONTYPE
Definition: liblwgeom.h:91
LWGEOM * lwcollection_as_lwgeom(const LWCOLLECTION *obj)
Definition: lwgeom.c:268
Here is the call graph for this function:
Here is the caller graph for this function: