PostGIS  2.1.10dev-r@@SVN_REVISION@@
sfcgal_geometry_t* LWGEOM2SFCGAL ( const LWGEOM geom)

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

References COLLECTIONTYPE, LWPSURFACE::flags, FLAGS_GET_SOLID, LWCOLLECTION::geoms, LWPSURFACE::geoms, LWTIN::geoms, LINETYPE, lwerror(), LWGEOM2SFCGAL(), lwgeom_is_empty(), MULTILINETYPE, MULTIPOINTTYPE, MULTIPOLYGONTYPE, LWCOLLECTION::ngeoms, LWPSURFACE::ngeoms, LWTIN::ngeoms, LWPOLY::nrings, LWPOINT::point, LWLINE::points, LWTRIANGLE::points, POINTTYPE, POLYGONTYPE, POLYHEDRALSURFACETYPE, ptarray_to_SFCGAL(), LWPOLY::rings, TINTYPE, TRIANGLETYPE, and LWGEOM::type.

Referenced by LWGEOM2SFCGAL(), lwgeom_sfcgal_noop(), POSTGIS2SFCGALGeometry(), and POSTGIS2SFCGALPreparedGeometry().

429 {
430  uint32_t i;
431  sfcgal_geometry_t* ret_geom = NULL;
432 
433  assert(geom);
434 
435  switch (geom->type)
436  {
437  case POINTTYPE:
438  {
439  const LWPOINT* lwp = (const LWPOINT*) geom;
440  if (lwgeom_is_empty(geom)) return sfcgal_point_create();
441 
442  return ptarray_to_SFCGAL(lwp->point, POINTTYPE);
443  }
444  break;
445 
446  case LINETYPE:
447  {
448  const LWLINE* line = (const LWLINE*) geom;
449  if (lwgeom_is_empty(geom)) return sfcgal_linestring_create();
450 
451  return ptarray_to_SFCGAL(line->points, LINETYPE);
452  }
453  break;
454 
455  case TRIANGLETYPE:
456  {
457  const LWTRIANGLE* triangle = (const LWTRIANGLE*) geom;
458  if (lwgeom_is_empty(geom)) return sfcgal_triangle_create();
459  return ptarray_to_SFCGAL(triangle->points, TRIANGLETYPE);
460  }
461  break;
462 
463  case POLYGONTYPE:
464  {
465  const LWPOLY* poly = (const LWPOLY*) geom;
466  uint32_t nrings = poly->nrings - 1;
467 
468  if (lwgeom_is_empty(geom)) return sfcgal_polygon_create();
469 
470  sfcgal_geometry_t* exterior_ring = ptarray_to_SFCGAL(poly->rings[0], LINETYPE);
471  ret_geom = sfcgal_polygon_create_from_exterior_ring(exterior_ring);
472 
473  for (i = 0; i < nrings; i++)
474  {
475  sfcgal_geometry_t* ring = ptarray_to_SFCGAL(poly->rings[i + 1], LINETYPE);
476  sfcgal_polygon_add_interior_ring(ret_geom, ring);
477  }
478  return ret_geom;
479  }
480  break;
481 
482  case MULTIPOINTTYPE:
483  case MULTILINETYPE:
484  case MULTIPOLYGONTYPE:
485  case COLLECTIONTYPE:
486  {
487  if (geom->type == MULTIPOINTTYPE) ret_geom = sfcgal_multi_point_create();
488  else if (geom->type == MULTILINETYPE) ret_geom = sfcgal_multi_linestring_create();
489  else if (geom->type == MULTIPOLYGONTYPE) ret_geom = sfcgal_multi_polygon_create();
490  else ret_geom = sfcgal_geometry_collection_create();
491 
492  const LWCOLLECTION* lwc = (const LWCOLLECTION*)geom;
493  for (i = 0; i < lwc->ngeoms; i++)
494  {
495  sfcgal_geometry_t* g = LWGEOM2SFCGAL(lwc->geoms[i]);
496  sfcgal_geometry_collection_add_geometry(ret_geom, g);
497  }
498 
499  return ret_geom;
500  }
501  break;
502 
504  {
505  const LWPSURFACE* lwp = (const LWPSURFACE*) geom;
506  ret_geom = sfcgal_polyhedral_surface_create();
507 
508  for (i = 0; i < lwp->ngeoms; i++)
509  {
510  sfcgal_geometry_t* g = LWGEOM2SFCGAL((const LWGEOM*) lwp->geoms[i]);
511  sfcgal_polyhedral_surface_add_polygon(ret_geom, g);
512  }
513  /* We treat polyhedral surface as the only exterior shell,
514  since we can't distinguish exterior from interior shells ... */
515  if (FLAGS_GET_SOLID(lwp->flags))
516  {
517  return sfcgal_solid_create_from_exterior_shell(ret_geom);
518  }
519 
520  return ret_geom;
521  }
522  break;
523 
524  case TINTYPE:
525  {
526  const LWTIN* lwp = (const LWTIN*) geom;
527  ret_geom = sfcgal_triangulated_surface_create();
528 
529  for (i = 0; i < lwp->ngeoms; i++)
530  {
531  sfcgal_geometry_t* g = LWGEOM2SFCGAL((const LWGEOM*) lwp->geoms[i]);
532  sfcgal_triangulated_surface_add_triangle(ret_geom, g);
533  }
534 
535  return ret_geom;
536  }
537  break;
538 
539  default:
540  lwerror("LWGEOM2SFCGAL: Unknown geometry type !");
541  return NULL;
542  }
543 }
#define LINETYPE
Definition: liblwgeom.h:61
uint8_t flags
Definition: liblwgeom.h:525
POINTARRAY * points
Definition: liblwgeom.h:389
static sfcgal_geometry_t * ptarray_to_SFCGAL(const POINTARRAY *pa, int type)
#define POLYGONTYPE
Definition: liblwgeom.h:62
#define MULTIPOINTTYPE
Definition: liblwgeom.h:63
#define TRIANGLETYPE
Definition: liblwgeom.h:73
#define POLYHEDRALSURFACETYPE
Definition: liblwgeom.h:72
LWPOLY ** geoms
Definition: liblwgeom.h:530
#define FLAGS_GET_SOLID(flags)
Definition: liblwgeom.h:111
POINTARRAY * point
Definition: liblwgeom.h:367
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:67
int ngeoms
Definition: liblwgeom.h:541
sfcgal_geometry_t * LWGEOM2SFCGAL(const LWGEOM *geom)
LWGEOM ** geoms
Definition: liblwgeom.h:465
#define TINTYPE
Definition: liblwgeom.h:74
LWTRIANGLE ** geoms
Definition: liblwgeom.h:543
POINTARRAY ** rings
Definition: liblwgeom.h:413
int nrings
Definition: liblwgeom.h:411
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:65
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:60
uint8_t type
Definition: liblwgeom.h:352
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members) ...
Definition: lwgeom.c:1229
#define MULTILINETYPE
Definition: liblwgeom.h:64
int ngeoms
Definition: liblwgeom.h:528
#define COLLECTIONTYPE
Definition: liblwgeom.h:66
POINTARRAY * points
Definition: liblwgeom.h:378

Here is the call graph for this function:

Here is the caller graph for this function: