28 #if POSTGIS_SFCGAL_VERSION >= 20100
29 #define sfcgal_triangulated_surface_num_triangles(g) sfcgal_triangulated_surface_num_patches((g))
30 #define sfcgal_triangulated_surface_triangle_n(g, i) sfcgal_triangulated_surface_patch_n((g), (i))
31 #define sfcgal_triangulated_surface_add_triangle(g, p) sfcgal_triangulated_surface_add_patch((g), (p))
32 #define sfcgal_polyhedral_surface_num_polygons(g) sfcgal_polyhedral_surface_num_patches((g))
33 #define sfcgal_polyhedral_surface_polygon_n(g, i) sfcgal_polyhedral_surface_patch_n((g), (i))
34 #define sfcgal_geometry_collection_num_geometries(g) sfcgal_geometry_num_geometries((g))
35 #define sfcgal_polyhedral_surface_add_polygon(g, p) sfcgal_polyhedral_surface_add_patch((g), (p))
46 const char *version = sfcgal_version();
50 #define MAX_LENGTH_SFCGAL_FULL_VERSION 50
55 #if POSTGIS_SFCGAL_VERSION >= 10400
56 const char *version = sfcgal_full_version();
61 "SFCGAL=\"%s\" CGAL=\"Unknown\" Boost=\"Unknown\"",
77 case SFCGAL_TYPE_POINT:
80 case SFCGAL_TYPE_LINESTRING:
83 case SFCGAL_TYPE_POLYGON:
86 case SFCGAL_TYPE_MULTIPOINT:
89 case SFCGAL_TYPE_MULTILINESTRING:
92 case SFCGAL_TYPE_MULTIPOLYGON:
95 case SFCGAL_TYPE_MULTISOLID:
100 case SFCGAL_TYPE_GEOMETRYCOLLECTION:
104 case SFCGAL_TYPE_CIRCULARSTRING:
107 case SFCGAL_TYPE_COMPOUNDCURVE:
110 case SFCGAL_TYPE_CURVEPOLYGON:
113 case SFCGAL_TYPE_MULTICURVE:
116 case SFCGAL_TYPE_MULTISURFACE:
120 case SFCGAL_TYPE_POLYHEDRALSURFACE:
123 case SFCGAL_TYPE_TRIANGULATEDSURFACE:
126 case SFCGAL_TYPE_TRIANGLE:
130 lwerror(
"SFCGAL_type_to_lwgeom_type: Unknown Type");
152 is_3d = sfcgal_geometry_is_3d(geom);
154 #if POSTGIS_SFCGAL_VERSION >= 10308
155 is_measured = sfcgal_geometry_is_measured(geom);
158 switch (sfcgal_geometry_type_id(geom))
160 case SFCGAL_TYPE_POINT: {
162 point.
x = sfcgal_point_x(geom);
163 point.
y = sfcgal_point_y(geom);
166 point.
z = sfcgal_point_z(geom);
170 #if POSTGIS_SFCGAL_VERSION >= 10308
172 point.
m = sfcgal_point_m(geom);
179 case SFCGAL_TYPE_LINESTRING: {
180 npoints = sfcgal_linestring_num_points(geom);
183 for (i = 0; i < npoints; i++)
185 const sfcgal_geometry_t *pt = sfcgal_linestring_point_n(geom, i);
186 point.
x = sfcgal_point_x(pt);
187 point.
y = sfcgal_point_y(pt);
190 point.
z = sfcgal_point_z(pt);
194 #if POSTGIS_SFCGAL_VERSION >= 10308
196 point.
m = sfcgal_point_m(pt);
204 case SFCGAL_TYPE_TRIANGLE: {
207 for (i = 0; i < 4; i++)
209 const sfcgal_geometry_t *pt = sfcgal_triangle_vertex(geom, (i % 3));
210 point.
x = sfcgal_point_x(pt);
211 point.
y = sfcgal_point_y(pt);
214 point.
z = sfcgal_point_z(pt);
218 #if POSTGIS_SFCGAL_VERSION >= 10308
220 point.
m = sfcgal_point_m(pt);
230 lwerror(
"ptarray_from_SFCGAL: Unknown Type");
239 static sfcgal_geometry_t *
242 #if POSTGIS_SFCGAL_VERSION >= 10500
243 if (is_3d && is_measured)
244 return sfcgal_point_create_from_xyzm(
x,
y, z, m);
246 return sfcgal_point_create_from_xyz(
x,
y, z);
247 else if (is_measured)
248 return sfcgal_point_create_from_xym(
x,
y, m);
250 return sfcgal_point_create_from_xy(
x,
y);
255 return sfcgal_point_create_from_xyz(
x,
y, z);
257 return sfcgal_point_create_from_xy(
x,
y);
264 static sfcgal_geometry_t *
268 int is_3d, is_measured;
284 sfcgal_geometry_t *line = sfcgal_linestring_create();
285 for (i = 0; i < pa->
npoints; i++)
288 sfcgal_linestring_add_point(
296 sfcgal_geometry_t *triangle = sfcgal_triangle_create();
297 for (i = 0; i < 3; i++)
300 sfcgal_geometry_t *vertex =
304 sfcgal_triangle_set_vertex(triangle, i, vertex);
305 sfcgal_geometry_delete(vertex);
312 lwerror(
"ptarray_to_SFCGAL: Unknown Type");
325 uint32_t ngeoms, nshells, nsolids;
331 want3d = force3D || sfcgal_geometry_is_3d(geom);
333 switch (sfcgal_geometry_type_id(geom))
335 case SFCGAL_TYPE_POINT: {
336 if (sfcgal_geometry_is_empty(geom))
343 case SFCGAL_TYPE_LINESTRING: {
344 if (sfcgal_geometry_is_empty(geom))
351 case SFCGAL_TYPE_TRIANGLE: {
352 if (sfcgal_geometry_is_empty(geom))
359 case SFCGAL_TYPE_POLYGON: {
360 if (sfcgal_geometry_is_empty(geom))
363 uint32_t nrings = sfcgal_polygon_num_interior_rings(geom) + 1;
367 for (i = 1; i < nrings; i++)
373 case SFCGAL_TYPE_MULTIPOINT:
374 case SFCGAL_TYPE_MULTILINESTRING:
375 case SFCGAL_TYPE_MULTIPOLYGON:
376 case SFCGAL_TYPE_MULTISOLID:
377 case SFCGAL_TYPE_GEOMETRYCOLLECTION: {
378 ngeoms = sfcgal_geometry_collection_num_geometries(geom);
384 for (i = 0; i < ngeoms; i++)
386 const sfcgal_geometry_t *g = sfcgal_geometry_collection_geometry_n(geom, i);
397 if (ngeoms == nsolids)
401 "SFCGAL2LWGEOM: SOLID in heterogeneous collection will be treated as a POLYHEDRALSURFACETYPE");
407 case SFCGAL_TYPE_CIRCULARSTRING:
408 case SFCGAL_TYPE_COMPOUNDCURVE:
409 case SFCGAL_TYPE_CURVEPOLYGON:
410 case SFCGAL_TYPE_MULTICURVE:
411 case SFCGAL_TYPE_MULTISURFACE:
412 case SFCGAL_TYPE_CURVE:
413 case SFCGAL_TYPE_SURFACE:
418 case SFCGAL_TYPE_POLYHEDRALSURFACE: {
419 ngeoms = sfcgal_polyhedral_surface_num_polygons(geom);
425 for (i = 0; i < ngeoms; i++)
427 const sfcgal_geometry_t *g = sfcgal_polyhedral_surface_polygon_n(geom, i);
435 case SFCGAL_TYPE_SOLID: {
436 nshells = sfcgal_solid_num_shells(geom);
438 for (ngeoms = 0, i = 0; i < nshells; i++)
439 ngeoms += sfcgal_polyhedral_surface_num_polygons(sfcgal_solid_shell_n(geom, i));
445 for (i = 0, k = 0; i < nshells; i++)
447 const sfcgal_geometry_t *shell = sfcgal_solid_shell_n(geom, i);
448 ngeoms = sfcgal_polyhedral_surface_num_polygons(shell);
450 for (j = 0; j < ngeoms; j++)
452 const sfcgal_geometry_t *g = sfcgal_polyhedral_surface_polygon_n(shell, j);
464 case SFCGAL_TYPE_TRIANGULATEDSURFACE: {
465 ngeoms = sfcgal_triangulated_surface_num_triangles(geom);
470 for (i = 0; i < ngeoms; i++)
472 const sfcgal_geometry_t *g = sfcgal_triangulated_surface_triangle_n(geom, i);
480 lwerror(
"SFCGAL2LWGEOM: Unknown Type");
489 sfcgal_geometry_t *ret_geom = NULL;
498 return sfcgal_point_create();
507 return sfcgal_linestring_create();
516 return sfcgal_triangle_create();
523 uint32_t nrings = poly->
nrings - 1;
526 return sfcgal_polygon_create();
529 ret_geom = sfcgal_polygon_create_from_exterior_ring(exterior_ring);
531 for (i = 0; i < nrings; i++)
534 sfcgal_polygon_add_interior_ring(ret_geom, ring);
545 ret_geom = sfcgal_multi_point_create();
547 ret_geom = sfcgal_multi_linestring_create();
549 ret_geom = sfcgal_multi_polygon_create();
551 ret_geom = sfcgal_geometry_collection_create();
554 for (i = 0; i < lwc->
ngeoms; i++)
557 sfcgal_geometry_collection_add_geometry(ret_geom, g);
566 ret_geom = sfcgal_polyhedral_surface_create();
568 for (i = 0; i < lwp->
ngeoms; i++)
571 sfcgal_polyhedral_surface_add_polygon(ret_geom, g);
577 return sfcgal_solid_create_from_exterior_shell(ret_geom);
586 ret_geom = sfcgal_triangulated_surface_create();
588 for (i = 0; i < lwp->
ngeoms; i++)
591 sfcgal_triangulated_surface_add_triangle(ret_geom, g);
611 sfcgal_geometry_t *converted;
619 sfcgal_geometry_delete(converted);
LWPOINT * lwpoint_construct_empty(int32_t srid, char hasz, char hasm)
POINTARRAY * ptarray_construct(char hasz, char hasm, uint32_t npoints)
Construct an empty pointarray, allocating storage and setting the npoints, but not filling in any inf...
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
#define FLAGS_GET_Z(flags)
LWLINE * lwline_construct(int32_t srid, GBOX *bbox, POINTARRAY *points)
LWTRIANGLE * lwtriangle_construct_empty(int32_t srid, char hasz, char hasm)
void * lwrealloc(void *mem, size_t size)
LWPOINT * lwpoint_construct(int32_t srid, GBOX *bbox, POINTARRAY *point)
#define POLYHEDRALSURFACETYPE
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
#define FLAGS_GET_M(flags)
int getPoint4d_p(const POINTARRAY *pa, uint32_t n, POINT4D *point)
#define FLAGS_GET_SOLID(flags)
void * lwalloc(size_t size)
LWCOLLECTION * lwcollection_construct(uint8_t type, int32_t srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms)
#define SRID_UNKNOWN
Unknown SRID value.
LWPOLY * lwpoly_construct_empty(int32_t srid, char hasz, char hasm)
LWPOLY * lwpoly_construct(int32_t srid, GBOX *bbox, uint32_t nrings, POINTARRAY **points)
#define FLAGS_SET_SOLID(flags, value)
void ptarray_set_point4d(POINTARRAY *pa, uint32_t n, const POINT4D *p4d)
LWLINE * lwline_construct_empty(int32_t srid, char hasz, char hasm)
LWTRIANGLE * lwtriangle_construct(int32_t srid, GBOX *bbox, POINTARRAY *points)
void lwnotice(const char *fmt,...) __attribute__((format(printf
Write a notice out to the notice handler.
void void lwerror(const char *fmt,...) __attribute__((format(printf
Write a notice out to the error handler.
sfcgal_geometry_t * LWGEOM2SFCGAL(const LWGEOM *geom)
static POINTARRAY * ptarray_from_SFCGAL(const sfcgal_geometry_t *geom, int force3D)
static int SFCGAL_type_to_lwgeom_type(sfcgal_geometry_type_t type)
LWGEOM * lwgeom_sfcgal_noop(const LWGEOM *geom_in)
LWGEOM * SFCGAL2LWGEOM(const sfcgal_geometry_t *geom, int force3D, int32_t srid)
const char * lwgeom_sfcgal_version()
#define MAX_LENGTH_SFCGAL_FULL_VERSION
static sfcgal_geometry_t * create_sfcgal_point_by_dimensions(double x, double y, double z, double m, int is_3d, int is_measured)
Create a SFCGAL point based on dimensional flags (XY, XYZ, XYM, XYZM).
const char * lwgeom_sfcgal_full_version()
static sfcgal_geometry_t * ptarray_to_SFCGAL(const POINTARRAY *pa, int type)
Convert a PostGIS pointarray to SFCGAL structure.
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)