PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ geometry_to_path()

Datum geometry_to_path ( PG_FUNCTION_ARGS  )

Definition at line 107 of file geometry_inout.c.

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

Referenced by geometry_to_point().

108 {
109  PATH *path;
110  LWLINE *lwline;
111  LWGEOM *lwgeom;
112  GSERIALIZED *geom;
113  POINTARRAY *pa;
114  int i;
115  const POINT2D *pt;
116  size_t size;
117 
118  POSTGIS_DEBUG(2, "geometry_to_path called");
119 
120  if ( PG_ARGISNULL(0) )
121  PG_RETURN_NULL();
122 
123  geom = PG_GETARG_GSERIALIZED_P(0);
124 
125  if ( gserialized_get_type(geom) != LINETYPE )
126  elog(ERROR, "geometry_to_path only accepts LineStrings");
127 
128  lwgeom = lwgeom_from_gserialized(geom);
129  if ( lwgeom_is_empty(lwgeom) )
130  PG_RETURN_NULL();
131  lwline = lwgeom_as_lwline(lwgeom);
132 
133  pa = lwline->points;
134  size = offsetof(PATH, p[0]) + sizeof(path->p[0]) * pa->npoints;
135  path = (PATH*)palloc(size);
136  SET_VARSIZE(path, size);
137  path->npts = pa->npoints;
138  path->closed = 0;
139  path->dummy = 0;
140 
141  for ( i = 0; i < pa->npoints; i++ )
142  {
143  pt = getPoint2d_cp(pa, i);
144  (path->p[i]).x = pt->x;
145  (path->p[i]).y = pt->y;
146  }
147 
148  lwgeom_free(lwgeom);
149  PG_FREE_IF_COPY(geom,0);
150 
151  PG_RETURN_PATH_P(path);
152 }
#define LINETYPE
Definition: liblwgeom.h:86
uint32_t gserialized_get_type(const GSERIALIZED *s)
Extract the geometry type from the serialized form (it hides in the anonymous data area...
Definition: g_serialized.c:86
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
int npoints
Definition: liblwgeom.h:371
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1099
double x
Definition: liblwgeom.h:328
const POINT2D * getPoint2d_cp(const POINTARRAY *pa, int n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from...
Definition: lwgeom_api.c:373
double y
Definition: liblwgeom.h:328
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:138
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:1346
POINTARRAY * points
Definition: liblwgeom.h:422
Here is the call graph for this function:
Here is the caller graph for this function: