[postgis-users] Query for nearest linestrings to a point, for latitude/longitude

Ovidiu Gheorghies govidiu at yahoo.com
Sun Aug 19 23:49:58 PDT 2007


I agree with your comment on the distortion of results cause by the fact that line_locate_point assumes Cartesian coordinates. Could you show me more precisely (in pseudocode) how to do the projections and compute the distance? I noticed that SRID-s correspond to specific region on the Earth, is it possible to write a code that works worldwide and not only for a specific region?

Best regards,
Ovidiu

----- Original Message ----
From: Rick Zoolker <zoolker at gmail.com>
To: PostGIS Users Discussion <postgis-users at postgis.refractions.net>
Sent: Monday, 20 August 2007 5:44:25
Subject: Re: [postgis-users] Query for nearest linestrings to a point, for latitude/longitude

I don't think the line_locate_point() will work properly with lat/long
coordinates as I believe it assumes Cartesian coordinates.
You could project all of the geometries and then use ST_Distance() to
determine the distance between your point and the linestrings.

On 8/17/07, Ovidiu Gheorghies <govidiu at yahoo.com> wrote:
> Hello all,
>
> I'm writing to ask if at this moment there is a better approach to what I am trying to achieve in PostGIS.
>
> The purpose of the query is to determine all the linestrings within x
> km from a point, given that the linestrings and the point are stored as
> GPS positions (latitude/longitude, SRID=4326).
>
> (see attached image)
>
> My proposed algorithm is:
>
>     * step 1: select all the linestrings within, say, 1 degree of latitude/longitude from the given point P, located at POINT(44 15):
>
>  SELECT myline, myname
>    FROM mylines
>      WHERE myline && Expand('POINT(44 15)', 1)
>
> The purpose is to quickly select relevant linestrings, using an index. For example, in the figure, lines L1, L2 and L3 will be selected, while L4 and other far-away linestrings will not be selected.
>
>     * step 2: for each of the obtained lines (L1, L2, and L3 in the figure) determine the closest points/projections (P1, P2 and P3) on the corresponding linestrings using (in pseudo-code):
>
> Pi_factor := line_locate_point(Li, P)
> Pi := line_interpolate_point(Li, Pi_factor)
>
>     * step 3: for each of the determined points (P1, P2, P3), compute the distance to P:
>
> Di := distance_sphere(P, Pi)
>
>     * step 4: knowing the correct distances on Earth between the points, select the desired linestrings
>
> I'd love to hear that this can be done much easier in PostGIS, but if not I will contribute a working plpgsql function based on your feedback.
>
> Best regards,
> Ovidiu
>
>
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users
>
>
>
_______________________________________________
postgis-users mailing list
postgis-users at postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users






More information about the postgis-users mailing list