[postgis-tickets] [PostGIS] #4700: Add more geography functions
PostGIS
trac at osgeo.org
Mon Jun 8 02:19:15 PDT 2020
#4700: Add more geography functions
-------------------------+---------------------
Reporter: vogg | Owner: pramsey
Type: enhancement | Status: new
Priority: medium | Milestone:
Component: postgis | Version: 2.3.x
Keywords: geography |
-------------------------+---------------------
When working with the GEOGRAPHY type, there are still many functions
missing, compared to the GEOMETRY type. This makes working with GEOGRAPHY
a lot more cumbersome than it needs to be.
While it is clear that some functions require extra care, we should at
least provide proper support for the "trivial" functions which are merely
packing and unpacking data structures.
In a real-world codebase, I found myself implementing the following helper
functions. Those already go a long way, and motivated coworkers to use
proper GEOGRAPHY where they otherwise would have avoided all that trouble:
{{{
create or replace function ad_internal.ST_MakeLine(geog1 geography, geog2
geography) returns geography immutable language sql as $$
select ST_MakeLine(geog1::geometry, geog2::geometry)::geography
$$;
create or replace function ad_internal.ST_StartPoint(line geography)
returns geography immutable language sql as $$
select ST_StartPoint(line::geometry)::geography
$$;
create or replace function ad_internal.ST_EndPoint(line geography) returns
geography immutable language sql as $$
select ST_EndPoint(line::geometry)::geography
$$;
create or replace function ad_internal.ST_Collect(g1 geography, g2
geography) returns geography immutable language sql as $$
select ST_Collect(g1::geometry, g2::geometry)::geography
$$;
create or replace function ad_internal.ST_Points(geog geography) returns
geography immutable language sql as $$
select ST_Points(geog::geometry)::geography
$$;
}}}
In addition, I propose the following addition to ST_Azimuth(), which
allows us to treat a 2-point-line as vector and calculating its azimuth
(it may be open to debate whether this function should be restricted to
1-point lines, or should allow for any line string, but taking the vector
only from the first point directly to the last point):
{{{
create or replace function ad_internal.ST_Azimuth(line geography) returns
float immutable language sql as $$
select ST_Azimuth(ad_internal.ST_StartPoint(line),
ad_internal.ST_EndPoint(line))
$$;
}}}
Note that all implementations are pure SQL. Is this okay, or are those
functions are only acceptable when provided as low-level C/C++ functions?
--
Ticket URL: <https://trac.osgeo.org/postgis/ticket/4700>
PostGIS <http://trac.osgeo.org/postgis/>
The PostGIS Trac is used for bug, enhancement & task tracking, a user and developer wiki, and a view into the subversion code repository of PostGIS project.
More information about the postgis-tickets
mailing list