PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ LWGEOM2SFCGAL()

sfcgal_geometry_t* LWGEOM2SFCGAL ( const LWGEOM geom)

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

446 {
447  uint32_t i;
448  sfcgal_geometry_t* ret_geom = NULL;
449 
450  assert(geom);
451 
452  switch (geom->type)
453  {
454  case POINTTYPE:
455  {
456  const LWPOINT* lwp = (const LWPOINT*) geom;
457  if (lwgeom_is_empty(geom)) return sfcgal_point_create();
458 
459  return ptarray_to_SFCGAL(lwp->point, POINTTYPE);
460  }
461  break;
462 
463  case LINETYPE:
464  {
465  const LWLINE* line = (const LWLINE*) geom;
466  if (lwgeom_is_empty(geom)) return sfcgal_linestring_create();
467 
468  return ptarray_to_SFCGAL(line->points, LINETYPE);
469  }
470  break;
471 
472  case TRIANGLETYPE:
473  {
474  const LWTRIANGLE* triangle = (const LWTRIANGLE*) geom;
475  if (lwgeom_is_empty(geom)) return sfcgal_triangle_create();
476  return ptarray_to_SFCGAL(triangle->points, TRIANGLETYPE);
477  }
478  break;
479 
480  case POLYGONTYPE:
481  {
482  const LWPOLY* poly = (const LWPOLY*) geom;
483  uint32_t nrings = poly->nrings - 1;
484 
485  if (lwgeom_is_empty(geom)) return sfcgal_polygon_create();
486 
487  sfcgal_geometry_t* exterior_ring = ptarray_to_SFCGAL(poly->rings[0], LINETYPE);
488  ret_geom = sfcgal_polygon_create_from_exterior_ring(exterior_ring);
489 
490  for (i = 0; i < nrings; i++)
491  {
492  sfcgal_geometry_t* ring = ptarray_to_SFCGAL(poly->rings[i + 1], LINETYPE);
493  sfcgal_polygon_add_interior_ring(ret_geom, ring);
494  }
495  return ret_geom;
496  }
497  break;
498 
499  case MULTIPOINTTYPE:
500  case MULTILINETYPE:
501  case MULTIPOLYGONTYPE:
502  case COLLECTIONTYPE:
503  {
504  if (geom->type == MULTIPOINTTYPE) ret_geom = sfcgal_multi_point_create();
505  else if (geom->type == MULTILINETYPE) ret_geom = sfcgal_multi_linestring_create();
506  else if (geom->type == MULTIPOLYGONTYPE) ret_geom = sfcgal_multi_polygon_create();
507  else ret_geom = sfcgal_geometry_collection_create();
508 
509  const LWCOLLECTION* lwc = (const LWCOLLECTION*)geom;
510  for (i = 0; i < lwc->ngeoms; i++)
511  {
512  sfcgal_geometry_t* g = LWGEOM2SFCGAL(lwc->geoms[i]);
513  sfcgal_geometry_collection_add_geometry(ret_geom, g);
514  }
515 
516  return ret_geom;
517  }
518  break;
519 
521  {
522  const LWPSURFACE* lwp = (const LWPSURFACE*) geom;
523  ret_geom = sfcgal_polyhedral_surface_create();
524 
525  for (i = 0; i < lwp->ngeoms; i++)
526  {
527  sfcgal_geometry_t* g = LWGEOM2SFCGAL((const LWGEOM*) lwp->geoms[i]);
528  sfcgal_polyhedral_surface_add_polygon(ret_geom, g);
529  }
530  /* We treat polyhedral surface as the only exterior shell,
531  since we can't distinguish exterior from interior shells ... */
532  if (FLAGS_GET_SOLID(lwp->flags))
533  {
534  return sfcgal_solid_create_from_exterior_shell(ret_geom);
535  }
536 
537  return ret_geom;
538  }
539  break;
540 
541  case TINTYPE:
542  {
543  const LWTIN* lwp = (const LWTIN*) geom;
544  ret_geom = sfcgal_triangulated_surface_create();
545 
546  for (i = 0; i < lwp->ngeoms; i++)
547  {
548  sfcgal_geometry_t* g = LWGEOM2SFCGAL((const LWGEOM*) lwp->geoms[i]);
549  sfcgal_triangulated_surface_add_triangle(ret_geom, g);
550  }
551 
552  return ret_geom;
553  }
554  break;
555 
556  default:
557  lwerror("LWGEOM2SFCGAL: Unknown geometry type !");
558  return NULL;
559  }
560 }
#define LINETYPE
Definition: liblwgeom.h:86
uint8_t flags
Definition: liblwgeom.h:569
POINTARRAY * points
Definition: liblwgeom.h:433
static sfcgal_geometry_t * ptarray_to_SFCGAL(const POINTARRAY *pa, int type)
#define POLYGONTYPE
Definition: liblwgeom.h:87
#define MULTIPOINTTYPE
Definition: liblwgeom.h:88
#define TRIANGLETYPE
Definition: liblwgeom.h:98
#define POLYHEDRALSURFACETYPE
Definition: liblwgeom.h:97
LWPOLY ** geoms
Definition: liblwgeom.h:574
#define FLAGS_GET_SOLID(flags)
Definition: liblwgeom.h:145
POINTARRAY * point
Definition: liblwgeom.h:411
unsigned int uint32_t
Definition: uthash.h:78
int ngeoms
Definition: liblwgeom.h:585
sfcgal_geometry_t * LWGEOM2SFCGAL(const LWGEOM *geom)
LWGEOM ** geoms
Definition: liblwgeom.h:509
#define TINTYPE
Definition: liblwgeom.h:99
LWTRIANGLE ** geoms
Definition: liblwgeom.h:587
POINTARRAY ** rings
Definition: liblwgeom.h:457
int nrings
Definition: liblwgeom.h:455
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:90
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:85
uint8_t type
Definition: liblwgeom.h:396
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:1346
#define MULTILINETYPE
Definition: liblwgeom.h:89
int ngeoms
Definition: liblwgeom.h:572
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
#define COLLECTIONTYPE
Definition: liblwgeom.h:91
POINTARRAY * points
Definition: liblwgeom.h:422
Here is the call graph for this function:
Here is the caller graph for this function: