PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ geometry_to_path()

Datum geometry_to_path ( PG_FUNCTION_ARGS  )

Definition at line 83 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().

84 {
85  PATH *path;
86  LWLINE *lwline;
87  LWGEOM *lwgeom;
88  GSERIALIZED *geom;
89  POINTARRAY *pa;
90  int i;
91  const 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 = PG_GETARG_GSERIALIZED_P(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  pt = getPoint2d_cp(pa, i);
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:71
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:55
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
int npoints
Definition: liblwgeom.h:355
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1050
double x
Definition: liblwgeom.h:312
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:472
double y
Definition: liblwgeom.h:312
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:1297
POINTARRAY * points
Definition: liblwgeom.h:406
Here is the call graph for this function:
Here is the caller graph for this function: