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

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

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

Here is the call graph for this function:

Here is the caller graph for this function: