PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ lwgeom_segmentize_sphere()

LWGEOM * lwgeom_segmentize_sphere ( const LWGEOM lwg_in,
double  max_seg_length 
)
extern

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.

Parameters
lwg_in= input geometry
max_seg_length= maximum segment length in radians

Definition at line 1743 of file lwgeodetic.c.

1744{
1745 POINTARRAY *pa_out;
1746 LWLINE *lwline;
1747 LWPOLY *lwpoly_in, *lwpoly_out;
1748 LWCOLLECTION *lwcol_in, *lwcol_out;
1749 uint32_t i;
1750
1751 /* Reflect NULL */
1752 if ( ! lwg_in )
1753 return NULL;
1754
1755 /* Clone empty */
1756 if ( lwgeom_is_empty(lwg_in) )
1757 return lwgeom_clone(lwg_in);
1758
1759 switch (lwg_in->type)
1760 {
1761 case MULTIPOINTTYPE:
1762 case POINTTYPE:
1763 return lwgeom_clone_deep(lwg_in);
1764 break;
1765 case LINETYPE:
1766 lwline = lwgeom_as_lwline(lwg_in);
1767 pa_out = ptarray_segmentize_sphere(lwline->points, max_seg_length);
1768 return lwline_as_lwgeom(lwline_construct(lwg_in->srid, NULL, pa_out));
1769 break;
1770 case POLYGONTYPE:
1771 lwpoly_in = lwgeom_as_lwpoly(lwg_in);
1772 lwpoly_out = lwpoly_construct_empty(lwg_in->srid, lwgeom_has_z(lwg_in), lwgeom_has_m(lwg_in));
1773 for ( i = 0; i < lwpoly_in->nrings; i++ )
1774 {
1775 pa_out = ptarray_segmentize_sphere(lwpoly_in->rings[i], max_seg_length);
1776 lwpoly_add_ring(lwpoly_out, pa_out);
1777 }
1778 return lwpoly_as_lwgeom(lwpoly_out);
1779 break;
1780 case MULTILINETYPE:
1781 case MULTIPOLYGONTYPE:
1782 case COLLECTIONTYPE:
1783 lwcol_in = lwgeom_as_lwcollection(lwg_in);
1784 lwcol_out = lwcollection_construct_empty(lwg_in->type, lwg_in->srid, lwgeom_has_z(lwg_in), lwgeom_has_m(lwg_in));
1785 for ( i = 0; i < lwcol_in->ngeoms; i++ )
1786 {
1787 lwcollection_add_lwgeom(lwcol_out, lwgeom_segmentize_sphere(lwcol_in->geoms[i], max_seg_length));
1788 }
1789 return lwcollection_as_lwgeom(lwcol_out);
1790 break;
1791 default:
1792 lwerror("lwgeom_segmentize_sphere: unsupported input geometry type: %d - %s",
1793 lwg_in->type, lwtype_name(lwg_in->type));
1794 break;
1795 }
1796
1797 lwerror("lwgeom_segmentize_sphere got to the end of the function, should not happen");
1798 return NULL;
1799}
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
Definition lwutil.c:216
#define COLLECTIONTYPE
Definition liblwgeom.h:122
#define MULTILINETYPE
Definition liblwgeom.h:120
#define LINETYPE
Definition liblwgeom.h:117
LWCOLLECTION * lwgeom_as_lwcollection(const LWGEOM *lwgeom)
Definition lwgeom.c:215
#define MULTIPOINTTYPE
Definition liblwgeom.h:119
int lwpoly_add_ring(LWPOLY *poly, POINTARRAY *pa)
Add a ring, allocating extra space if necessary.
Definition lwpoly.c:247
LWGEOM * lwgeom_clone(const LWGEOM *lwgeom)
Clone LWGEOM object.
Definition lwgeom.c:473
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
Definition lwgeom.c:916
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition liblwgeom.h:116
LWPOLY * lwgeom_as_lwpoly(const LWGEOM *lwgeom)
Definition lwgeom.c:197
LWLINE * lwline_construct(int32_t srid, GBOX *bbox, POINTARRAY *points)
Definition lwline.c:42
#define MULTIPOLYGONTYPE
Definition liblwgeom.h:121
#define POLYGONTYPE
Definition liblwgeom.h:118
LWGEOM * lwline_as_lwgeom(const LWLINE *obj)
Definition lwgeom.c:321
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition lwgeom.c:161
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int32_t srid, char hasz, char hasm)
LWCOLLECTION * lwcollection_add_lwgeom(LWCOLLECTION *col, const LWGEOM *geom)
Appends geom to the collection managed by col.
LWPOLY * lwpoly_construct_empty(int32_t srid, char hasz, char hasm)
Definition lwpoly.c:161
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
Definition lwgeom.c:923
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
Definition lwgeom.c:311
LWGEOM * lwcollection_as_lwgeom(const LWCOLLECTION *obj)
Definition lwgeom.c:291
LWGEOM * lwgeom_clone_deep(const LWGEOM *lwgeom)
Deep clone an LWGEOM, everything is copied.
Definition lwgeom.c:511
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!...
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.
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition lwutil.c:190
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)
Definition lwinline.h:193
uint32_t ngeoms
Definition liblwgeom.h:566
LWGEOM ** geoms
Definition liblwgeom.h:561
uint8_t type
Definition liblwgeom.h:448
int32_t srid
Definition liblwgeom.h:446
POINTARRAY * points
Definition liblwgeom.h:469
POINTARRAY ** rings
Definition liblwgeom.h:505
uint32_t nrings
Definition liblwgeom.h:510

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(), lwgeom_segmentize_sphere(), 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(), lwgeom_segmentize_sphere(), test_geos_subdivide(), and test_lwgeom_segmentize_sphere().

Here is the call graph for this function:
Here is the caller graph for this function: