[postgis-users] generating new point geometry

Nicolas Ribot nicolas.ribot at gmail.com
Thu Sep 15 08:52:26 PDT 2011


On 15 September 2011 17:18, Yamini Singh <yaminijsingh at live.com> wrote:
> Hi All,
>
> I have two questions to ask:
>
> Q1: I have a table that has one geometry column and I want to calculate
> distance (in Km) between two geometries which is in one column. I am using
> select query as under, and wanted to know if this is the right way of doing
> distance calculation between two points. Since, both the points are in one
> table but in different rows so I am using select statement to pick the geom
> from
> each row.
>
> select st_distance_sphere((select the_geom from table_name where
> place_name='PL1'), (select the_geom from table_name where
> place_name='PL2'))/1000;
>
> Q2: I have a table that has columns distance, direction, place_name
> and geometry (with SRID 4326) as under.
>
> _________________________________________________________
>
> | Id | distance | direction | Place_name |    geom      |
> --------------------------------------------------------
> |  1 |   42 km  |    E      | PL1        | some geometry|
>
> ---------------------------------------------------------
>
> Now I want to calculate new geometry with reference to given geometry based
> on some distance and direction. Such that new geometry is at ?42km E of some
> reference geometry?. Is there a function that can do this? Or if someone can
> point me to a specific link..
>

Hi Yamini,

It may be easier to first reproject your data to a planar system
before translating geometries, then st_translate() should do the
trick.
Based on distance and direction, you can compute the deltax and deltay
translation parameters and give them to st_translate (here, 42 000 m
(assuming your planar projection system is in meters) added to X
coordinate will translate the input geometry east.

I don't think st_translate will be able to work with geographic data
without some maths to convert from KM to degrees, taking into account
currrent latitude.

Nicolas



More information about the postgis-users mailing list