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

◆ geometry_to_path()

Datum geometry_to_path ( PG_FUNCTION_ARGS  )

Definition at line 96 of file geometry_inout.c.

97{
98 PATH *path;
99 LWLINE *lwline;
100 LWGEOM *lwgeom;
101 GSERIALIZED *geom;
102 POINTARRAY *pa;
103 uint32_t i;
104 const POINT2D *pt;
105 size_t size;
106
107 POSTGIS_DEBUG(2, "geometry_to_path called");
108
109 if ( PG_ARGISNULL(0) )
110 PG_RETURN_NULL();
111
112 geom = PG_GETARG_GSERIALIZED_P(0);
113
114 if ( gserialized_get_type(geom) != LINETYPE )
115 elog(ERROR, "geometry_to_path only accepts LineStrings");
116
117 lwgeom = lwgeom_from_gserialized(geom);
118 if ( lwgeom_is_empty(lwgeom) )
119 PG_RETURN_NULL();
120 lwline = lwgeom_as_lwline(lwgeom);
121
122 pa = lwline->points;
123 size = offsetof(PATH, p[0]) + sizeof(path->p[0]) * pa->npoints;
124 path = (PATH*)palloc(size);
125 SET_VARSIZE(path, size);
126 path->npts = pa->npoints;
127 path->closed = 0;
128 path->dummy = 0;
129
130 for ( i = 0; i < pa->npoints; i++ )
131 {
132 pt = getPoint2d_cp(pa, i);
133 (path->p[i]).x = pt->x;
134 (path->p[i]).y = pt->y;
135 }
136
137 lwgeom_free(lwgeom);
138 PG_FREE_IF_COPY(geom,0);
139
140 PG_RETURN_PATH_P(path);
141}
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
uint32_t gserialized_get_type(const GSERIALIZED *g)
Extract the geometry type from the serialized form (it hides in the anonymous data area,...
void lwgeom_free(LWGEOM *geom)
Definition lwgeom.c:1246
#define LINETYPE
Definition liblwgeom.h:103
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition lwgeom.c:207
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:199
static const POINT2D * getPoint2d_cp(const POINTARRAY *pa, uint32_t n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from.
Definition lwinline.h:97
POINTARRAY * points
Definition liblwgeom.h:483
double y
Definition liblwgeom.h:390
double x
Definition liblwgeom.h:390
uint32_t npoints
Definition liblwgeom.h:427

References getPoint2d_cp(), gserialized_get_type(), LINETYPE, lwgeom_as_lwline(), lwgeom_free(), lwgeom_from_gserialized(), lwgeom_is_empty(), POINTARRAY::npoints, LWLINE::points, POINT2D::x, and POINT2D::y.

Here is the call graph for this function: