35 const char *version = sfcgal_version();
49 case SFCGAL_TYPE_POINT:
52 case SFCGAL_TYPE_LINESTRING:
55 case SFCGAL_TYPE_POLYGON:
58 case SFCGAL_TYPE_MULTIPOINT:
61 case SFCGAL_TYPE_MULTILINESTRING:
64 case SFCGAL_TYPE_MULTIPOLYGON:
67 case SFCGAL_TYPE_MULTISOLID:
72 case SFCGAL_TYPE_GEOMETRYCOLLECTION:
76 case SFCGAL_TYPE_CIRCULARSTRING:
79 case SFCGAL_TYPE_COMPOUNDCURVE:
82 case SFCGAL_TYPE_CURVEPOLYGON:
85 case SFCGAL_TYPE_MULTICURVE:
88 case SFCGAL_TYPE_MULTISURFACE:
92 case SFCGAL_TYPE_POLYHEDRALSURFACE:
95 case SFCGAL_TYPE_TRIANGULATEDSURFACE:
98 case SFCGAL_TYPE_TRIANGLE:
102 lwerror(
"SFCGAL_type_to_lwgeom_type: Unknown Type");
122 switch (sfcgal_geometry_type_id(geom))
124 case SFCGAL_TYPE_POINT:
127 point.
x = sfcgal_point_x(geom);
128 point.
y = sfcgal_point_y(geom);
130 if (sfcgal_geometry_is_3d(geom))
131 point.
z = sfcgal_point_z(geom);
139 case SFCGAL_TYPE_LINESTRING:
141 npoints = sfcgal_linestring_num_points(geom);
144 for (i = 0; i < npoints; i++)
146 const sfcgal_geometry_t *pt = sfcgal_linestring_point_n(geom, i);
147 point.
x = sfcgal_point_x(pt);
148 point.
y = sfcgal_point_y(pt);
150 if (sfcgal_geometry_is_3d(geom))
151 point.
z = sfcgal_point_z(pt);
160 case SFCGAL_TYPE_TRIANGLE:
164 for (i = 0; i < 4; i++)
166 const sfcgal_geometry_t *pt = sfcgal_triangle_vertex(geom, (i % 3));
167 point.
x = sfcgal_point_x(pt);
168 point.
y = sfcgal_point_y(pt);
170 if (sfcgal_geometry_is_3d(geom))
171 point.
z = sfcgal_point_z(pt);
182 lwerror(
"ptarray_from_SFCGAL: Unknown Type");
194 static sfcgal_geometry_t *
211 return sfcgal_point_create_from_xyz(point.
x, point.
y, point.
z);
213 return sfcgal_point_create_from_xy(point.
x, point.
y);
219 sfcgal_geometry_t *line = sfcgal_linestring_create();
221 for (i = 0; i < pa->
npoints; i++)
226 sfcgal_linestring_add_point(line,
227 sfcgal_point_create_from_xyz(point.
x, point.
y, point.
z));
231 sfcgal_linestring_add_point(line, sfcgal_point_create_from_xy(point.
x, point.
y));
241 sfcgal_geometry_t *triangle = sfcgal_triangle_create();
245 sfcgal_triangle_set_vertex_from_xyz(triangle, 0, point.
x, point.
y, point.
z);
247 sfcgal_triangle_set_vertex_from_xy(triangle, 0, point.
x, point.
y);
251 sfcgal_triangle_set_vertex_from_xyz(triangle, 1, point.
x, point.
y, point.
z);
253 sfcgal_triangle_set_vertex_from_xy(triangle, 1, point.
x, point.
y);
257 sfcgal_triangle_set_vertex_from_xyz(triangle, 2, point.
x, point.
y, point.
z);
259 sfcgal_triangle_set_vertex_from_xy(triangle, 2, point.
x, point.
y);
267 lwerror(
"ptarray_from_SFCGAL: Unknown Type");
280 uint32_t ngeoms, nshells, nsolids;
286 want3d = force3D || sfcgal_geometry_is_3d(geom);
288 switch (sfcgal_geometry_type_id(geom))
290 case SFCGAL_TYPE_POINT:
292 if (sfcgal_geometry_is_empty(geom))
299 case SFCGAL_TYPE_LINESTRING:
301 if (sfcgal_geometry_is_empty(geom))
308 case SFCGAL_TYPE_TRIANGLE:
310 if (sfcgal_geometry_is_empty(geom))
317 case SFCGAL_TYPE_POLYGON:
319 if (sfcgal_geometry_is_empty(geom))
322 uint32_t nrings = sfcgal_polygon_num_interior_rings(geom) + 1;
326 for (i = 1; i < nrings; i++)
332 case SFCGAL_TYPE_MULTIPOINT:
333 case SFCGAL_TYPE_MULTILINESTRING:
334 case SFCGAL_TYPE_MULTIPOLYGON:
335 case SFCGAL_TYPE_MULTISOLID:
336 case SFCGAL_TYPE_GEOMETRYCOLLECTION:
338 ngeoms = sfcgal_geometry_collection_num_geometries(geom);
344 for (i = 0; i < ngeoms; i++)
346 const sfcgal_geometry_t *g = sfcgal_geometry_collection_geometry_n(geom, i);
357 if (ngeoms == nsolids)
361 "SFCGAL2LWGEOM: SOLID in heterogeneous collection will be treated as a POLYHEDRALSURFACETYPE");
367 case SFCGAL_TYPE_CIRCULARSTRING:
368 case SFCGAL_TYPE_COMPOUNDCURVE:
369 case SFCGAL_TYPE_CURVEPOLYGON:
370 case SFCGAL_TYPE_MULTICURVE:
371 case SFCGAL_TYPE_MULTISURFACE:
372 case SFCGAL_TYPE_CURVE:
373 case SFCGAL_TYPE_SURFACE:
378 case SFCGAL_TYPE_POLYHEDRALSURFACE:
380 ngeoms = sfcgal_polyhedral_surface_num_polygons(geom);
386 for (i = 0; i < ngeoms; i++)
388 const sfcgal_geometry_t *g = sfcgal_polyhedral_surface_polygon_n(geom, i);
396 case SFCGAL_TYPE_SOLID:
398 nshells = sfcgal_solid_num_shells(geom);
400 for (ngeoms = 0, i = 0; i < nshells; i++)
401 ngeoms += sfcgal_polyhedral_surface_num_polygons(sfcgal_solid_shell_n(geom, i));
407 for (i = 0, k = 0; i < nshells; i++)
409 const sfcgal_geometry_t *shell = sfcgal_solid_shell_n(geom, i);
410 ngeoms = sfcgal_polyhedral_surface_num_polygons(shell);
412 for (j = 0; j < ngeoms; j++)
414 const sfcgal_geometry_t *g = sfcgal_polyhedral_surface_polygon_n(shell, j);
426 case SFCGAL_TYPE_TRIANGULATEDSURFACE:
428 ngeoms = sfcgal_triangulated_surface_num_triangles(geom);
433 for (i = 0; i < ngeoms; i++)
435 const sfcgal_geometry_t *g = sfcgal_triangulated_surface_triangle_n(geom, i);
443 lwerror(
"SFCGAL2LWGEOM: Unknown Type");
452 sfcgal_geometry_t *ret_geom = NULL;
462 return sfcgal_point_create();
472 return sfcgal_linestring_create();
482 return sfcgal_triangle_create();
490 uint32_t nrings = poly->
nrings - 1;
493 return sfcgal_polygon_create();
496 ret_geom = sfcgal_polygon_create_from_exterior_ring(exterior_ring);
498 for (i = 0; i < nrings; i++)
501 sfcgal_polygon_add_interior_ring(ret_geom, ring);
513 ret_geom = sfcgal_multi_point_create();
515 ret_geom = sfcgal_multi_linestring_create();
517 ret_geom = sfcgal_multi_polygon_create();
519 ret_geom = sfcgal_geometry_collection_create();
522 for (i = 0; i < lwc->
ngeoms; i++)
525 sfcgal_geometry_collection_add_geometry(ret_geom, g);
535 ret_geom = sfcgal_polyhedral_surface_create();
537 for (i = 0; i < lwp->
ngeoms; i++)
540 sfcgal_polyhedral_surface_add_polygon(ret_geom, g);
546 return sfcgal_solid_create_from_exterior_shell(ret_geom);
556 ret_geom = sfcgal_triangulated_surface_create();
558 for (i = 0; i < lwp->
ngeoms; i++)
561 sfcgal_triangulated_surface_add_triangle(ret_geom, g);
569 lwerror(
"LWGEOM2SFCGAL: Unknown geometry type !");
581 sfcgal_geometry_t *converted;
589 sfcgal_geometry_delete(converted);
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()
static sfcgal_geometry_t * ptarray_to_SFCGAL(const POINTARRAY *pa, int type)
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)
int getPoint3dz_p(const POINTARRAY *pa, uint32_t n, POINT3DZ *point)
void * lwrealloc(void *mem, size_t size)
LWPOINT * lwpoint_construct(int32_t srid, GBOX *bbox, POINTARRAY *point)
#define POLYHEDRALSURFACETYPE
#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 lwerror(const char *fmt,...)
Write a notice out to the error handler.
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
static int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members)