PostGIS  2.1.10dev-r@@SVN_REVISION@@
Datum geometry_to_path ( PG_FUNCTION_ARGS  )

Definition at line 83 of file geometry_inout.c.

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

84 {
85  PATH *path;
86  LWLINE *lwline;
87  LWGEOM *lwgeom;
88  GSERIALIZED *geom;
89  POINTARRAY *pa;
90  int i;
91  POINT2D pt;
92  size_t size;
93 
94  POSTGIS_DEBUG(2, "geometry_to_path called");
95 
96  if ( PG_ARGISNULL(0) )
97  PG_RETURN_NULL();
98 
99  geom = (GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
100 
101  if ( gserialized_get_type(geom) != LINETYPE )
102  elog(ERROR, "geometry_to_path only accepts LineStrings");
103 
104  lwgeom = lwgeom_from_gserialized(geom);
105  if ( lwgeom_is_empty(lwgeom) )
106  PG_RETURN_NULL();
107  lwline = lwgeom_as_lwline(lwgeom);
108 
109  pa = lwline->points;
110  size = offsetof(PATH, p[0]) + sizeof(path->p[0]) * pa->npoints;
111  path = (PATH*)palloc(size);
112  SET_VARSIZE(path, size);
113  path->npts = pa->npoints;
114  path->closed = 0;
115  path->dummy = 0;
116 
117  for ( i = 0; i < pa->npoints; i++ )
118  {
119  getPoint2d_p(pa, i, &pt);
120  (path->p[i]).x = pt.x;
121  (path->p[i]).y = pt.y;
122  }
123 
124  lwgeom_free(lwgeom);
125  PG_FREE_IF_COPY(geom,0);
126 
127  PG_RETURN_PATH_P(path);
128 }
#define LINETYPE
Definition: liblwgeom.h:61
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:56
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
int npoints
Definition: liblwgeom.h:327
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1006
double x
Definition: liblwgeom.h:284
double y
Definition: liblwgeom.h:284
int getPoint2d_p(const POINTARRAY *pa, int n, POINT2D *point)
Definition: lwgeom_api.c:434
tuple x
Definition: pixval.py:53
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:89
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
POINTARRAY * points
Definition: liblwgeom.h:378

Here is the call graph for this function: