PostGIS  2.5.1dev-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 169 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().

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