PostGIS  2.1.10dev-r@@SVN_REVISION@@
LWGEOM* lwgeom_segmentize_sphere ( const LWGEOM lwg_in,
double  max_seg_length 

Create a new, densified geometry where no segment is longer than max_seg_length.

Derive a new geometry with vertices added to ensure no vertex is more than max_seg_length (in radians) from any other vertex.

Input geometry is not altered, output geometry must be freed by caller.

lwg_in= input geometry
max_seg_length= maximum segment length in radians

Definition at line 1638 of file lwgeodetic.c.

References COLLECTIONTYPE, LWCOLLECTION::geoms, LINETYPE, lwcollection_add_lwgeom(), lwcollection_as_lwgeom(), lwcollection_construct_empty(), lwerror(), lwgeom_as_lwcollection(), lwgeom_as_lwline(), lwgeom_as_lwpoly(), lwgeom_clone(), lwgeom_clone_deep(), lwgeom_has_m(), lwgeom_has_z(), lwgeom_is_empty(), lwline_as_lwgeom(), lwline_construct(), lwpoly_add_ring(), lwpoly_as_lwgeom(), lwpoly_construct_empty(), lwtype_name(), MULTILINETYPE, MULTIPOINTTYPE, MULTIPOLYGONTYPE, LWCOLLECTION::ngeoms, LWPOLY::nrings, LWLINE::points, POINTTYPE, POLYGONTYPE, ptarray_segmentize_sphere(), LWPOLY::rings, LWGEOM::srid, and LWGEOM::type.

Referenced by geography_segmentize(), and test_lwgeom_segmentize_sphere().

1639 {
1640  POINTARRAY *pa_out;
1641  LWLINE *lwline;
1642  LWPOLY *lwpoly_in, *lwpoly_out;
1643  LWCOLLECTION *lwcol_in, *lwcol_out;
1644  int i;
1646  /* Reflect NULL */
1647  if ( ! lwg_in )
1648  return NULL;
1650  /* Clone empty */
1651  if ( lwgeom_is_empty(lwg_in) )
1652  return lwgeom_clone(lwg_in);
1654  switch (lwg_in->type)
1655  {
1657  case POINTTYPE:
1658  return lwgeom_clone_deep(lwg_in);
1659  break;
1660  case LINETYPE:
1661  lwline = lwgeom_as_lwline(lwg_in);
1662  pa_out = ptarray_segmentize_sphere(lwline->points, max_seg_length);
1663  return lwline_as_lwgeom(lwline_construct(lwg_in->srid, NULL, pa_out));
1664  break;
1665  case POLYGONTYPE:
1666  lwpoly_in = lwgeom_as_lwpoly(lwg_in);
1667  lwpoly_out = lwpoly_construct_empty(lwg_in->srid, lwgeom_has_z(lwg_in), lwgeom_has_m(lwg_in));
1668  for ( i = 0; i < lwpoly_in->nrings; i++ )
1669  {
1670  pa_out = ptarray_segmentize_sphere(lwpoly_in->rings[i], max_seg_length);
1671  lwpoly_add_ring(lwpoly_out, pa_out);
1672  }
1673  return lwpoly_as_lwgeom(lwpoly_out);
1674  break;
1678  lwcol_in = lwgeom_as_lwcollection(lwg_in);
1679  lwcol_out = lwcollection_construct_empty(lwg_in->type, lwg_in->srid, lwgeom_has_z(lwg_in), lwgeom_has_m(lwg_in));
1680  for ( i = 0; i < lwcol_in->ngeoms; i++ )
1681  {
1682  lwcollection_add_lwgeom(lwcol_out, lwgeom_segmentize_sphere(lwcol_in->geoms[i], max_seg_length));
1683  }
1684  return lwcollection_as_lwgeom(lwcol_out);
1685  break;
1686  default:
1687  lwerror("lwgeom_segmentize_sphere: unsupported input geometry type: %d - %s",
1688  lwg_in->type, lwtype_name(lwg_in->type));
1689  break;
1690  }
1692  lwerror("lwgeom_segmentize_sphere got to the end of the function, should not happen");
1693  return NULL;
1694 }
#define LINETYPE
Definition: liblwgeom.h:61
Definition: liblwgeom.h:62
Definition: liblwgeom.h:63
LWGEOM * lwgeom_clone_deep(const LWGEOM *lwgeom)
Deep clone an LWGEOM, everything is copied.
Definition: lwgeom.c:389
LWPOLY * lwgeom_as_lwpoly(const LWGEOM *lwgeom)
Definition: lwgeom.c:125
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
Definition: lwgeom.c:792
int32_t srid
Definition: liblwgeom.h:355
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
Definition: lwgeom.c:239
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:67
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:164
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
Definition: lwgeom.c:249
LWLINE * lwline_construct(int srid, GBOX *bbox, POINTARRAY *points)
Definition: lwline.c:29
LWGEOM ** geoms
Definition: liblwgeom.h:465
Definition: liblwgeom.h:413
static POINTARRAY * ptarray_segmentize_sphere(const POINTARRAY *pa_in, double max_seg_length)
Create a new point array with no segment longer than the input segment length (expressed in radians!)...
Definition: lwgeodetic.c:1530
int nrings
Definition: liblwgeom.h:411
LWGEOM * lwgeom_clone(const LWGEOM *lwgeom)
Clone LWGEOM object.
Definition: lwgeom.c:351
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:89
Definition: liblwgeom.h:65
LWGEOM * lwgeom_segmentize_sphere(const LWGEOM *lwg_in, double max_seg_length)
Create a new, densified geometry where no segment is longer than max_seg_length.
Definition: lwgeodetic.c:1638
LWCOLLECTION * lwgeom_as_lwcollection(const LWGEOM *lwgeom)
Definition: lwgeom.c:143
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:60
LWPOLY * lwpoly_construct_empty(int srid, char hasz, char hasm)
Definition: lwpoly.c:66
uint8_t type
Definition: liblwgeom.h:352
int lwpoly_add_ring(LWPOLY *poly, POINTARRAY *pa)
Add a ring, allocating extra space if necessary.
Definition: lwpoly.c:154
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:1229
Definition: liblwgeom.h:64
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int srid, char hasz, char hasm)
Definition: lwcollection.c:81
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
Definition: lwgeom.c:799
LWCOLLECTION * lwcollection_add_lwgeom(LWCOLLECTION *col, const LWGEOM *geom)
Appends geom to the collection managed by col.
Definition: lwcollection.c:174
Definition: liblwgeom.h:66
Definition: liblwgeom.h:378
LWGEOM * lwcollection_as_lwgeom(const LWCOLLECTION *obj)
Definition: lwgeom.c:219

Here is the call graph for this function:

Here is the caller graph for this function: