Commit ce70e490 authored by Paul Ramsey's avatar Paul Ramsey

Move deprecated functions into legacy.sql.

Reduce the number of multi-signature functions.
Use native C calls more often in place of SQL wrappers.
Remove "versioned" form of ST_AsGeoJSON and ST_AsKML.
Harmonize documentation and tests.


git-svn-id: http://svn.osgeo.org/postgis/trunk@17300 b70326c6-7e19-0410-871a-916f4a2858ee
parent dcc1fb66
Pipeline #50832676 failed with stage
in 4 minutes and 56 seconds
......@@ -20,6 +20,7 @@ PostGIS 3.0.0
- #4267, Enable Proj 6 deprecated APIs (Darafei Praliaskouski, Raúl Marín)
- #4268, Bump minimum SFCGAL version to 1.3.1 (Darafei Praliaskouski)
- #4331, ST_3DMakeBox now returns error instead of a miniscule box (Regina Obe)
- #4342, Removed "versioned" variants of ST_AsGeoJSON and ST_AsKML (Paul Ramsey)
* New Features *
- #2902, postgis_geos_noop (Sandro Santilli)
......@@ -31,6 +32,7 @@ PostGIS 3.0.0
- #4311, Introduce `--with-wagyu` as an option for MVT polygons (Raúl Marín)
* Enhancements and fixes *
- #4342, Move deprecated functions into legacy.sql file
- #4341, Using "support function" API in PgSQL 12+ to replace SQL inlining
as the mechanism for providing index support under ST_Intersects, et al
- #4322, Support for Proj 6+ API, bringing more accurate datum transforms
......
......@@ -1514,11 +1514,12 @@ NOTICE: Self-intersection at or near point 0 0
<funcprototype>
<funcdef>text <function>ST_IsValidReason</function></funcdef>
<paramdef><type>geometry </type> <parameter>geomA</parameter></paramdef>
<paramdef><type>integer </type> <parameter>flags</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>text <function>ST_IsValidReason</function></funcdef>
<paramdef><type>geometry </type> <parameter>geomA</parameter></paramdef>
<paramdef><type>integer </type> <parameter>flags</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
......@@ -1597,11 +1598,7 @@ SELECT ST_IsValidReason('LINESTRING(220227 150406,2220227 150407,222020 150410)'
<funcprototype>
<funcdef>valid_detail <function>ST_IsValidDetail</function></funcdef>
<paramdef><type>geometry </type> <parameter>geom</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>valid_detail <function>ST_IsValidDetail</function></funcdef>
<paramdef><type>geometry </type> <parameter>geom</parameter></paramdef>
<paramdef><type>integer </type> <parameter>flags</parameter></paramdef>
<paramdef choice="opt"><type>integer </type> <parameter>flags</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
......
......@@ -2399,6 +2399,7 @@ SELECT ST_Disjoint('POINT(0 0)'::geometry, 'LINESTRING ( 0 0, 0 2 )'::geometry);
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>float <function>ST_Distance</function></funcdef>
......@@ -2408,28 +2409,20 @@ SELECT ST_Disjoint('POINT(0 0)'::geometry, 'LINESTRING ( 0 0, 0 2 )'::geometry);
<paramdef><type>geometry </type>
<parameter>g2</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>float <function>ST_Distance</function></funcdef>
<paramdef><type>geography </type>
<parameter>gg1</parameter></paramdef>
<paramdef><type>geography </type>
<parameter>gg2</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>float <function>ST_Distance</function></funcdef>
<paramdef><type>geography </type>
<parameter>gg1</parameter></paramdef>
<parameter>geog1</parameter></paramdef>
<paramdef><type>geography </type>
<parameter>gg2</parameter></paramdef>
<parameter>geog2</parameter></paramdef>
<paramdef><type>boolean </type>
<parameter>use_spheroid</parameter></paramdef>
<paramdef choice="opt">><type>boolean </type>
<parameter>use_spheroid=true</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
......@@ -3755,80 +3748,6 @@ CAST('SPHEROID["GRS_1980",6378137,298.257222101]' As spheroid) As sph_m) as foo
</refsection>
</refentry>
<refentry id="ST_Length2D_Spheroid">
<refnamediv>
<refname>ST_Length2D_Spheroid</refname>
<refpurpose>Calculates the 2D length/perimeter of a geometry on an ellipsoid. This
is useful if the coordinates of the geometry are in
longitude/latitude and a length is desired without reprojection. </refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>float <function>ST_Length2D_Spheroid</function></funcdef>
<paramdef><type>geometry </type> <parameter>a_geometry</parameter></paramdef>
<paramdef><type>spheroid </type> <parameter>a_spheroid</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsection>
<title>Description</title>
<para>Calculates the 2D length/perimeter of a geometry on an ellipsoid. This
is useful if the coordinates of the geometry are in
longitude/latitude and a length is desired without reprojection.
The ellipsoid is a separate database type and can be constructed
as follows:</para>
<literallayout>SPHEROID[&lt;NAME&gt;,&lt;SEMI-MAJOR AXIS&gt;,&lt;INVERSE FLATTENING&gt;]</literallayout>
<literallayout>SPHEROID["GRS_1980",6378137,298.257222101]</literallayout>
<note><para>This is much like <xref linkend="ST_Length_Spheroid" /> except it will ignore the Z ordinate in calculations.</para></note>
</refsection>
<refsection>
<title>Examples</title>
<programlisting>SELECT ST_Length2D_Spheroid( geometry_column,
'SPHEROID["GRS_1980",6378137,298.257222101]' )
FROM geometry_table;
SELECT ST_Length2D_Spheroid( the_geom, sph_m ) As tot_len,
ST_Length2D_Spheroid(ST_GeometryN(the_geom,1), sph_m) As len_line1,
ST_Length2D_Spheroid(ST_GeometryN(the_geom,2), sph_m) As len_line2
FROM (SELECT ST_GeomFromText('MULTILINESTRING((-118.584 38.374,-118.583 38.5),
(-71.05957 42.3589 , -71.061 43))') As the_geom,
CAST('SPHEROID["GRS_1980",6378137,298.257222101]' As spheroid) As sph_m) as foo;
tot_len | len_line1 | len_line2
------------------+------------------+------------------
85204.5207562955 | 13986.8725229309 | 71217.6482333646
--3D Observe same answer
SELECT ST_Length2D_Spheroid( the_geom, sph_m ) As tot_len,
ST_Length2D_Spheroid(ST_GeometryN(the_geom,1), sph_m) As len_line1,
ST_Length2D_Spheroid(ST_GeometryN(the_geom,2), sph_m) As len_line2
FROM (SELECT ST_GeomFromEWKT('MULTILINESTRING((-118.584 38.374 20,-118.583 38.5 30),
(-71.05957 42.3589 75, -71.061 43 90))') As the_geom,
CAST('SPHEROID["GRS_1980",6378137,298.257222101]' As spheroid) As sph_m) as foo;
tot_len | len_line1 | len_line2
------------------+------------------+------------------
85204.5207562955 | 13986.8725229309 | 71217.6482333646
</programlisting>
</refsection>
<!-- Optionally add a "See Also" section -->
<refsection>
<title>See Also</title>
<para><xref linkend="ST_GeometryN" />, <xref linkend="ST_Length_Spheroid" /></para>
</refsection>
</refentry>
<refentry id="ST_LongestLine">
<refnamediv>
......
......@@ -339,20 +339,6 @@ CIRCULARSTRING(220268 150415 1,220227 150505 2,220227 150406 3)
<paramdef choice="opt"><type>integer </type> <parameter>maxdecimaldigits=15</parameter></paramdef>
<paramdef choice="opt"><type>integer </type> <parameter>options=0</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>text <function>ST_AsGeoJSON</function></funcdef>
<paramdef><type>integer </type> <parameter>gj_version</parameter></paramdef>
<paramdef><type>geometry </type> <parameter>geom</parameter></paramdef>
<paramdef choice="opt"><type>integer </type> <parameter>maxdecimaldigits=15</parameter></paramdef>
<paramdef choice="opt"><type>integer </type> <parameter>options=0</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>text <function>ST_AsGeoJSON</function></funcdef>
<paramdef><type>integer </type> <parameter>gj_version</parameter></paramdef>
<paramdef><type>geography </type> <parameter>geog</parameter></paramdef>
<paramdef choice="opt"><type>integer </type> <parameter>maxdecimaldigits=15</parameter></paramdef>
<paramdef choice="opt"><type>integer </type> <parameter>options=0</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
......@@ -487,6 +473,8 @@ st_asgeojson
<paramdef><type>geography </type> <parameter>geog</parameter></paramdef>
<paramdef choice="opt"><type>integer </type> <parameter>maxdecimaldigits=15</parameter></paramdef>
<paramdef choice="opt"><type>integer </type> <parameter>options=0</parameter></paramdef>
<paramdef choice="opt"><type>text </type> <parameter>nprefix=null</parameter></paramdef>
<paramdef choice="opt"><type>text </type> <parameter>id=null</parameter></paramdef>
</funcprototype>
......@@ -730,31 +718,21 @@ SELECT ST_AsGML(3, ST_GeomFromEWKT('POLYHEDRALSURFACE( ((0 0 0, 0 0 1, 0 1 1, 0
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>text <function>ST_AsKML</function></funcdef>
<paramdef><type>geometry </type> <parameter>geom</parameter></paramdef>
<paramdef choice="opt"><type>integer </type> <parameter>maxdecimaldigits=15</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>text <function>ST_AsKML</function></funcdef>
<paramdef><type>geography </type> <parameter>geog</parameter></paramdef>
<paramdef choice="opt"><type>integer </type> <parameter>maxdecimaldigits=15</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>text <function>ST_AsKML</function></funcdef>
<paramdef><type>integer </type> <parameter>version</parameter></paramdef>
<paramdef><type>geometry </type> <parameter>geom</parameter></paramdef>
<paramdef choice="opt"><type>integer </type> <parameter>maxdecimaldigits=15</parameter></paramdef>
<paramdef choice="opt"><type>text </type> <parameter>nprefix=NULL</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>text <function>ST_AsKML</function></funcdef>
<paramdef><type>integer </type> <parameter>version</parameter></paramdef>
<paramdef><type>geography </type> <parameter>geog</parameter></paramdef>
<paramdef choice="opt"><type>integer </type> <parameter>maxdecimaldigits=15</parameter></paramdef>
<paramdef choice="opt"><type>text </type> <parameter>nprefix=NULL</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
......
......@@ -14,44 +14,33 @@ from the input geometry.
<refsynopsisdiv>
<funcsynopsis>
<funcprototype>
<funcdef>geometry <function>ST_Buffer</function></funcdef>
<paramdef><type>geometry </type> <parameter>g1</parameter></paramdef>
<paramdef><type>float </type> <parameter>radius_of_buffer</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>geometry <function>ST_Buffer</function></funcdef>
<paramdef><type>geometry </type> <parameter>g1</parameter></paramdef>
<paramdef><type>float </type> <parameter>radius_of_buffer</parameter></paramdef>
<paramdef><type>integer </type> <parameter>num_seg_quarter_circle</parameter></paramdef>
<paramdef choice="opt"><type>text </type> <parameter>buffer_style_parameters=''</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>geometry <function>ST_Buffer</function></funcdef>
<paramdef><type>geometry </type> <parameter>g1</parameter></paramdef>
<paramdef><type>float </type> <parameter>radius_of_buffer</parameter></paramdef>
<paramdef><type>text </type> <parameter>buffer_style_parameters</parameter></paramdef>
<paramdef><type>integer </type> <parameter>num_seg_quarter_circle</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>geography <function>ST_Buffer</function></funcdef>
<paramdef><type>geography </type> <parameter>g1</parameter></paramdef>
<paramdef><type>float </type> <parameter>radius_of_buffer_in_meters</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>geography <function>ST_Buffer</function></funcdef>
<paramdef><type>geography </type> <parameter>g1</parameter></paramdef>
<paramdef><type>float </type> <parameter>radius_of_buffer</parameter></paramdef>
<paramdef><type>integer </type> <parameter>num_seg_quarter_circle</parameter></paramdef>
<paramdef choice="opt"><type>text </type> <parameter>buffer_style_parameters</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>geography <function>ST_Buffer</function></funcdef>
<paramdef><type>geography </type> <parameter>g1</parameter></paramdef>
<paramdef><type>float </type> <parameter>radius_of_buffer</parameter></paramdef>
<paramdef><type>text </type> <parameter>buffer_style_parameters</parameter></paramdef>
<paramdef><type>integer </type> <parameter>num_seg_quarter_circle</parameter></paramdef>
</funcprototype>
</funcsynopsis>
......
......@@ -397,10 +397,8 @@ CREATE OPERATOR CLASS btree_geography_ops
-- SVG OUTPUT
--
-- ST_AsSVG(geography, rel, precision)
-- rel int4 DEFAULT 0, maxdecimaldigits int4 DEFAULT 15
-- Changed 2.0.0 to use default args and named args
CREATE OR REPLACE FUNCTION ST_AsSVG(geog geography,rel int4 DEFAULT 0,maxdecimaldigits int4 DEFAULT 15)
CREATE OR REPLACE FUNCTION ST_AsSVG(geog geography, rel int4 DEFAULT 0, maxdecimaldigits int4 DEFAULT 15)
RETURNS text
AS 'MODULE_PATHNAME','geography_as_svg'
LANGUAGE 'c' IMMUTABLE STRICT _PARALLEL;
......@@ -415,11 +413,20 @@ CREATE OR REPLACE FUNCTION ST_AsSVG(text)
-- GML OUTPUT
--
-- _ST_AsGML(version, geography, precision, option, prefix, id)
CREATE OR REPLACE FUNCTION _ST_AsGML(int4, geography, int4, int4, text, text)
-- ST_AsGML(version, geography, precision, option, prefix, id)
-- Changed: 3.0.0 to bind directly to C
-- Changed: 2.0.0 to use default args and allow named args
-- Changed: 2.1.0 enhance to allow id value
-- Availability: 1.5.0
CREATE OR REPLACE FUNCTION ST_AsGML(version int4, geog geography, maxdecimaldigits int4 DEFAULT 15, options int4 DEFAULT 0, nprefix text DEFAULT 'gml', id text DEFAULT '')
RETURNS text
AS 'MODULE_PATHNAME','geography_as_gml'
LANGUAGE 'c' IMMUTABLE _PARALLEL;
LANGUAGE 'c' IMMUTABLE STRICT _PARALLEL;
CREATE OR REPLACE FUNCTION ST_AsGML(geog geography, maxdecimaldigits int4 DEFAULT 15, options int4 DEFAULT 0, nprefix text DEFAULT 'gml', id text DEFAULT '')
RETURNS text
AS 'MODULE_PATHNAME','geography_as_gml'
LANGUAGE 'c' IMMUTABLE STRICT _PARALLEL;
-- Availability: 1.5.0 - this is just a hack to prevent unknown from causing ambiguous name because of geography
-- Change 2.0.0 to use base function
......@@ -428,60 +435,29 @@ CREATE OR REPLACE FUNCTION ST_AsGML(text)
$$ SELECT @extschema@._ST_AsGML(2,$1::@extschema@.geometry,15,0, NULL, NULL); $$
LANGUAGE 'sql' IMMUTABLE STRICT _PARALLEL;
-- ST_AsGML (geography, precision, option) / version=2
-- Availability: 1.5.0
-- Changed: 2.0.0 to use default args
CREATE OR REPLACE FUNCTION ST_AsGML(geog geography, maxdecimaldigits int4 DEFAULT 15, options int4 DEFAULT 0)
RETURNS text
AS 'SELECT @extschema@._ST_AsGML(2, $1, $2, $3, null, null)'
LANGUAGE 'sql' IMMUTABLE STRICT _PARALLEL;
-- ST_AsGML(version, geography, precision, option, prefix)
-- Changed: 2.0.0 to use default args and allow named args
-- Changed: 2.1.0 enhance to allow id value
-- Availability: 1.5.0
CREATE OR REPLACE FUNCTION ST_AsGML(version int4, geog geography, maxdecimaldigits int4 DEFAULT 15, options int4 DEFAULT 0, nprefix text DEFAULT NULL, id text DEFAULT NULL)
RETURNS text
AS $$ SELECT @extschema@._ST_AsGML($1, $2, $3, $4, $5, $6);$$
LANGUAGE 'sql' IMMUTABLE _PARALLEL;
--
-- KML OUTPUT
--
-- _ST_AsKML(version, geography, precision)
CREATE OR REPLACE FUNCTION _ST_AsKML(int4, geography, int4, text)
RETURNS text
AS 'MODULE_PATHNAME','geography_as_kml'
LANGUAGE 'c' IMMUTABLE _PARALLEL;
-- AsKML(geography,precision) / version=2
-- AsKML(geography,precision)
-- Changed: 2.0.0 to use default args and named args
CREATE OR REPLACE FUNCTION ST_AsKML(geog geography, maxdecimaldigits int4 DEFAULT 15)
CREATE OR REPLACE FUNCTION ST_AsKML(geog geography, maxdecimaldigits int4 DEFAULT 15, nprefix text DEFAULT '')
RETURNS text
AS 'SELECT @extschema@._ST_AsKML(2, $1, $2, null)'
LANGUAGE 'sql' IMMUTABLE STRICT _PARALLEL;
AS 'MODULE_PATHNAME','geography_as_kml'
LANGUAGE 'c' IMMUTABLE STRICT _PARALLEL;
-- Availability: 1.5.0 - this is just a hack to prevent unknown from causing ambiguous name because of geography
-- Deprecated 2.0.0
CREATE OR REPLACE FUNCTION ST_AsKML(text)
RETURNS text AS
$$ SELECT @extschema@._ST_AsKML(2, $1::@extschema@.geometry, 15, null); $$
$$ SELECT @extschema@.ST_AsKML($1::@extschema@.geometry, 15); $$
LANGUAGE 'sql' IMMUTABLE STRICT _PARALLEL;
-- ST_AsKML(version, geography, precision, prefix)
-- Availability: 2.0.0 nprefix added
-- Changed: 2.0.0 to use default args and named args
CREATE OR REPLACE FUNCTION ST_AsKML(version int4, geog geography, maxdecimaldigits int4 DEFAULT 15, nprefix text DEFAULT null)
RETURNS text
AS 'SELECT @extschema@._ST_AsKML($1, $2, $3, $4)'
LANGUAGE 'sql' IMMUTABLE _PARALLEL;
--
-- GeoJson Output
--
CREATE OR REPLACE FUNCTION _ST_AsGeoJson(int4, geography, int4, int4)
CREATE OR REPLACE FUNCTION ST_AsGeoJson(geog geography, maxdecimaldigits int4 DEFAULT 15, options int4 DEFAULT 0)
RETURNS text
AS 'MODULE_PATHNAME','geography_as_geojson'
LANGUAGE 'c' IMMUTABLE STRICT _PARALLEL;
......@@ -490,49 +466,22 @@ CREATE OR REPLACE FUNCTION _ST_AsGeoJson(int4, geography, int4, int4)
-- Deprecated in 2.0.0
CREATE OR REPLACE FUNCTION ST_AsGeoJson(text)
RETURNS text AS
$$ SELECT @extschema@._ST_AsGeoJson(1, $1::@extschema@.geometry,15,0); $$
LANGUAGE 'sql' IMMUTABLE STRICT _PARALLEL;
-- ST_AsGeoJson(geography, precision, options) / version=1
-- Changed: 2.0.0 to use default args and named args
CREATE OR REPLACE FUNCTION ST_AsGeoJson(geog geography, maxdecimaldigits int4 DEFAULT 15, options int4 DEFAULT 0)
RETURNS text
AS $$ SELECT @extschema@._ST_AsGeoJson(1, $1, $2, $3); $$
$$ SELECT @extschema@.ST_AsGeoJson($1::@extschema@.geometry,15,0); $$
LANGUAGE 'sql' IMMUTABLE STRICT _PARALLEL;
-- ST_AsGeoJson(version, geography, precision,options)
-- Changed: 2.0.0 to use default args and named args
CREATE OR REPLACE FUNCTION ST_AsGeoJson(gj_version int4, geog geography, maxdecimaldigits int4 DEFAULT 15, options int4 DEFAULT 0)
RETURNS text
AS $$ SELECT @extschema@._ST_AsGeoJson($1, $2, $3, $4); $$
LANGUAGE 'sql' IMMUTABLE STRICT _PARALLEL;
-- ---------- ---------- ---------- ---------- ---------- ---------- ----------
-- Measurement Functions
-- Availability: 1.5.0
-- ---------- ---------- ---------- ---------- ---------- ---------- ----------
-- Stop calculation and return immediately once distance is less than tolerance
-- Availability: 1.5.0
CREATE OR REPLACE FUNCTION _ST_Distance(geography, geography, float8, boolean)
CREATE OR REPLACE FUNCTION ST_Distance(geog1 geography, geog2 geography, use_spheroid boolean DEFAULT true)
RETURNS float8
AS 'MODULE_PATHNAME','geography_distance'
LANGUAGE 'c' IMMUTABLE STRICT _PARALLEL
COST 100;
-- Availability: 1.5.0
CREATE OR REPLACE FUNCTION ST_Distance(geography, geography, boolean)
RETURNS float8
AS 'SELECT @extschema@._ST_Distance($1, $2, 0.0, $3)'
LANGUAGE 'sql' IMMUTABLE STRICT _PARALLEL;
-- Currently defaulting to spheroid calculations
-- Availability: 1.5.0
CREATE OR REPLACE FUNCTION ST_Distance(geography, geography)
RETURNS float8
AS 'SELECT @extschema@._ST_Distance($1, $2, 0.0, true)'
LANGUAGE 'sql' IMMUTABLE STRICT _PARALLEL;
-- Availability: 1.5.0 - this is just a hack to prevent unknown from causing ambiguous name because of geography
CREATE OR REPLACE FUNCTION ST_Distance(text, text)
RETURNS float8 AS
......@@ -672,8 +621,8 @@ CREATE OR REPLACE FUNCTION _ST_BestSRID(geography, geography)
-- Availability: 1.5.0
CREATE OR REPLACE FUNCTION _ST_BestSRID(geography)
RETURNS integer
AS 'SELECT @extschema@._ST_BestSRID($1,$1)'
LANGUAGE 'sql' IMMUTABLE STRICT _PARALLEL;
AS 'MODULE_PATHNAME','geography_bestsrid'
LANGUAGE 'c' IMMUTABLE STRICT _PARALLEL;
-- Availability: 1.5.0
CREATE OR REPLACE FUNCTION ST_Buffer(geography, float8)
......@@ -730,10 +679,10 @@ CREATE OR REPLACE FUNCTION ST_AsBinary(geography)
LANGUAGE 'c' IMMUTABLE STRICT _PARALLEL;
-- Availability: 2.0.0
CREATE OR REPLACE FUNCTION ST_AsBinary(geography,text)
RETURNS bytea AS
$$ SELECT @extschema@.ST_AsBinary($1::@extschema@.geometry, $2); $$
LANGUAGE 'sql' IMMUTABLE STRICT _PARALLEL;
CREATE OR REPLACE FUNCTION ST_AsBinary(geography, text)
RETURNS bytea
AS 'MODULE_PATHNAME','LWGEOM_asBinary'
LANGUAGE 'c' IMMUTABLE _PARALLEL;
-- Availability: 2.0.0
CREATE OR REPLACE FUNCTION ST_AsEWKT(geography)
......
......@@ -222,76 +222,73 @@ Datum geography_as_gml(PG_FUNCTION_ARGS)
const char *prefix = default_prefix;
char *prefix_buf = "";
text *prefix_text, *id_text = NULL;
const char *id=NULL;
const char *id = NULL;
char *id_buf;
/* Get the version */
version = PG_GETARG_INT32(0);
if ( version != 2 && version != 3 )
/*
* Two potential callers, one starts with GML version,
* one starts with geography, and we check for initial
* argument type and then dynamically change what args
* we read based on presence/absence
*/
Oid first_type = get_fn_expr_argtype(fcinfo->flinfo, 0);
int argnum = 0;
int argeom = 0;
if (first_type != INT4OID)
{
elog(ERROR, "Only GML 2 and GML 3 are supported");
PG_RETURN_NULL();
version = 2;
}
else
{
/* Get the version */
version = PG_GETARG_INT32(argnum++);
argeom = 1;
if (version != 2 && version != 3)
{
elog(ERROR, "Only GML 2 and GML 3 are supported");
PG_RETURN_NULL();
}
}
/* Get the geography */
if ( PG_ARGISNULL(1) ) PG_RETURN_NULL();
g = PG_GETARG_GSERIALIZED_P(1);
/* Get the parameters, both callers have same order */
g = PG_GETARG_GSERIALIZED_P(argnum++);
precision = PG_GETARG_INT32(argnum++);
option = PG_GETARG_INT32(argnum++);
prefix_text = PG_GETARG_TEXT_P(argnum++);
id_text = PG_GETARG_TEXT_P(argnum++);
/* Convert to lwgeom so we can run the old functions */
lwgeom = lwgeom_from_gserialized(g);
/* Retrieve precision if any (default is max) */
if (PG_NARGS() >2 && !PG_ARGISNULL(2))
/* Condition the precision argument */
if (precision > DBL_DIG)
precision = DBL_DIG;
if (precision < 0)
precision = 0;
/* Condition the prefix argument */
if (VARSIZE_ANY_EXHDR(prefix_text) > 0)
{
precision = PG_GETARG_INT32(2);
/* TODO: leave this to liblwgeom */
if ( precision > DBL_DIG )
precision = DBL_DIG;
else if ( precision < 0 ) precision = 0;
/* +2 is one for the ':' and one for term null */
prefix_buf = palloc(VARSIZE_ANY_EXHDR(prefix_text)+2);
memcpy(prefix_buf, VARDATA_ANY(prefix_text),
VARSIZE_ANY_EXHDR(prefix_text));
/* add colon and null terminate */
prefix_buf[VARSIZE_ANY_EXHDR(prefix_text)] = ':';
prefix_buf[VARSIZE_ANY_EXHDR(prefix_text)+1] = '\0';
prefix = prefix_buf;
}
/* retrieve option */
if (PG_NARGS() >3 && !PG_ARGISNULL(3))
option = PG_GETARG_INT32(3);
/* retrieve prefix */
if (PG_NARGS() >4 && !PG_ARGISNULL(4))
else
{
prefix_text = PG_GETARG_TEXT_P(4);
if ( VARSIZE_ANY_EXHDR(prefix_text) == 0 )
{
prefix = "";
}
else
{
/* +2 is one for the ':' and one for term null */
prefix_buf = palloc(VARSIZE_ANY_EXHDR(prefix_text)+2);
memcpy(prefix_buf, VARDATA_ANY(prefix_text),
VARSIZE_ANY_EXHDR(prefix_text));
/* add colon and null terminate */
prefix_buf[VARSIZE_ANY_EXHDR(prefix_text)] = ':';
prefix_buf[VARSIZE_ANY_EXHDR(prefix_text)+1] = '\0';
prefix = prefix_buf;
}
prefix = "";
}
/* retrieve id */
if (PG_NARGS() >5 && !PG_ARGISNULL(5))
if (VARSIZE_ANY_EXHDR(id_text) > 0)
{
id_text = PG_GETARG_TEXT_P(5);
if ( VARSIZE_ANY_EXHDR(id_text) == 0 )
{
id = "";
}
else
{
id_buf = palloc(VARSIZE_ANY_EXHDR(id_text)+1);
memcpy(id_buf, VARDATA(id_text), VARSIZE_ANY_EXHDR(id_text));
prefix_buf[VARSIZE_ANY_EXHDR(id_text)+1] = '\0';
id = id_buf;
}
id_buf = palloc(VARSIZE_ANY_EXHDR(id_text)+1);
memcpy(id_buf, VARDATA(id_text), VARSIZE_ANY_EXHDR(id_text));
prefix_buf[VARSIZE_ANY_EXHDR(id_text)+1] = '\0';
id = id_buf;
}
if (option & 1) srs = getSRSbySRID(srid, false);
......@@ -328,10 +325,10 @@ Datum geography_as_gml(PG_FUNCTION_ARGS)
gml = lwgeom_to_gml3(lwgeom, srs, precision, lwopts, prefix, id);
lwgeom_free(lwgeom);
PG_FREE_IF_COPY(g, 1);
PG_FREE_IF_COPY(g, argeom);
/* Return null on null */
if ( ! gml )
if (!gml)
PG_RETURN_NULL();
/* Turn string result into text for return */
......@@ -348,70 +345,45 @@ Datum geography_as_gml(PG_FUNCTION_ARGS)
PG_FUNCTION_INFO_V1(geography_as_kml);
Datum geography_as_kml(PG_FUNCTION_ARGS)
{
GSERIALIZED *g = NULL;
LWGEOM *lwgeom = NULL;
char *kml;
text *result;
int version;
int precision = DBL_DIG;
static const char *default_prefix = "";
char *prefixbuf;
const char* prefix = default_prefix;
text *prefix_text;
/* Get the version */
version = PG_GETARG_INT32(0);
if ( version != 2)
{
elog(ERROR, "Only KML 2 is supported");
PG_RETURN_NULL();
}
/* Get the geometry */
if ( PG_ARGISNULL(1) ) PG_RETURN_NULL();
g = PG_GETARG_GSERIALIZED_P(1);
/* Convert to lwgeom so we can run the old functions */
lwgeom = lwgeom_from_gserialized(g);
/* Retrieve precision if any (default is max) */
if (PG_NARGS() >2 && !PG_ARGISNULL(2))
const char *prefix = default_prefix;
GSERIALIZED *g = PG_GETARG_GSERIALIZED_P(0);
int precision = PG_GETARG_INT32(1);
text *prefix_text = PG_GETARG_TEXT_P(2);
LWGEOM *lwgeom = lwgeom_from_gserialized(g);
/* Condition the precision */
if (precision > DBL_DIG)
precision = DBL_DIG;
if (precision < 0)
precision = 0;
if (VARSIZE_ANY_EXHDR(prefix_text) > 0)
{
precision = PG_GETARG_INT32(2);
/* TODO: leave this to liblwgeom */
if ( precision > DBL_DIG )
precision = DBL_DIG;
else if ( precision < 0 ) precision = 0;
/* +2 is one for the ':' and one for term null */
prefixbuf = palloc(VARSIZE_ANY_EXHDR(prefix_text)+2);
memcpy(prefixbuf, VARDATA(prefix_text),
VARSIZE_ANY_EXHDR(prefix_text));
/* add colon and null terminate */
prefixbuf[VARSIZE_ANY_EXHDR(prefix_text)] = ':';
prefixbuf[VARSIZE_ANY_EXHDR(prefix_text)+1] = '\0';
prefix = prefixbuf;
}
/* retrieve prefix */
if (PG_NARGS() >3 && !PG_ARGISNULL(3))
else
{
prefix_text = PG_GETARG_TEXT_P(3);
if ( VARSIZE_ANY_EXHDR(prefix_text) == 0 )
{
prefix = "";
}
else
{
/* +2 is one for the ':' and one for term null */
prefixbuf = palloc(VARSIZE_ANY_EXHDR(prefix_text)+2);
memcpy(prefixbuf, VARDATA(prefix_text),
VARSIZE_ANY_EXHDR(prefix_text));
/* add colon and null terminate */
prefixbuf[VARSIZE_ANY_EXHDR(prefix_text)] = ':';
prefixbuf[VARSIZE_ANY_EXHDR(prefix_text)+1] = '\0';
prefix = prefixbuf;
}
prefix = "";
}
kml = lwgeom_to_kml2(lwgeom, precision, prefix);
lwgeom_free(lwgeom);
PG_FREE_IF_COPY(g, 1);
PG_FREE_IF_COPY(g, 0);
if ( ! kml )
if (!kml)
PG_RETURN_NULL();
result = cstring_to_text(kml);
......@@ -427,32 +399,17 @@ Datum geography_as_kml(PG_FUNCTION_ARGS)
PG_FUNCTION_INFO_V1(geography_as_svg);
Datum geography_as_svg(PG_FUNCTION_ARGS)
{
GSERIALIZED *g = NULL;
LWGEOM *lwgeom = NULL;
char *svg;
text *result;
int relative = 0;
int precision=DBL_DIG;
if ( PG_ARGISNULL(0) ) PG_RETURN_NULL();
g = PG_GETARG_GSERIALIZED_P(0);
/* Convert to lwgeom so we can run the old functions */
lwgeom = lwgeom_from_gserialized(g);
/* check for relative path notation */
if ( PG_NARGS() > 1 && ! PG_ARGISNULL(1) )
relative = PG_GETARG_INT32(1) ? 1:0;
GSERIALIZED *g = PG_GETARG_GSERIALIZED_P(0);
int relative = PG_GETARG_INT32(1) ? 1 : 0;
int precision = PG_GETARG_INT32(2);
LWGEOM *lwgeom = lwgeom_from_gserialized(g);
if ( PG_NARGS() > 2 && ! PG_ARGISNULL(2) )
{
precision = PG_GETARG_INT32(2);
/* TODO: leave this to liblwgeom */
if ( precision > DBL_DIG )
precision = DBL_DIG;
else if ( precision < 0 ) precision = 0;
}
if (precision > DBL_DIG)
precision = DBL_DIG;
else if (precision < 0)