PostGIS  2.1.10dev-r@@SVN_REVISION@@
LWGEOM* SFCGAL2LWGEOM ( const sfcgal_geometry_t *  geom,
int  force3D,
int  srid 
)

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

References LWGEOM::flags, FLAGS_SET_SOLID, lwalloc(), lwcollection_construct(), lwerror(), lwline_construct(), lwline_construct_empty(), lwpoint_construct(), lwpoint_construct_empty(), lwpoly_construct(), lwpoly_construct_empty(), lwrealloc(), lwtriangle_construct(), lwtriangle_construct_empty(), POLYHEDRALSURFACETYPE, ptarray_from_SFCGAL(), SFCGAL2LWGEOM(), SFCGAL_type_to_lwgeom_type(), and TINTYPE.

Referenced by lwgeom_sfcgal_noop(), SFCGAL2LWGEOM(), and SFCGALGeometry2POSTGIS().

270 {
271  uint32_t ngeoms, nshells;
272  uint32_t i, j, k;
273  int want3d;
274 
275  assert(geom);
276 
277  want3d = force3D || sfcgal_geometry_is_3d(geom);
278 
279  switch (sfcgal_geometry_type_id(geom))
280  {
281  case SFCGAL_TYPE_POINT:
282  {
283  if (sfcgal_geometry_is_empty(geom))
284  return (LWGEOM*) lwpoint_construct_empty(srid, want3d, 0);
285 
286  POINTARRAY* pa = ptarray_from_SFCGAL(geom, want3d);
287  return (LWGEOM*) lwpoint_construct(srid, NULL, pa);
288  }
289 
290  case SFCGAL_TYPE_LINESTRING:
291  {
292  if (sfcgal_geometry_is_empty(geom))
293  return (LWGEOM*) lwline_construct_empty(srid, want3d, 0);
294 
295  POINTARRAY* pa = ptarray_from_SFCGAL(geom, want3d);
296  return (LWGEOM*) lwline_construct(srid, NULL, pa);
297  }
298 
299  case SFCGAL_TYPE_TRIANGLE:
300  {
301  if (sfcgal_geometry_is_empty(geom))
302  return (LWGEOM*) lwtriangle_construct_empty(srid, want3d, 0);
303 
304  POINTARRAY* pa = ptarray_from_SFCGAL(geom, want3d);
305  return (LWGEOM*) lwtriangle_construct(srid, NULL, pa);
306  }
307 
308  case SFCGAL_TYPE_POLYGON:
309  {
310  if (sfcgal_geometry_is_empty(geom))
311  return (LWGEOM*) lwpoly_construct_empty(srid, want3d, 0);
312 
313  uint32_t nrings = sfcgal_polygon_num_interior_rings(geom) + 1;
314  POINTARRAY** pa = (POINTARRAY**) lwalloc(sizeof(POINTARRAY*) * nrings);
315 
316  pa[0] = ptarray_from_SFCGAL(sfcgal_polygon_exterior_ring(geom), want3d);
317  for (i = 1; i < nrings; i++)
318  pa[i] = ptarray_from_SFCGAL(sfcgal_polygon_interior_ring_n(geom, i-1), want3d);
319 
320  return (LWGEOM*) lwpoly_construct(srid, NULL, nrings, pa);
321  }
322 
323  case SFCGAL_TYPE_MULTIPOINT:
324  case SFCGAL_TYPE_MULTILINESTRING:
325  case SFCGAL_TYPE_MULTIPOLYGON:
326  case SFCGAL_TYPE_MULTISOLID:
327  case SFCGAL_TYPE_GEOMETRYCOLLECTION:
328  {
329  ngeoms = sfcgal_geometry_collection_num_geometries(geom);
330  LWGEOM** geoms = NULL;
331  if (ngeoms)
332  {
333  geoms = (LWGEOM**) lwalloc(sizeof(LWGEOM*) * ngeoms);
334  for (i = 0; i < ngeoms; i++)
335  {
336  const sfcgal_geometry_t* g = sfcgal_geometry_collection_geometry_n(geom, i);
337  geoms[i] = SFCGAL2LWGEOM(g, 0, srid);
338  }
339  geoms = (LWGEOM**) lwrealloc(geoms, sizeof(LWGEOM*) * ngeoms);
340  }
342  sfcgal_geometry_type_id(geom)), srid, NULL, ngeoms, geoms);
343  }
344 
345 #if 0
346  case SFCGAL_TYPE_CIRCULARSTRING:
347  case SFCGAL_TYPE_COMPOUNDCURVE:
348  case SFCGAL_TYPE_CURVEPOLYGON:
349  case SFCGAL_TYPE_MULTICURVE:
350  case SFCGAL_TYPE_MULTISURFACE:
351  case SFCGAL_TYPE_CURVE:
352  case SFCGAL_TYPE_SURFACE:
353 
354  /* TODO curve types handling */
355 #endif
356 
357  case SFCGAL_TYPE_POLYHEDRALSURFACE:
358  {
359  ngeoms = sfcgal_polyhedral_surface_num_polygons(geom);
360 
361  LWGEOM** geoms = NULL;
362  if (ngeoms)
363  {
364  geoms = (LWGEOM**) lwalloc(sizeof(LWGEOM*) * ngeoms);
365  for (i = 0; i < ngeoms; i++)
366  {
367  const sfcgal_geometry_t* g = sfcgal_polyhedral_surface_polygon_n( geom, i );
368  geoms[i] = SFCGAL2LWGEOM(g, 0, srid);
369  }
370  }
371  return (LWGEOM*)lwcollection_construct(POLYHEDRALSURFACETYPE, srid, NULL, ngeoms, geoms);
372  }
373 
374  /* Solid is map as a closed PolyhedralSurface (for now) */
375  case SFCGAL_TYPE_SOLID:
376  {
377  nshells = sfcgal_solid_num_shells(geom);
378 
379  for (ngeoms = 0, i = 0; i < nshells; i++)
380  ngeoms += sfcgal_polyhedral_surface_num_polygons(sfcgal_solid_shell_n(geom, i));
381 
382  LWGEOM** geoms = 0;
383  if (ngeoms)
384  {
385  geoms = (LWGEOM**) lwalloc( sizeof(LWGEOM*) * ngeoms);
386  for (i = 0, k =0 ; i < nshells; i++)
387  {
388  const sfcgal_geometry_t* shell = sfcgal_solid_shell_n(geom, i);
389  ngeoms = sfcgal_polyhedral_surface_num_polygons(shell);
390 
391  for (j = 0; j < ngeoms; j++)
392  {
393  const sfcgal_geometry_t* g = sfcgal_polyhedral_surface_polygon_n(shell, j);
394  geoms[k] = SFCGAL2LWGEOM(g, 1, srid);
395  k++;
396  }
397  }
398  }
399  LWGEOM* rgeom = (LWGEOM*) lwcollection_construct(POLYHEDRALSURFACETYPE, srid, NULL, ngeoms, geoms);
400  if (ngeoms) FLAGS_SET_SOLID( rgeom->flags, 1);
401  return rgeom;
402  }
403 
404  case SFCGAL_TYPE_TRIANGULATEDSURFACE:
405  {
406  ngeoms = sfcgal_triangulated_surface_num_triangles(geom);
407  LWGEOM** geoms = NULL;
408  if (ngeoms)
409  {
410  geoms = (LWGEOM**) lwalloc(sizeof(LWGEOM*) * ngeoms);
411  for (i = 0; i < ngeoms; i++)
412  {
413  const sfcgal_geometry_t* g = sfcgal_triangulated_surface_triangle_n(geom, i);
414  geoms[i] = SFCGAL2LWGEOM(g, 0, srid);
415  }
416  }
417  return (LWGEOM*) lwcollection_construct(TINTYPE, srid, NULL, ngeoms, geoms);
418  }
419 
420  default:
421  lwerror("SFCGAL2LWGEOM: Unknown Type");
422  return NULL;
423  }
424 }
#define FLAGS_SET_SOLID(flags, value)
Definition: liblwgeom.h:117
LWLINE * lwline_construct_empty(int srid, char hasz, char hasm)
Definition: lwline.c:51
LWCOLLECTION * lwcollection_construct(uint8_t type, int srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms)
Definition: lwcollection.c:30
LWTRIANGLE * lwtriangle_construct_empty(int srid, char hasz, char hasm)
Definition: lwtriangle.c:45
uint8_t flags
Definition: liblwgeom.h:353
#define POLYHEDRALSURFACETYPE
Definition: liblwgeom.h:72
LWPOINT * lwpoint_construct_empty(int srid, char hasz, char hasm)
Definition: lwpoint.c:118
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:67
LWGEOM * geom
static int SFCGAL_type_to_lwgeom_type(sfcgal_geometry_type_t type)
LWPOLY * lwpoly_construct(int srid, GBOX *bbox, uint32_t nrings, POINTARRAY **points)
Definition: lwpoly.c:29
LWLINE * lwline_construct(int srid, GBOX *bbox, POINTARRAY *points)
Definition: lwline.c:29
#define TINTYPE
Definition: liblwgeom.h:74
LWTRIANGLE * lwtriangle_construct(int srid, GBOX *bbox, POINTARRAY *points)
Definition: lwtriangle.c:27
static POINTARRAY * ptarray_from_SFCGAL(const sfcgal_geometry_t *geom, int force3D)
void * lwrealloc(void *mem, size_t size)
Definition: lwutil.c:183
LWPOLY * lwpoly_construct_empty(int srid, char hasz, char hasm)
Definition: lwpoly.c:66
LWPOINT * lwpoint_construct(int srid, GBOX *bbox, POINTARRAY *point)
Definition: lwpoint.c:96
void * lwalloc(size_t size)
Definition: lwutil.c:175
LWGEOM * SFCGAL2LWGEOM(const sfcgal_geometry_t *geom, int force3D, int srid)

Here is the call graph for this function:

Here is the caller graph for this function: