PostGIS  2.5.0dev-r@@SVN_REVISION@@
LWGEOM* lwgeom_segmentize_sphere ( const LWGEOM lwg_in,
double  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.

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 1652 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().

1653 {
1654  POINTARRAY *pa_out;
1655  LWLINE *lwline;
1656  LWPOLY *lwpoly_in, *lwpoly_out;
1657  LWCOLLECTION *lwcol_in, *lwcol_out;
1658  uint32_t i;
1660  /* Reflect NULL */
1661  if ( ! lwg_in )
1662  return NULL;
1664  /* Clone empty */
1665  if ( lwgeom_is_empty(lwg_in) )
1666  return lwgeom_clone(lwg_in);
1668  switch (lwg_in->type)
1669  {
1671  case POINTTYPE:
1672  return lwgeom_clone_deep(lwg_in);
1673  break;
1674  case LINETYPE:
1675  lwline = lwgeom_as_lwline(lwg_in);
1676  pa_out = ptarray_segmentize_sphere(lwline->points, max_seg_length);
1677  return lwline_as_lwgeom(lwline_construct(lwg_in->srid, NULL, pa_out));
1678  break;
1679  case POLYGONTYPE:
1680  lwpoly_in = lwgeom_as_lwpoly(lwg_in);
1681  lwpoly_out = lwpoly_construct_empty(lwg_in->srid, lwgeom_has_z(lwg_in), lwgeom_has_m(lwg_in));
1682  for ( i = 0; i < lwpoly_in->nrings; i++ )
1683  {
1684  pa_out = ptarray_segmentize_sphere(lwpoly_in->rings[i], max_seg_length);
1685  lwpoly_add_ring(lwpoly_out, pa_out);
1686  }
1687  return lwpoly_as_lwgeom(lwpoly_out);
1688  break;
1692  lwcol_in = lwgeom_as_lwcollection(lwg_in);
1693  lwcol_out = lwcollection_construct_empty(lwg_in->type, lwg_in->srid, lwgeom_has_z(lwg_in), lwgeom_has_m(lwg_in));
1694  for ( i = 0; i < lwcol_in->ngeoms; i++ )
1695  {
1696  lwcollection_add_lwgeom(lwcol_out, lwgeom_segmentize_sphere(lwcol_in->geoms[i], max_seg_length));
1697  }
1698  return lwcollection_as_lwgeom(lwcol_out);
1699  break;
1700  default:
1701  lwerror("lwgeom_segmentize_sphere: unsupported input geometry type: %d - %s",
1702  lwg_in->type, lwtype_name(lwg_in->type));
1703  break;
1704  }
1706  lwerror("lwgeom_segmentize_sphere got to the end of the function, should not happen");
1707  return NULL;
1708 }
#define LINETYPE
Definition: liblwgeom.h:85
Definition: liblwgeom.h:86
Definition: liblwgeom.h:87
LWGEOM * lwgeom_clone_deep(const LWGEOM *lwgeom)
Deep clone an LWGEOM, everything is copied.
Definition: lwgeom.c:513
LWPOLY * lwgeom_as_lwpoly(const LWGEOM *lwgeom)
Definition: lwgeom.c:205
uint32_t ngeoms
Definition: liblwgeom.h:506
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
Definition: lwgeom.c:923
int32_t srid
Definition: liblwgeom.h:398
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
Definition: lwgeom.c:319
uint32_t nrings
Definition: liblwgeom.h:454
unsigned int uint32_t
Definition: uthash.h:78
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition: lwutil.c:218
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
Definition: lwgeom.c:329
LWLINE * lwline_construct(int srid, GBOX *bbox, POINTARRAY *points)
Definition: lwline.c:42
LWGEOM ** geoms
Definition: liblwgeom.h:508
Definition: liblwgeom.h:456
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:1593
LWGEOM * lwgeom_clone(const LWGEOM *lwgeom)
Clone LWGEOM object.
Definition: lwgeom.c:475
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:169
Definition: liblwgeom.h:89
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:1652
LWCOLLECTION * lwgeom_as_lwcollection(const LWGEOM *lwgeom)
Definition: lwgeom.c:223
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:84
LWPOLY * lwpoly_construct_empty(int srid, char hasz, char hasm)
Definition: lwpoly.c:159
uint8_t type
Definition: liblwgeom.h:395
int lwpoly_add_ring(LWPOLY *poly, POINTARRAY *pa)
Add a ring, allocating extra space if necessary.
Definition: lwpoly.c:245
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
Definition: liblwgeom.h:88
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int srid, char hasz, char hasm)
Definition: lwcollection.c:94
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
Definition: lwgeom.c:930
LWCOLLECTION * lwcollection_add_lwgeom(LWCOLLECTION *col, const LWGEOM *geom)
Appends geom to the collection managed by col.
Definition: lwcollection.c:187
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
Definition: liblwgeom.h:90
Definition: liblwgeom.h:421
LWGEOM * lwcollection_as_lwgeom(const LWCOLLECTION *obj)
Definition: lwgeom.c:299

Here is the call graph for this function:

Here is the caller graph for this function: