PostGIS  2.1.10dev-r@@SVN_REVISION@@
static POINTARRAY * ptarray_from_SFCGAL ( const sfcgal_geometry_t *  geom,
int  force3D 
)
static

Definition at line 110 of file liblwgeom/lwgeom_sfcgal.c.

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

Referenced by SFCGAL2LWGEOM().

111 {
112  POINT4D point;
113  uint32_t i, npoints;
114  POINTARRAY* pa = NULL;
115 
116  assert(geom);
117 
118  switch (sfcgal_geometry_type_id(geom))
119  {
120  case SFCGAL_TYPE_POINT:
121  {
122  pa = ptarray_construct(want3d, 0, 1);
123  point.x = sfcgal_point_x(geom);
124  point.y = sfcgal_point_y(geom);
125 
126  if (sfcgal_geometry_is_3d(geom))
127  point.z = sfcgal_point_z(geom);
128  else if (want3d)
129  point.z = 0.0;
130 
131  ptarray_set_point4d(pa, 0, &point);
132  }
133  break;
134 
135  case SFCGAL_TYPE_LINESTRING:
136  {
137  npoints = sfcgal_linestring_num_points(geom);
138  pa = ptarray_construct(want3d, 0, npoints);
139 
140  for (i = 0; i < npoints; i++)
141  {
142  const sfcgal_geometry_t* pt = sfcgal_linestring_point_n(geom, i);
143  point.x = sfcgal_point_x(pt);
144  point.y = sfcgal_point_y(pt);
145 
146  if (sfcgal_geometry_is_3d(geom))
147  point.z = sfcgal_point_z(pt);
148  else if (want3d)
149  point.z = 0.0;
150 
151  ptarray_set_point4d(pa, i, &point);
152  }
153  }
154  break;
155 
156  case SFCGAL_TYPE_TRIANGLE:
157  {
158  pa = ptarray_construct(want3d, 0, 4);
159 
160  for (i = 0; i < 4; i++)
161  {
162  const sfcgal_geometry_t* pt = sfcgal_triangle_vertex(geom, (i%3));
163  point.x = sfcgal_point_x(pt);
164  point.y = sfcgal_point_y(pt);
165 
166  if ( sfcgal_geometry_is_3d(geom))
167  point.z = sfcgal_point_z(pt);
168  else if (want3d)
169  point.z = 0.0;
170 
171  ptarray_set_point4d(pa, i, &point);
172  }
173  }
174  break;
175 
176  /* Other types should not be called directly ... */
177  default:
178  lwerror("ptarray_from_SFCGAL: Unknown Type");
179  break;
180  }
181  return pa;
182 }
void ptarray_set_point4d(POINTARRAY *pa, int n, const POINT4D *p4d)
Definition: lwgeom_api.c:501
double x
Definition: liblwgeom.h:308
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:49
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:67
LWGEOM * geom
double z
Definition: liblwgeom.h:308
double y
Definition: liblwgeom.h:308

Here is the call graph for this function:

Here is the caller graph for this function: