PostGIS  2.5.0dev-r@@SVN_REVISION@@
void lwgeom_simplify_in_place ( LWGEOM igeom,
double  dist,
int  preserve_collapsed 
)

Definition at line 1741 of file lwgeom.c.

References COLLECTIONTYPE, LWCOLLECTION::geoms, getPoint2d_cp(), LINETYPE, lwerror(), lwgeom_free(), lwgeom_is_empty(), lwtype_name(), POINTARRAY::maxpoints, MULTILINETYPE, MULTIPOINTTYPE, MULTIPOLYGONTYPE, LWCOLLECTION::ngeoms, POINTARRAY::npoints, LWPOLY::nrings, p2d_same(), LWLINE::points, POINTTYPE, POLYGONTYPE, ptarray_copy_point(), ptarray_free(), ptarray_simplify_in_place(), LWPOLY::rings, and LWGEOM::type.

Referenced by lwgeom_simplify(), and mvt_geom().

1742 {
1743  switch (geom->type)
1744  {
1745  /* No-op! Cannot simplify points */
1746  case POINTTYPE:
1747  return;
1748  case LINETYPE:
1749  {
1750  LWLINE *g = (LWLINE*)(geom);
1751  POINTARRAY *pa = g->points;
1752  ptarray_simplify_in_place(pa, epsilon, 2);
1753  /* Invalid output */
1754  if (pa->npoints == 1 && pa->maxpoints > 1)
1755  {
1756  /* Use first point as last point */
1757  if (preserve_collapsed)
1758  {
1759  pa->npoints = 2;
1760  ptarray_copy_point(pa, 0, 1);
1761  }
1762  /* Finish the collapse process */
1763  else
1764  {
1765  pa->npoints = 0;
1766  }
1767  }
1768  /* Duped output, force collapse */
1769  if (pa->npoints == 2 && !preserve_collapsed)
1770  {
1771  if (p2d_same(getPoint2d_cp(pa, 0), getPoint2d_cp(pa, 1)))
1772  pa->npoints = 0;
1773  }
1774  break;
1775  }
1776  case POLYGONTYPE:
1777  {
1778  uint32_t i, j = 0;
1779  LWPOLY *g = (LWPOLY*)(geom);
1780  for (i = 0; i < g->nrings; i++)
1781  {
1782  POINTARRAY *pa = g->rings[i];
1783  /* Only stop collapse on first ring */
1784  int minpoints = (preserve_collapsed && i == 0) ? 4 : 0;
1785  /* Skip zero'ed out rings */
1786  if(!pa)
1787  continue;
1788  ptarray_simplify_in_place(pa, epsilon, minpoints);
1789  /* Drop collapsed rings */
1790  if(pa->npoints < 4)
1791  {
1792  ptarray_free(pa);
1793  continue;
1794  }
1795  g->rings[j++] = pa;
1796  }
1797  /* Update ring count */
1798  g->nrings = j;
1799  break;
1800  }
1801  /* Can process all multi* types as generic collection */
1802  case MULTIPOINTTYPE:
1803  case MULTILINETYPE:
1804  case MULTIPOLYGONTYPE:
1805  case COLLECTIONTYPE:
1806  {
1807  uint32_t i, j = 0;
1808  LWCOLLECTION *col = (LWCOLLECTION*)geom;
1809  for (i = 0; i < col->ngeoms; i++)
1810  {
1811  LWGEOM *g = col->geoms[i];
1812  if (!g) continue;
1813  lwgeom_simplify_in_place(g, epsilon, preserve_collapsed);
1814  /* Drop zero'ed out geometries */
1815  if(lwgeom_is_empty(g))
1816  {
1817  lwgeom_free(g);
1818  continue;
1819  }
1820  col->geoms[j++] = g;
1821  }
1822  /* Update geometry count */
1823  col->ngeoms = j;
1824  break;
1825  }
1826  default:
1827  {
1828  lwerror("%s: unsupported geometry type: %s", __func__, lwtype_name(geom->type));
1829  break;
1830  }
1831  }
1832  return;
1833 }
#define LINETYPE
Definition: liblwgeom.h:85
#define POLYGONTYPE
Definition: liblwgeom.h:86
void ptarray_copy_point(POINTARRAY *pa, uint32_t from, uint32_t to)
Definition: lwgeom_api.c:450
void ptarray_free(POINTARRAY *pa)
Definition: ptarray.c:328
#define MULTIPOINTTYPE
Definition: liblwgeom.h:87
uint32_t maxpoints
Definition: liblwgeom.h:371
uint32_t ngeoms
Definition: liblwgeom.h:506
uint32_t nrings
Definition: liblwgeom.h:454
void ptarray_simplify_in_place(POINTARRAY *pa, double epsilon, uint32_t minpts)
Definition: ptarray.c:1569
unsigned int uint32_t
Definition: uthash.h:78
int p2d_same(const POINT2D *p1, const POINT2D *p2)
Definition: lwalgorithm.c:49
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:218
LWGEOM ** geoms
Definition: liblwgeom.h:508
POINTARRAY ** rings
Definition: liblwgeom.h:456
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 MULTIPOLYGONTYPE
Definition: liblwgeom.h:89
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:84
void lwgeom_simplify_in_place(LWGEOM *geom, double epsilon, int preserve_collapsed)
Definition: lwgeom.c:1741
void lwgeom_free(LWGEOM *lwgeom)
Definition: lwgeom.c:1137
#define MULTILINETYPE
Definition: liblwgeom.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
const POINT2D * getPoint2d_cp(const POINTARRAY *pa, uint32_t n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from...
Definition: lwgeom_api.c:364
POINTARRAY * points
Definition: liblwgeom.h:421
uint32_t npoints
Definition: liblwgeom.h:370

Here is the call graph for this function:

Here is the caller graph for this function: