# [postgis-users] Help determining position

Sun Oct 18 20:17:34 PDT 2009

```Surya,

> with help of the list I am able to determine minimum width of a river using SQL below. Especially thanks to Mr. Simon Greener.. I still need to determine position (in meter and also latlon) of this point from the river mounth. Can anybody give me suggestion what Postgis function I should use together with the following SQL.

Not going to do everything for you (after all you have not supplied us a definition of the river mouth), but I would probably start by trying to find the actual points in the left/right bank that are closest via something like this:

-- Which points are closest to each other?
--
SELECT l.rin,ST_Point((l.coord).x,(l.coord).y),
r.rin,ST_Point((r.coord).x,(r.coord).y),
ST_Distance(ST_Point((l.coord).x,(l.coord).y),
ST_Point((r.coord).x,(r.coord).y)) as PDistance
FROM (select row_number() over (order by the_geom) as rin,
ST_DumpPoints(the_geom) as coord
from River r
where r.Name = 'Barito' ) as l,
(select row_number() over (order by the_geom) as rin,
ST_DumpPoints(the_geom) as coord
from River r
where r.Name = 'Barito' ) as r
WHERE l.rin <> r.rin
ORDER BY 5 ASC
LIMIT 1;

Note, the ST_DumpPoints() function is a user defined one you can get from http://www.spatialdbadvisor.com/postgis_tips_tricks/109/implementing-oracles-getvertices-function-in-postgis-st_dumppoints

But this will return the left and right points that are closest. Then you need to calculate the distance from each point to the point that defines the mouth of your river and chose the closest.

regards
Simon

--
SpatialDB Advice and Design, Solutions Architecture and Programming,
Oracle Database 10g Administrator Certified Associate; Oracle Database 10g SQL Certified Professional
Oracle Spatial, SQL Server, PostGIS, MySQL, ArcSDE, Manifold GIS, FME, Radius Topology and Studio Specialist.
39 Cliff View Drive, Allens Rivulet, 7150, Tasmania, Australia.