27 #include "utils/builtins.h"
28 #include "../liblwgeom/liblwgeom.h"
30 #include "lwgeom_pg.h"
32 #include "../postgis_config.h"
66 sfcgal_set_error_handlers((sfcgal_error_handler_t)(
void *)lwpgnotice,
67 (sfcgal_error_handler_t)(
void *)lwpgerror);
81 lwpgerror(
"POSTGIS2SFCGALGeometry: Unable to deserialize input");
90 sfcgal_prepared_geometry_t *
97 lwpgerror(
"POSTGIS2SFCGALPreparedGeometry: Unable to deserialize input");
127 sfcgal_prepared_geometry_geometry(geom), force3D, sfcgal_prepared_geometry_srid(geom));
135 sfcgal_prepared_geometry_t *g;
136 text *wkttext = PG_GETARG_TEXT_P(0);
141 g = sfcgal_io_read_ewkt(cstring, strlen(cstring));
144 sfcgal_prepared_geometry_delete(g);
145 PG_RETURN_POINTER(result);
152 sfcgal_geometry_t *geom;
157 input = PG_GETARG_GSERIALIZED_P(0);
160 result = sfcgal_geometry_area_3d(geom);
161 sfcgal_geometry_delete(geom);
163 PG_FREE_IF_COPY(input, 0);
165 PG_RETURN_FLOAT8(result);
172 sfcgal_geometry_t *geom;
177 input = PG_GETARG_GSERIALIZED_P(0);
180 result = sfcgal_geometry_is_planar(geom);
181 sfcgal_geometry_delete(geom);
183 PG_FREE_IF_COPY(input, 0);
185 PG_RETURN_BOOL(result);
192 sfcgal_geometry_t *geom;
197 input = PG_GETARG_GSERIALIZED_P(0);
200 result = sfcgal_geometry_orientation(geom);
201 sfcgal_geometry_delete(geom);
203 PG_FREE_IF_COPY(input, 0);
205 PG_RETURN_INT32(result);
212 sfcgal_geometry_t *geom;
213 sfcgal_geometry_t *result;
218 input = PG_GETARG_GSERIALIZED_P(0);
221 PG_FREE_IF_COPY(input, 0);
223 result = sfcgal_geometry_tesselate(geom);
224 sfcgal_geometry_delete(geom);
227 sfcgal_geometry_delete(result);
229 PG_RETURN_POINTER(output);
236 sfcgal_geometry_t *geom;
237 sfcgal_geometry_t *result;
242 input = PG_GETARG_GSERIALIZED_P(0);
245 PG_FREE_IF_COPY(input, 0);
247 result = sfcgal_geometry_triangulate_2dz(geom);
248 sfcgal_geometry_delete(geom);
251 sfcgal_geometry_delete(result);
253 PG_RETURN_POINTER(output);
260 sfcgal_geometry_t *geom;
261 sfcgal_geometry_t *result;
266 input = PG_GETARG_GSERIALIZED_P(0);
269 PG_FREE_IF_COPY(input, 0);
271 result = sfcgal_geometry_force_lhr(geom);
272 sfcgal_geometry_delete(geom);
275 sfcgal_geometry_delete(result);
277 PG_RETURN_POINTER(output);
284 sfcgal_geometry_t *geom;
285 sfcgal_geometry_t *result;
290 input = PG_GETARG_GSERIALIZED_P(0);
293 PG_FREE_IF_COPY(input, 0);
295 result = sfcgal_geometry_straight_skeleton(geom);
296 sfcgal_geometry_delete(geom);
299 sfcgal_geometry_delete(result);
301 PG_RETURN_POINTER(output);
308 sfcgal_geometry_t *geom;
309 sfcgal_geometry_t *result;
314 input = PG_GETARG_GSERIALIZED_P(0);
317 PG_FREE_IF_COPY(input, 0);
319 result = sfcgal_geometry_approximate_medial_axis(geom);
320 sfcgal_geometry_delete(geom);
323 sfcgal_geometry_delete(result);
325 PG_RETURN_POINTER(output);
332 sfcgal_geometry_t *geom0, *geom1;
333 sfcgal_geometry_t *result;
338 input0 = PG_GETARG_GSERIALIZED_P(0);
340 input1 = PG_GETARG_GSERIALIZED_P(1);
342 PG_FREE_IF_COPY(input0, 0);
344 PG_FREE_IF_COPY(input1, 1);
346 result = sfcgal_geometry_intersection_3d(geom0, geom1);
347 sfcgal_geometry_delete(geom0);
348 sfcgal_geometry_delete(geom1);
351 sfcgal_geometry_delete(result);
353 PG_RETURN_POINTER(output);
360 sfcgal_geometry_t *geom0, *geom1;
361 sfcgal_geometry_t *result;
366 input0 = (
GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
368 input1 = (
GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
370 PG_FREE_IF_COPY(input0, 0);
372 PG_FREE_IF_COPY(input1, 1);
374 result = sfcgal_geometry_difference_3d(geom0, geom1);
375 sfcgal_geometry_delete(geom0);
376 sfcgal_geometry_delete(geom1);
379 sfcgal_geometry_delete(result);
381 PG_RETURN_POINTER(output);
388 sfcgal_geometry_t *geom0, *geom1;
389 sfcgal_geometry_t *result;
394 input0 = (
GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
396 input1 = (
GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
398 PG_FREE_IF_COPY(input0, 0);
400 PG_FREE_IF_COPY(input1, 1);
402 result = sfcgal_geometry_union_3d(geom0, geom1);
403 sfcgal_geometry_delete(geom0);
404 sfcgal_geometry_delete(geom1);
407 sfcgal_geometry_delete(result);
409 PG_RETURN_POINTER(output);
416 sfcgal_geometry_t *geom;
421 input = (
GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
424 result = sfcgal_geometry_volume(geom);
425 sfcgal_geometry_delete(geom);
427 PG_FREE_IF_COPY(input, 0);
429 PG_RETURN_FLOAT8(result);
436 sfcgal_geometry_t *geom0, *geom1;
437 sfcgal_geometry_t *result;
442 input0 = PG_GETARG_GSERIALIZED_P(0);
444 input1 = PG_GETARG_GSERIALIZED_P(1);
446 PG_FREE_IF_COPY(input0, 0);
448 PG_FREE_IF_COPY(input1, 1);
450 result = sfcgal_geometry_minkowski_sum(geom0, geom1);
451 sfcgal_geometry_delete(geom0);
452 sfcgal_geometry_delete(geom1);
455 sfcgal_geometry_delete(result);
457 PG_RETURN_POINTER(output);
464 sfcgal_geometry_t *geom;
465 sfcgal_geometry_t *result;
471 input = PG_GETARG_GSERIALIZED_P(0);
475 PG_FREE_IF_COPY(input, 0);
477 dx = PG_GETARG_FLOAT8(1);
478 dy = PG_GETARG_FLOAT8(2);
479 dz = PG_GETARG_FLOAT8(3);
481 result = sfcgal_geometry_extrude(geom, dx, dy, dz);
482 sfcgal_geometry_delete(geom);
485 sfcgal_geometry_delete(result);
487 PG_RETURN_POINTER(output);
494 text *result = cstring_to_text(ver);
495 PG_RETURN_POINTER(result);
504 PG_FREE_IF_COPY(input, 0);
506 elog(ERROR,
"sfcgal_is_solid: Unable to deserialize input");
512 PG_RETURN_BOOL(result);
522 elog(ERROR,
"sfcgal_make_solid: Unable to deserialize input");
528 PG_FREE_IF_COPY(input, 0);
529 PG_RETURN_POINTER(output);
540 input = PG_GETARG_GSERIALIZED_P(0);
543 elog(ERROR,
"sfcgal_noop: Unable to deserialize input");
548 elog(ERROR,
"sfcgal_noop: Unable to deserialize lwgeom");
551 PG_FREE_IF_COPY(input, 0);
552 PG_RETURN_POINTER(output);
LWGEOM * lwgeom_sfcgal_noop(const LWGEOM *geom_in)
int32_t gserialized_get_srid(const GSERIALIZED *g)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
sfcgal_geometry_t * LWGEOM2SFCGAL(const LWGEOM *geom)
LWGEOM * SFCGAL2LWGEOM(const sfcgal_geometry_t *geom, int force3D, int32_t srid)
const char * lwgeom_sfcgal_version()
void lwgeom_free(LWGEOM *geom)
int lwgeom_needs_bbox(const LWGEOM *geom)
Check whether or not a lwgeom is big enough to warrant a bounding box.
int lwgeom_is_solid(const LWGEOM *geom)
Return LW_TRUE if geometry has SOLID flag.
void * lwalloc(size_t size)
#define LW_TRUE
Return types for functions with status returns.
#define FLAGS_SET_SOLID(flags, value)
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Datum sfcgal_make_solid(PG_FUNCTION_ARGS)
char * text_to_cstring(const text *textptr)
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
Datum sfcgal_force_lhr(PG_FUNCTION_ARGS)
Datum postgis_sfcgal_version(PG_FUNCTION_ARGS)
sfcgal_geometry_t * POSTGIS2SFCGALGeometry(GSERIALIZED *pglwgeom)
PG_FUNCTION_INFO_V1(sfcgal_from_ewkt)
sfcgal_prepared_geometry_t * POSTGIS2SFCGALPreparedGeometry(GSERIALIZED *pglwgeom)
Datum sfcgal_from_ewkt(PG_FUNCTION_ARGS)
Datum sfcgal_orientation(PG_FUNCTION_ARGS)
Datum sfcgal_intersection3D(PG_FUNCTION_ARGS)
Datum sfcgal_approximate_medial_axis(PG_FUNCTION_ARGS)
Datum ST_ConstrainedDelaunayTriangles(PG_FUNCTION_ARGS)
Datum postgis_sfcgal_noop(PG_FUNCTION_ARGS)
Datum sfcgal_is_solid(PG_FUNCTION_ARGS)
Datum sfcgal_area3D(PG_FUNCTION_ARGS)
void sfcgal_postgis_init(void)
Datum sfcgal_is_planar(PG_FUNCTION_ARGS)
Datum sfcgal_difference3D(PG_FUNCTION_ARGS)
Datum sfcgal_extrude(PG_FUNCTION_ARGS)
Datum sfcgal_tesselate(PG_FUNCTION_ARGS)
Datum sfcgal_minkowski_sum(PG_FUNCTION_ARGS)
GSERIALIZED * SFCGALPreparedGeometry2POSTGIS(const sfcgal_prepared_geometry_t *geom, int force3D)
Datum sfcgal_straight_skeleton(PG_FUNCTION_ARGS)
Datum sfcgal_volume(PG_FUNCTION_ARGS)
GSERIALIZED * SFCGALGeometry2POSTGIS(const sfcgal_geometry_t *geom, int force3D, int32_t SRID)
Datum sfcgal_union3D(PG_FUNCTION_ARGS)