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

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

435 {
436  uint32_t i;
437  sfcgal_geometry_t* ret_geom = NULL;
438 
439  assert(geom);
440 
441  switch (geom->type)
442  {
443  case POINTTYPE:
444  {
445  const LWPOINT* lwp = (const LWPOINT*) geom;
446  if (lwgeom_is_empty(geom)) return sfcgal_point_create();
447 
448  return ptarray_to_SFCGAL(lwp->point, POINTTYPE);
449  }
450  break;
451 
452  case LINETYPE:
453  {
454  const LWLINE* line = (const LWLINE*) geom;
455  if (lwgeom_is_empty(geom)) return sfcgal_linestring_create();
456 
457  return ptarray_to_SFCGAL(line->points, LINETYPE);
458  }
459  break;
460 
461  case TRIANGLETYPE:
462  {
463  const LWTRIANGLE* triangle = (const LWTRIANGLE*) geom;
464  if (lwgeom_is_empty(geom)) return sfcgal_triangle_create();
465  return ptarray_to_SFCGAL(triangle->points, TRIANGLETYPE);
466  }
467  break;
468 
469  case POLYGONTYPE:
470  {
471  const LWPOLY* poly = (const LWPOLY*) geom;
472  uint32_t nrings = poly->nrings - 1;
473 
474  if (lwgeom_is_empty(geom)) return sfcgal_polygon_create();
475 
476  sfcgal_geometry_t* exterior_ring = ptarray_to_SFCGAL(poly->rings[0], LINETYPE);
477  ret_geom = sfcgal_polygon_create_from_exterior_ring(exterior_ring);
478 
479  for (i = 0; i < nrings; i++)
480  {
481  sfcgal_geometry_t* ring = ptarray_to_SFCGAL(poly->rings[i + 1], LINETYPE);
482  sfcgal_polygon_add_interior_ring(ret_geom, ring);
483  }
484  return ret_geom;
485  }
486  break;
487 
488  case MULTIPOINTTYPE:
489  case MULTILINETYPE:
490  case MULTIPOLYGONTYPE:
491  case COLLECTIONTYPE:
492  {
493  if (geom->type == MULTIPOINTTYPE) ret_geom = sfcgal_multi_point_create();
494  else if (geom->type == MULTILINETYPE) ret_geom = sfcgal_multi_linestring_create();
495  else if (geom->type == MULTIPOLYGONTYPE) ret_geom = sfcgal_multi_polygon_create();
496  else ret_geom = sfcgal_geometry_collection_create();
497 
498  const LWCOLLECTION* lwc = (const LWCOLLECTION*)geom;
499  for (i = 0; i < lwc->ngeoms; i++)
500  {
501  sfcgal_geometry_t* g = LWGEOM2SFCGAL(lwc->geoms[i]);
502  sfcgal_geometry_collection_add_geometry(ret_geom, g);
503  }
504 
505  return ret_geom;
506  }
507  break;
508 
510  {
511  const LWPSURFACE* lwp = (const LWPSURFACE*) geom;
512  ret_geom = sfcgal_polyhedral_surface_create();
513 
514  for (i = 0; i < lwp->ngeoms; i++)
515  {
516  sfcgal_geometry_t* g = LWGEOM2SFCGAL((const LWGEOM*) lwp->geoms[i]);
517  sfcgal_polyhedral_surface_add_polygon(ret_geom, g);
518  }
519  /* We treat polyhedral surface as the only exterior shell,
520  since we can't distinguish exterior from interior shells ... */
521  if (FLAGS_GET_SOLID(lwp->flags))
522  {
523  return sfcgal_solid_create_from_exterior_shell(ret_geom);
524  }
525 
526  return ret_geom;
527  }
528  break;
529 
530  case TINTYPE:
531  {
532  const LWTIN* lwp = (const LWTIN*) geom;
533  ret_geom = sfcgal_triangulated_surface_create();
534 
535  for (i = 0; i < lwp->ngeoms; i++)
536  {
537  sfcgal_geometry_t* g = LWGEOM2SFCGAL((const LWGEOM*) lwp->geoms[i]);
538  sfcgal_triangulated_surface_add_triangle(ret_geom, g);
539  }
540 
541  return ret_geom;
542  }
543  break;
544 
545  default:
546  lwerror("LWGEOM2SFCGAL: Unknown geometry type !");
547  return NULL;
548  }
549 }
#define LINETYPE
Definition: liblwgeom.h:71
uint8_t flags
Definition: liblwgeom.h:553
POINTARRAY * points
Definition: liblwgeom.h:417
static sfcgal_geometry_t * ptarray_to_SFCGAL(const POINTARRAY *pa, int type)
#define POLYGONTYPE
Definition: liblwgeom.h:72
#define MULTIPOINTTYPE
Definition: liblwgeom.h:73
#define TRIANGLETYPE
Definition: liblwgeom.h:83
#define POLYHEDRALSURFACETYPE
Definition: liblwgeom.h:82
LWPOLY ** geoms
Definition: liblwgeom.h:558
#define FLAGS_GET_SOLID(flags)
Definition: liblwgeom.h:129
POINTARRAY * point
Definition: liblwgeom.h:395
int ngeoms
Definition: liblwgeom.h:569
sfcgal_geometry_t * LWGEOM2SFCGAL(const LWGEOM *geom)
LWGEOM ** geoms
Definition: liblwgeom.h:493
#define TINTYPE
Definition: liblwgeom.h:84
LWTRIANGLE ** geoms
Definition: liblwgeom.h:571
POINTARRAY ** rings
Definition: liblwgeom.h:441
int nrings
Definition: liblwgeom.h:439
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:75
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:70
uint8_t type
Definition: liblwgeom.h:380
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:1297
#define MULTILINETYPE
Definition: liblwgeom.h:74
int ngeoms
Definition: liblwgeom.h:556
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:74
#define COLLECTIONTYPE
Definition: liblwgeom.h:76
POINTARRAY * points
Definition: liblwgeom.h:406

Here is the call graph for this function:

Here is the caller graph for this function: