From: Darafei Praliaskouski Date: Fri, 30 Nov 2018 17:25:51 +0000 (+0000) Subject: SFCGAL: remove ST_Area SFCGAL implementation X-Git-Tag: 3.0.0alpha1~251 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=30f582482519b8bddefa14cfc10e0ed2345674d6;p=postgis SFCGAL: remove ST_Area SFCGAL implementation References #4258 Closes https://github.com/postgis/postgis/pull/345 git-svn-id: http://svn.osgeo.org/postgis/trunk@17092 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/NEWS b/NEWS index 02e42e8ae..8369c27f5 100644 --- a/NEWS +++ b/NEWS @@ -46,6 +46,7 @@ PostGIS 3.0.0 - #4139, Make mixed-dimension ND index build tree correctly (Darafei Praliaskouski, Arthur Lesuisse, Andrew Gierth, Raúl Marín) - #4262, Document MULTISURFACE compatibility of ST_LineToCurve (Steven Ottens) + - #4258, Remove SFCGAL support for ST_Area (Darafei Praliaskouski) PostGIS 2.5.0 2018/09/23 diff --git a/doc/reference_measure.xml b/doc/reference_measure.xml index 7a1c9be81..1d08ac531 100644 --- a/doc/reference_measure.xml +++ b/doc/reference_measure.xml @@ -675,12 +675,12 @@ SELECT ST_AsEWKT(ST_3DShortestLine(line,pt)) AS shl3d_line_pt, Enhanced: 2.0.0 - support for 2D polyhedral surfaces was introduced. Enhanced: 2.2.0 - measurement on spheroid performed with GeographicLib for improved accuracy and robustness. Requires Proj >= 4.9.0 to take advantage of the new feature. + Changed: 3.0.0 - does not depend on SFCGAL anymore. &sfs_compliant; &sqlmm_compliant; SQL-MM 3: 8.1.2, 9.5.3 &P_support; For polyhedral surfaces, only supports 2D polyhedral surfaces (not 2.5D). For 2.5D, may give a non-zero answer, but only for the faces that sit completely in XY plane. - &sfcgal_enhanced; @@ -689,54 +689,65 @@ SELECT ST_AsEWKT(ST_3DShortestLine(line,pt)) AS shl3d_line_pt, Note this is in square feet because EPSG:2249 is Massachusetts State Plane Feet -SELECT ST_Area(the_geom) As sqft, ST_Area(the_geom)*POWER(0.3048,2) As sqm - FROM (SELECT - ST_GeomFromText('POLYGON((743238 2967416,743238 2967450, - 743265 2967450,743265.625 2967416,743238 2967416))',2249) ) As foo(the_geom); - sqft | sqm ----------+------------- - 928.625 | 86.27208552 +select ST_Area(geom) sqft, + ST_Area(geom) * 0.3048 ^ 2 sqm +from ( + select 'SRID=2249;POLYGON((743238 2967416,743238 2967450, + 743265 2967450,743265.625 2967416,743238 2967416))' :: geometry geom + ) subquery; +┌─────────┬─────────────┐ +│ sqft │ sqm │ +├─────────┼─────────────┤ +│ 928.625 │ 86.27208552 │ +└─────────┴─────────────┘ Return area square feet and transform to Massachusetts state plane meters (EPSG:26986) to get square meters. Note this is in square feet because 2249 is Massachusetts State Plane Feet and transformed area is in square meters since EPSG:26986 is state plane Massachusetts meters - - -SELECT ST_Area(the_geom) As sqft, ST_Area(ST_Transform(the_geom,26986)) As sqm - FROM (SELECT - ST_GeomFromText('POLYGON((743238 2967416,743238 2967450, - 743265 2967450,743265.625 2967416,743238 2967416))',2249) ) As foo(the_geom); - sqft | sqm ----------+------------------ - 928.625 | 86.2724304199219 - +select ST_Area(geom) sqft, + ST_Area(ST_Transform(geom, 26986)) As sqm +from ( + select + 'SRID=2249;POLYGON((743238 2967416,743238 2967450, + 743265 2967450,743265.625 2967416,743238 2967416))' :: geometry geom + ) subquery; +┌─────────┬─────────────────┐ +│ sqft │ sqm │ +├─────────┼─────────────────┤ +│ 928.625 │ 86.272430607008 │ +└─────────┴─────────────────┘ + Return area square feet and square meters using geography data type. Note that we transform to our geometry to geography (before you can do that make sure your geometry is in WGS 84 long lat 4326). Geography always measures in meters. This is just for demonstration to compare. Normally your table will be stored in geography data type already. -SELECT ST_Area(the_geog)/POWER(0.3048,2) As sqft_spheroid, ST_Area(the_geog,false)/POWER(0.3048,2) As sqft_sphere, ST_Area(the_geog) As sqm_spheroid - FROM (SELECT - geography( - ST_Transform( - ST_GeomFromText('POLYGON((743238 2967416,743238 2967450,743265 2967450,743265.625 2967416,743238 2967416))', - 2249 - ) ,4326 - ) - ) - ) As foo(the_geog); - sqft_spheroid | sqft_sphere | sqm_spheroid -------------------+------------------+------------------ - 928.684403538925 | 927.049336105925 | 86.2776042893529 +select ST_Area(geog) / 0.3048 ^ 2 sqft_spheroid, + ST_Area(geog, false) / 0.3048 ^ 2 sqft_sphere, + ST_Area(geog) sqm_spheroid +from ( + select ST_Transform( + 'SRID=2249;POLYGON((743238 2967416,743238 2967450,743265 2967450,743265.625 2967416,743238 2967416))'::geometry, + 4326 + ) :: geography geog + ) as subquery; +┌──────────────────┬──────────────────┬──────────────────┐ +│ sqft_spheroid │ sqft_sphere │ sqm_spheroid │ +├──────────────────┼──────────────────┼──────────────────┤ +│ 928.684405784452 │ 927.049336105925 │ 86.2776044979692 │ +└──────────────────┴──────────────────┴──────────────────┘ + - --if your data is in geography already - SELECT ST_Area(the_geog)/POWER(0.3048,2) As sqft, ST_Area(the_geog) As sqm - FROM somegeogtable; + If your data is in geography already: + +select ST_Area(geog) / 0.3048 ^ 2 sqft, + ST_Area(the_geog) sqm +from somegeogtable; See Also - , , , + , , , , diff --git a/postgis/legacy.sql.in b/postgis/legacy.sql.in index b7498120e..900c18895 100644 --- a/postgis/legacy.sql.in +++ b/postgis/legacy.sql.in @@ -560,7 +560,7 @@ CREATE OR REPLACE FUNCTION AddPoint(geometry, geometry, integer) -- Deprecation in 1.2.3 CREATE OR REPLACE FUNCTION Area(geometry) RETURNS FLOAT8 - AS 'MODULE_PATHNAME','LWGEOM_area_polygon' + AS 'MODULE_PATHNAME','ST_Area' LANGUAGE 'c' IMMUTABLE STRICT; -- this is an alias for 'area(geometry)' @@ -568,7 +568,7 @@ CREATE OR REPLACE FUNCTION Area(geometry) -- Deprecation in 1.2.3 CREATE OR REPLACE FUNCTION Area2D(geometry) RETURNS FLOAT8 - AS 'MODULE_PATHNAME', 'LWGEOM_area_polygon' + AS 'MODULE_PATHNAME', 'ST_Area' LANGUAGE 'c' IMMUTABLE STRICT; -- Deprecation in 1.2.3 diff --git a/postgis/lwgeom_backend_api.c b/postgis/lwgeom_backend_api.c index a9c1fe39f..82e69bd51 100644 --- a/postgis/lwgeom_backend_api.c +++ b/postgis/lwgeom_backend_api.c @@ -57,7 +57,6 @@ struct lwgeom_backend_definition Datum (*intersection_fn) (PG_FUNCTION_ARGS); Datum (*difference_fn) (PG_FUNCTION_ARGS); Datum (*union_fn) (PG_FUNCTION_ARGS); - Datum (*area_fn) (PG_FUNCTION_ARGS); Datum (*distance_fn) (PG_FUNCTION_ARGS); Datum (*distance3d_fn) (PG_FUNCTION_ARGS); }; @@ -75,7 +74,6 @@ struct lwgeom_backend_definition lwgeom_backends[LWGEOM_NUM_BACKENDS] = { .intersection_fn = geos_intersection, .difference_fn = geos_difference, .union_fn = geos_geomunion, - .area_fn = LWGEOM_area_polygon, .distance_fn = LWGEOM_mindistance2d, .distance3d_fn = LWGEOM_mindistance3d }, @@ -86,7 +84,6 @@ struct lwgeom_backend_definition lwgeom_backends[LWGEOM_NUM_BACKENDS] = { .intersection_fn = sfcgal_intersection, .difference_fn = sfcgal_difference, .union_fn = sfcgal_union, - .area_fn = sfcgal_area, .distance_fn = sfcgal_distance, .distance3d_fn = sfcgal_distance3D } @@ -189,12 +186,6 @@ Datum geomunion(PG_FUNCTION_ARGS) return (*lwgeom_backend->union_fn)( fcinfo ); } -PG_FUNCTION_INFO_V1(area); -Datum area(PG_FUNCTION_ARGS) -{ - return (*lwgeom_backend->area_fn)( fcinfo ); -} - PG_FUNCTION_INFO_V1(distance); Datum distance(PG_FUNCTION_ARGS) { diff --git a/postgis/lwgeom_functions_basic.c b/postgis/lwgeom_functions_basic.c index 98ce3ed4b..4d2be7ceb 100644 --- a/postgis/lwgeom_functions_basic.c +++ b/postgis/lwgeom_functions_basic.c @@ -44,7 +44,7 @@ Datum LWGEOM_mem_size(PG_FUNCTION_ARGS); Datum LWGEOM_summary(PG_FUNCTION_ARGS); Datum LWGEOM_npoints(PG_FUNCTION_ARGS); Datum LWGEOM_nrings(PG_FUNCTION_ARGS); -Datum LWGEOM_area_polygon(PG_FUNCTION_ARGS); +Datum ST_Area(PG_FUNCTION_ARGS); Datum postgis_uses_stats(PG_FUNCTION_ARGS); Datum postgis_autocache_bbox(PG_FUNCTION_ARGS); Datum postgis_scripts_released(PG_FUNCTION_ARGS); @@ -269,15 +269,13 @@ Datum LWGEOM_nrings(PG_FUNCTION_ARGS) * area (line) = 0 * area(polygon) = find its 2d area */ -PG_FUNCTION_INFO_V1(LWGEOM_area_polygon); -Datum LWGEOM_area_polygon(PG_FUNCTION_ARGS) +PG_FUNCTION_INFO_V1(ST_Area); +Datum ST_Area(PG_FUNCTION_ARGS) { GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0); LWGEOM *lwgeom = lwgeom_from_gserialized(geom); double area = 0.0; - POSTGIS_DEBUG(2, "in LWGEOM_area_polygon"); - area = lwgeom_area(lwgeom); lwgeom_free(lwgeom); diff --git a/postgis/lwgeom_sfcgal.c b/postgis/lwgeom_sfcgal.c index 5660486d7..2b28e3fa0 100644 --- a/postgis/lwgeom_sfcgal.c +++ b/postgis/lwgeom_sfcgal.c @@ -38,7 +38,6 @@ Datum postgis_sfcgal_version(PG_FUNCTION_ARGS); Datum sfcgal_from_ewkt(PG_FUNCTION_ARGS); Datum sfcgal_distance(PG_FUNCTION_ARGS); Datum sfcgal_distance3D(PG_FUNCTION_ARGS); -Datum sfcgal_area(PG_FUNCTION_ARGS); Datum sfcgal_area3D(PG_FUNCTION_ARGS); Datum sfcgal_intersects(PG_FUNCTION_ARGS); Datum sfcgal_intersects3D(PG_FUNCTION_ARGS); @@ -156,27 +155,6 @@ Datum sfcgal_from_ewkt(PG_FUNCTION_ARGS) } -PG_FUNCTION_INFO_V1(sfcgal_area); -Datum sfcgal_area(PG_FUNCTION_ARGS) - { - GSERIALIZED *input; - sfcgal_geometry_t *geom; - double result; - - sfcgal_postgis_init(); - - input = PG_GETARG_GSERIALIZED_P(0); - geom = POSTGIS2SFCGALGeometry(input); - - result = sfcgal_geometry_area(geom); - sfcgal_geometry_delete(geom); - - PG_FREE_IF_COPY(input, 0); - - PG_RETURN_FLOAT8(result); -} - - PG_FUNCTION_INFO_V1(sfcgal_area3D); Datum sfcgal_area3D(PG_FUNCTION_ARGS) { diff --git a/postgis/lwgeom_sfcgal.h b/postgis/lwgeom_sfcgal.h index c350ba65f..16e6988bd 100644 --- a/postgis/lwgeom_sfcgal.h +++ b/postgis/lwgeom_sfcgal.h @@ -46,7 +46,6 @@ Datum sfcgal_union3D(PG_FUNCTION_ARGS); Datum sfcgal_union(PG_FUNCTION_ARGS); Datum sfcgal_volume(PG_FUNCTION_ARGS); Datum sfcgal_triangulate(PG_FUNCTION_ARGS); -Datum sfcgal_area(PG_FUNCTION_ARGS); Datum sfcgal_distance(PG_FUNCTION_ARGS); Datum sfcgal_distance3D(PG_FUNCTION_ARGS); Datum sfcgal_make_solid(PG_FUNCTION_ARGS); diff --git a/postgis/postgis.sql.in b/postgis/postgis.sql.in index 3a88787c9..2669ca03a 100644 --- a/postgis/postgis.sql.in +++ b/postgis/postgis.sql.in @@ -1278,16 +1278,16 @@ CREATE OR REPLACE FUNCTION ST_Perimeter(geometry) -- Availability: 1.2.2 -- Deprecation in 1.3.4 -CREATE OR REPLACE FUNCTION ST_area2d(geometry) +CREATE OR REPLACE FUNCTION ST_Area2D(geometry) RETURNS FLOAT8 - AS 'MODULE_PATHNAME', 'LWGEOM_area_polygon' + AS 'MODULE_PATHNAME', 'ST_Area' LANGUAGE 'c' IMMUTABLE STRICT _PARALLEL COST 10; -- PostGIS equivalent function: area(geometry) CREATE OR REPLACE FUNCTION ST_Area(geometry) RETURNS FLOAT8 - AS 'MODULE_PATHNAME','area' + AS 'MODULE_PATHNAME','ST_Area' LANGUAGE 'c' IMMUTABLE STRICT _PARALLEL COST 10; diff --git a/postgis/postgis_legacy.c b/postgis/postgis_legacy.c index dbfbee2e2..369f391ab 100644 --- a/postgis/postgis_legacy.c +++ b/postgis/postgis_legacy.c @@ -51,3 +51,5 @@ POSTGIS_DEPRECATE("2.5.0", pgis_abs_in); POSTGIS_DEPRECATE("2.5.0", pgis_abs_out); +POSTGIS_DEPRECATE("3.0.0", area); +POSTGIS_DEPRECATE("3.0.0", LWGEOM_area_polygon);