PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ ptarray_from_GEOSCoordSeq()

POINTARRAY* ptarray_from_GEOSCoordSeq ( const GEOSCoordSequence *  cs,
char  want3d 
)

Definition at line 54 of file liblwgeom/lwgeom_geos.c.

References LWDEBUG, LWDEBUGF, lwerror(), ptarray_construct(), ptarray_set_point4d(), POINT4D::x, POINT4D::y, and POINT4D::z.

Referenced by GEOS2LWGEOM(), and lwtin_from_geos().

55 {
56  uint32_t dims=2;
57  uint32_t size, i;
58  POINTARRAY *pa;
59  POINT4D point;
60 
61  LWDEBUG(2, "ptarray_fromGEOSCoordSeq called");
62 
63  if ( ! GEOSCoordSeq_getSize(cs, &size) )
64  lwerror("Exception thrown");
65 
66  LWDEBUGF(4, " GEOSCoordSeq size: %d", size);
67 
68  if ( want3d )
69  {
70  if ( ! GEOSCoordSeq_getDimensions(cs, &dims) )
71  lwerror("Exception thrown");
72 
73  LWDEBUGF(4, " GEOSCoordSeq dimensions: %d", dims);
74 
75  /* forget higher dimensions (if any) */
76  if ( dims > 3 ) dims = 3;
77  }
78 
79  LWDEBUGF(4, " output dimensions: %d", dims);
80 
81  pa = ptarray_construct((dims==3), 0, size);
82 
83  for (i=0; i<size; i++)
84  {
85  GEOSCoordSeq_getX(cs, i, &(point.x));
86  GEOSCoordSeq_getY(cs, i, &(point.y));
87  if ( dims >= 3 ) GEOSCoordSeq_getZ(cs, i, &(point.z));
88  ptarray_set_point4d(pa,i,&point);
89  }
90 
91  return pa;
92 }
void ptarray_set_point4d(POINTARRAY *pa, int n, const POINT4D *p4d)
Definition: lwgeom_api.c:536
double x
Definition: liblwgeom.h:336
POINTARRAY * ptarray_construct(char hasz, char hasm, uint32_t npoints)
Construct an empty pointarray, allocating storage and setting the npoints, but not filling in any inf...
Definition: ptarray.c:62
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:50
double z
Definition: liblwgeom.h:336
double y
Definition: liblwgeom.h:336
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:55
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:74
Here is the call graph for this function:
Here is the caller graph for this function: