38 const char *version = sfcgal_version();
53 case SFCGAL_TYPE_POINT:
56 case SFCGAL_TYPE_LINESTRING:
59 case SFCGAL_TYPE_POLYGON:
62 case SFCGAL_TYPE_MULTIPOINT:
65 case SFCGAL_TYPE_MULTILINESTRING:
68 case SFCGAL_TYPE_MULTIPOLYGON:
71 case SFCGAL_TYPE_MULTISOLID:
76 case SFCGAL_TYPE_GEOMETRYCOLLECTION:
80 case SFCGAL_TYPE_CIRCULARSTRING:
83 case SFCGAL_TYPE_COMPOUNDCURVE:
86 case SFCGAL_TYPE_CURVEPOLYGON:
89 case SFCGAL_TYPE_MULTICURVE:
92 case SFCGAL_TYPE_MULTISURFACE:
96 case SFCGAL_TYPE_POLYHEDRALSURFACE:
99 case SFCGAL_TYPE_TRIANGULATEDSURFACE:
102 case SFCGAL_TYPE_TRIANGLE:
106 lwerror(
"SFCGAL_type_to_lwgeom_type: Unknown Type");
127 switch (sfcgal_geometry_type_id(geom))
129 case SFCGAL_TYPE_POINT:
132 point.
x = sfcgal_point_x(geom);
133 point.
y = sfcgal_point_y(geom);
135 if (sfcgal_geometry_is_3d(geom))
136 point.
z = sfcgal_point_z(geom);
144 case SFCGAL_TYPE_LINESTRING:
146 npoints = sfcgal_linestring_num_points(geom);
149 for (i = 0; i < npoints; i++)
151 const sfcgal_geometry_t* pt = sfcgal_linestring_point_n(geom, i);
152 point.
x = sfcgal_point_x(pt);
153 point.
y = sfcgal_point_y(pt);
155 if (sfcgal_geometry_is_3d(geom))
156 point.
z = sfcgal_point_z(pt);
165 case SFCGAL_TYPE_TRIANGLE:
169 for (i = 0; i < 4; i++)
171 const sfcgal_geometry_t* pt = sfcgal_triangle_vertex(geom, (i%3));
172 point.
x = sfcgal_point_x(pt);
173 point.
y = sfcgal_point_y(pt);
175 if ( sfcgal_geometry_is_3d(geom))
176 point.
z = sfcgal_point_z(pt);
187 lwerror(
"ptarray_from_SFCGAL: Unknown Type");
200 static sfcgal_geometry_t*
216 if (is_3d)
return sfcgal_point_create_from_xyz(point.
x, point.
y, point.
z);
217 else return sfcgal_point_create_from_xy(point.
x, point.
y);
223 sfcgal_geometry_t* line = sfcgal_linestring_create();
225 for (i = 0; i < pa->
npoints; i++)
230 sfcgal_linestring_add_point(line,
231 sfcgal_point_create_from_xyz(point.
x, point.
y, point.
z));
235 sfcgal_linestring_add_point(line,
236 sfcgal_point_create_from_xy(point.
x, point.
y));
246 sfcgal_geometry_t* triangle = sfcgal_triangle_create();
249 if (is_3d) sfcgal_triangle_set_vertex_from_xyz(triangle, 0, point.
x, point.
y, point.
z);
250 else sfcgal_triangle_set_vertex_from_xy (triangle, 0, point.
x, point.
y);
253 if (is_3d) sfcgal_triangle_set_vertex_from_xyz(triangle, 1, point.
x, point.
y, point.
z);
254 else sfcgal_triangle_set_vertex_from_xy (triangle, 1, point.
x, point.
y);
257 if (is_3d) sfcgal_triangle_set_vertex_from_xyz(triangle, 2, point.
x, point.
y, point.
z);
258 else sfcgal_triangle_set_vertex_from_xy (triangle, 2, point.
x, point.
y);
266 lwerror(
"ptarray_from_SFCGAL: Unknown Type");
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);
353 sfcgal_geometry_type_id(geom)), srid, NULL, ngeoms, geoms);
357 else if ( nsolids )
lwnotice(
"SFCGAL2LWGEOM: SOLID in heterogeneous collection will be treated as a POLYHEDRALSURFACETYPE");
363 case SFCGAL_TYPE_CIRCULARSTRING:
364 case SFCGAL_TYPE_COMPOUNDCURVE:
365 case SFCGAL_TYPE_CURVEPOLYGON:
366 case SFCGAL_TYPE_MULTICURVE:
367 case SFCGAL_TYPE_MULTISURFACE:
368 case SFCGAL_TYPE_CURVE:
369 case SFCGAL_TYPE_SURFACE:
374 case SFCGAL_TYPE_POLYHEDRALSURFACE:
376 ngeoms = sfcgal_polyhedral_surface_num_polygons(geom);
382 for (i = 0; i < ngeoms; i++)
384 const sfcgal_geometry_t* g = sfcgal_polyhedral_surface_polygon_n( geom, i );
392 case SFCGAL_TYPE_SOLID:
394 nshells = sfcgal_solid_num_shells(geom);
396 for (ngeoms = 0, i = 0; i < nshells; i++)
397 ngeoms += sfcgal_polyhedral_surface_num_polygons(sfcgal_solid_shell_n(geom, i));
403 for (i = 0, k =0 ; i < nshells; i++)
405 const sfcgal_geometry_t* shell = sfcgal_solid_shell_n(geom, i);
406 ngeoms = sfcgal_polyhedral_surface_num_polygons(shell);
408 for (j = 0; j < ngeoms; j++)
410 const sfcgal_geometry_t* g = sfcgal_polyhedral_surface_polygon_n(shell, j);
421 case SFCGAL_TYPE_TRIANGULATEDSURFACE:
423 ngeoms = sfcgal_triangulated_surface_num_triangles(geom);
428 for (i = 0; i < ngeoms; i++)
430 const sfcgal_geometry_t* g = sfcgal_triangulated_surface_triangle_n(geom, i);
438 lwerror(
"SFCGAL2LWGEOM: Unknown Type");
448 sfcgal_geometry_t* ret_geom = NULL;
488 ret_geom = sfcgal_polygon_create_from_exterior_ring(exterior_ring);
490 for (i = 0; i < nrings; i++)
493 sfcgal_polygon_add_interior_ring(ret_geom, ring);
505 else if (geom->
type ==
MULTILINETYPE) ret_geom = sfcgal_multi_linestring_create();
507 else ret_geom = sfcgal_geometry_collection_create();
510 for (i = 0; i < lwc->
ngeoms; i++)
513 sfcgal_geometry_collection_add_geometry(ret_geom, g);
523 ret_geom = sfcgal_polyhedral_surface_create();
525 for (i = 0; i < lwp->
ngeoms; i++)
528 sfcgal_polyhedral_surface_add_polygon(ret_geom, g);
534 return sfcgal_solid_create_from_exterior_shell(ret_geom);
544 ret_geom = sfcgal_triangulated_surface_create();
546 for (i = 0; i < lwp->
ngeoms; i++)
549 sfcgal_triangulated_surface_add_triangle(ret_geom, g);
557 lwerror(
"LWGEOM2SFCGAL: Unknown geometry type !");
569 sfcgal_geometry_t* converted;
577 sfcgal_geometry_delete(converted);
void ptarray_set_point4d(POINTARRAY *pa, int n, const POINT4D *p4d)
LWGEOM * lwgeom_sfcgal_noop(const LWGEOM *geom_in)
#define FLAGS_SET_SOLID(flags, value)
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...
LWLINE * lwline_construct_empty(int srid, char hasz, char hasm)
static sfcgal_geometry_t * ptarray_to_SFCGAL(const POINTARRAY *pa, int type)
LWCOLLECTION * lwcollection_construct(uint8_t type, int srid, GBOX *bbox, uint32_t ngeoms, LWGEOM **geoms)
void lwnotice(const char *fmt,...)
Write a notice out to the notice handler.
LWTRIANGLE * lwtriangle_construct_empty(int srid, char hasz, char hasm)
#define POLYHEDRALSURFACETYPE
#define FLAGS_GET_SOLID(flags)
LWPOINT * lwpoint_construct_empty(int srid, char hasz, char hasm)
const char * lwgeom_sfcgal_version()
int getPoint3dz_p(const POINTARRAY *pa, int n, POINT3DZ *point)
sfcgal_geometry_t * LWGEOM2SFCGAL(const LWGEOM *geom)
static int SFCGAL_type_to_lwgeom_type(sfcgal_geometry_type_t type)
LWPOLY * lwpoly_construct(int srid, GBOX *bbox, uint32_t nrings, POINTARRAY **points)
LWLINE * lwline_construct(int srid, GBOX *bbox, POINTARRAY *points)
#define SRID_UNKNOWN
Unknown SRID value.
#define FLAGS_GET_Z(flags)
Macros for manipulating the 'flags' byte.
LWTRIANGLE * lwtriangle_construct(int srid, GBOX *bbox, POINTARRAY *points)
static POINTARRAY * ptarray_from_SFCGAL(const sfcgal_geometry_t *geom, int force3D)
void * lwrealloc(void *mem, size_t size)
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
LWPOLY * lwpoly_construct_empty(int srid, char hasz, char hasm)
LWPOINT * lwpoint_construct(int srid, GBOX *bbox, POINTARRAY *point)
void * lwalloc(size_t size)
int lwgeom_is_empty(const LWGEOM *geom)
Return true or false depending on whether a geometry is an "empty" geometry (no vertices members) ...
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
LWGEOM * SFCGAL2LWGEOM(const sfcgal_geometry_t *geom, int force3D, int srid)