PostGIS  2.2.7dev-r@@SVN_REVISION@@
static sfcgal_geometry_t * ptarray_to_SFCGAL ( const POINTARRAY pa,
int  type 
)
static

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

References POINTARRAY::flags, FLAGS_GET_Z, getPoint3dz_p(), LINETYPE, lwerror(), POINTARRAY::npoints, POINTTYPE, TRIANGLETYPE, POINT3DZ::x, POINT3DZ::y, and POINT3DZ::z.

Referenced by LWGEOM2SFCGAL().

191 {
192  POINT3DZ point;
193  int is_3d;
194  uint32_t i;
195 
196  assert(pa);
197 
198  is_3d = FLAGS_GET_Z(pa->flags) != 0;
199 
200  switch (type)
201  {
202  case POINTTYPE:
203  {
204  getPoint3dz_p(pa, 0, &point);
205  if (is_3d) return sfcgal_point_create_from_xyz(point.x, point.y, point.z);
206  else return sfcgal_point_create_from_xy(point.x, point.y);
207  }
208  break;
209 
210  case LINETYPE:
211  {
212  sfcgal_geometry_t* line = sfcgal_linestring_create();
213 
214  for (i = 0; i < pa->npoints; i++)
215  {
216  getPoint3dz_p(pa, i, &point);
217  if (is_3d)
218  {
219  sfcgal_linestring_add_point(line,
220  sfcgal_point_create_from_xyz(point.x, point.y, point.z));
221  }
222  else
223  {
224  sfcgal_linestring_add_point(line,
225  sfcgal_point_create_from_xy(point.x, point.y));
226  }
227  }
228 
229  return line;
230  }
231  break;
232 
233  case TRIANGLETYPE:
234  {
235  sfcgal_geometry_t* triangle = sfcgal_triangle_create();
236 
237  getPoint3dz_p(pa, 0, &point);
238  if (is_3d) sfcgal_triangle_set_vertex_from_xyz(triangle, 0, point.x, point.y, point.z);
239  else sfcgal_triangle_set_vertex_from_xy (triangle, 0, point.x, point.y);
240 
241  getPoint3dz_p(pa, 1, &point);
242  if (is_3d) sfcgal_triangle_set_vertex_from_xyz(triangle, 1, point.x, point.y, point.z);
243  else sfcgal_triangle_set_vertex_from_xy (triangle, 1, point.x, point.y);
244 
245  getPoint3dz_p(pa, 2, &point);
246  if (is_3d) sfcgal_triangle_set_vertex_from_xyz(triangle, 2, point.x, point.y, point.z);
247  else sfcgal_triangle_set_vertex_from_xy (triangle, 2, point.x, point.y);
248 
249  return triangle;
250  }
251  break;
252 
253  /* Other SFCGAL types should not be called directly ... */
254  default:
255  lwerror("ptarray_from_SFCGAL: Unknown Type");
256  return NULL;
257  }
258 }
#define LINETYPE
Definition: liblwgeom.h:71
double z
Definition: liblwgeom.h:318
double y
Definition: liblwgeom.h:318
double x
Definition: liblwgeom.h:318
int npoints
Definition: liblwgeom.h:355
#define TRIANGLETYPE
Definition: liblwgeom.h:83
int getPoint3dz_p(const POINTARRAY *pa, int n, POINT3DZ *point)
Definition: lwgeom_api.c:319
uint8_t flags
Definition: liblwgeom.h:353
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
Definition: liblwgeom.h:124
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:70
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: