PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ ptarray_from_GEOSCoordSeq()

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

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

69 {
70  uint32_t dims=2;
71  uint32_t size, i;
72  POINTARRAY *pa;
73  POINT4D point;
74 
75  LWDEBUG(2, "ptarray_fromGEOSCoordSeq called");
76 
77  if ( ! GEOSCoordSeq_getSize(cs, &size) )
78  lwerror("Exception thrown");
79 
80  LWDEBUGF(4, " GEOSCoordSeq size: %d", size);
81 
82  if ( want3d )
83  {
84  if ( ! GEOSCoordSeq_getDimensions(cs, &dims) )
85  lwerror("Exception thrown");
86 
87  LWDEBUGF(4, " GEOSCoordSeq dimensions: %d", dims);
88 
89  /* forget higher dimensions (if any) */
90  if ( dims > 3 ) dims = 3;
91  }
92 
93  LWDEBUGF(4, " output dimensions: %d", dims);
94 
95  pa = ptarray_construct((dims==3), 0, size);
96 
97  for (i=0; i<size; i++)
98  {
99  GEOSCoordSeq_getX(cs, i, &(point.x));
100  GEOSCoordSeq_getY(cs, i, &(point.y));
101  if ( dims >= 3 ) GEOSCoordSeq_getZ(cs, i, &(point.z));
102  ptarray_set_point4d(pa,i,&point);
103  }
104 
105  return pa;
106 }
void ptarray_set_point4d(POINTARRAY *pa, int n, const POINT4D *p4d)
Definition: lwgeom_api.c:437
double x
Definition: liblwgeom.h:352
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:83
unsigned int uint32_t
Definition: uthash.h:78
double z
Definition: liblwgeom.h:352
double y
Definition: liblwgeom.h:352
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
Here is the call graph for this function:
Here is the caller graph for this function: