From aeb23624e1262b197d01fff94cc537fe7c0bd967 Mon Sep 17 00:00:00 2001 From: Darafei Praliaskouski Date: Sun, 18 Aug 2019 12:18:59 +0000 Subject: [PATCH] postgis_sfcgal_noop(). Patch by Lucas C. Villa Real , tweaks by Darafei Praliaskouski Closes #3979 git-svn-id: http://svn.osgeo.org/postgis/trunk@17727 b70326c6-7e19-0410-871a-916f4a2858ee --- NEWS | 1 + postgis/lwgeom_sfcgal.c | 24 ++++++++++++++++++++++++ postgis/sfcgal.sql.in | 7 +++++++ regress/sfcgal/regress_sfcgal.sql | 1 + regress/sfcgal/regress_sfcgal_expected | 1 + 5 files changed, 34 insertions(+) diff --git a/NEWS b/NEWS index 2a191d3f8..b294be076 100644 --- a/NEWS +++ b/NEWS @@ -203,6 +203,7 @@ Additional features enabled if you are running Proj6+ and PostgreSQL 12 - #4277, ST_GeomFromGeoJSON now marks SRID=4326 by default as per RFC7946, ST_AsGeoJSON sets SRID in JSON output if it differs from 4326. (Darafei Praliaskouski) + - #3979, postgis_sfcgal_noop() round trip function (Lucas C. Villa Real) * Fixes * - #4342, Move deprecated functions into legacy.sql file diff --git a/postgis/lwgeom_sfcgal.c b/postgis/lwgeom_sfcgal.c index f15ac6db6..ed0b07fb8 100644 --- a/postgis/lwgeom_sfcgal.c +++ b/postgis/lwgeom_sfcgal.c @@ -50,6 +50,7 @@ Datum sfcgal_tesselate(PG_FUNCTION_ARGS); Datum sfcgal_minkowski_sum(PG_FUNCTION_ARGS); Datum sfcgal_make_solid(PG_FUNCTION_ARGS); Datum sfcgal_is_solid(PG_FUNCTION_ARGS); +Datum postgis_sfcgal_noop(PG_FUNCTION_ARGS); GSERIALIZED *geometry_serialize(LWGEOM *lwgeom); char *text_to_cstring(const text *textptr); @@ -526,3 +527,26 @@ Datum sfcgal_make_solid(PG_FUNCTION_ARGS) PG_FREE_IF_COPY(input, 0); PG_RETURN_POINTER(output); } + +PG_FUNCTION_INFO_V1(postgis_sfcgal_noop); +Datum postgis_sfcgal_noop(PG_FUNCTION_ARGS) +{ + GSERIALIZED *input, *output; + LWGEOM *geom, *result; + + sfcgal_postgis_init(); + + input = PG_GETARG_GSERIALIZED_P(0); + geom = lwgeom_from_gserialized(input); + if (!geom) + elog(ERROR, "sfcgal_noop: Unable to deserialize input"); + + result = lwgeom_sfcgal_noop(geom); + lwgeom_free(geom); + if (!result) + elog(ERROR, "sfcgal_noop: Unable to deserialize lwgeom"); + + output = geometry_serialize(result); + PG_FREE_IF_COPY(input, 0); + PG_RETURN_POINTER(output); +} diff --git a/postgis/sfcgal.sql.in b/postgis/sfcgal.sql.in index bb3f83aeb..798fe2493 100644 --- a/postgis/sfcgal.sql.in +++ b/postgis/sfcgal.sql.in @@ -27,6 +27,13 @@ CREATE OR REPLACE FUNCTION postgis_sfcgal_version() RETURNS text AS 'MODULE_PATHNAME' LANGUAGE 'c' IMMUTABLE; +-- Availability: 3.0.0 +CREATE OR REPLACE FUNCTION postgis_sfcgal_noop(geometry) + RETURNS geometry + AS 'MODULE_PATHNAME', 'postgis_sfcgal_noop' + LANGUAGE 'c' IMMUTABLE STRICT _PARALLEL + COST 1; + -- Availability: 2.1.0 CREATE OR REPLACE FUNCTION ST_3DIntersection(geom1 geometry, geom2 geometry) RETURNS geometry diff --git a/regress/sfcgal/regress_sfcgal.sql b/regress/sfcgal/regress_sfcgal.sql index 896bb3af0..6853ec4d3 100644 --- a/regress/sfcgal/regress_sfcgal.sql +++ b/regress/sfcgal/regress_sfcgal.sql @@ -30,3 +30,4 @@ SELECT 'ST_Orientation_2', ST_Orientation(ST_ForceRHR('POLYGON((0 0,0 1,1 1,1 0, SELECT 'ST_MinkowskiSum', ST_AsText(ST_MinkowskiSum('LINESTRING(0 0,4 0)','POLYGON((0 0,1 0,1 1,0 1,0 0))')); SELECT 'ST_StraightSkeleton', ST_AsText(ST_StraightSkeleton('POLYGON((1 1,2 1,2 2,1 2,1 1))')); SELECT 'ST_ConstrainedDelaunayTriangles', ST_AsText(ST_ConstrainedDelaunayTriangles('GEOMETRYCOLLECTION(POINT(0 0), POLYGON((2 2, 2 -2, 4 0, 2 2)))')); +SELECT 'postgis_sfcgal_noop', ST_NPoints(postgis_sfcgal_noop(ST_Buffer('POINT(0 0)', 5))); diff --git a/regress/sfcgal/regress_sfcgal_expected b/regress/sfcgal/regress_sfcgal_expected index 785d51fde..a67ed5660 100644 --- a/regress/sfcgal/regress_sfcgal_expected +++ b/regress/sfcgal/regress_sfcgal_expected @@ -10,3 +10,4 @@ ST_Orientation_2|1 ST_MinkowskiSum|MULTIPOLYGON(((0 0,1 0,5 0,5 1,4 1,0 1,0 0))) ST_StraightSkeleton|MULTILINESTRING((1 1,1.5 1.5),(2 1,1.5 1.5),(2 2,1.5 1.5),(1 2,1.5 1.5)) ST_ConstrainedDelaunayTriangles|TIN(((4 0,2 2,2 -2,4 0)),((2 2,0 0,2 -2,2 2))) +postgis_sfcgal_noop|33 -- 2.49.0