[postgis-users] Postgis - Line to Point distance

Pedro Doria Meunier pdoria at netmadeira.com
Fri Jul 10 01:53:10 PDT 2009


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi

You can always get the desired SRID from the spatial_ref_sys table via
the longitude of your point.
Here's two helper functions in PHP to achieve just that:

// determine UTM zone from LonLat coordinates
// params $long: longitude
// returns (int) utm
function UtmZoneFromLong($lon) {
    $utm = floor(($lon + 180) / 6) + 1;
    return $utm;
}

// query the spatial_ref_sys table for the srid of the given utm zone
// params $utm: utm zone string (MUST BE TRAILED WITH 'N' OR 'S'!),
$conn: connection to the db
// returns (int) srid
function SridFromUtmZone($utm, $conn){
    $myresult = pg_exec($conn, "SELECT srid FROM spatial_ref_sys WHERE
srtext LIKE 'PROJCS[\"WGS 84 / UTM zone $utm%' LIMIT 1");
    $srid=pg_result($myresult, 0, 0);
    return $srid;
}

Even if you're not in PHP programming I think that with this you can
extrapolate to some other solution ;-)

Pedro Doria Meunier
GSM: +351 96 17 20 188
Skype: pdoriam
 



Peter Kukuča wrote:
> Hi Pedro,
>
> thank you for your reply.
>
> I cannot use pointn, the line can be up to several hundred
> kilometers long and consits of up to 800 points, so this would be
> too rough.
>
> Regardinf the decond suggestion, that is exactly what I am doing
> now, but I don't know, which projection (srid) to transform the
> wgs84 data into. It should work on all of the earth's surface, at
> least in all of europe for a start. And from what I found, the
> projections are usually tied to a small territory. I was thinking
> about mercator projection, but there is a zillion of them in
> postgis. And I found a post, that the one with srid 900913 is
> working great, but I don't have that one in my postgis.
>
> 2009/7/10 Pedro Doria Meunier <pdoria at netmadeira.com
> <mailto:pdoria at netmadeira.com>>
>
> Hi Peter
>
> You could use the pointn(geometry, n) for the first point of the
> linestring as a first approach. As far as meters are concerned
> here's a little example of transforming the geometry to the desired
> projected system:
>
> select distance(transform(u.coordinates,srid),
> transform(p.geometry,srid)) AS thedistance
>
> HTH,
>
> Pedro Doria Meunier GSM: +351 96 17 20 188 Skype: pdoriam
>
>
>
>
> Peter Kuku a wrote:
>> Dear sir,
>
>> I am not sure if I am writing to the correct email address. I
>> have found a post on the postgis-users formu from *Rich Gibson
>> *and
> this
>> address was next to it.
>
>> I am using postgis for a while now and it is great. It solved
> a lot
>> of problems for me.
>
>> However, I am now facing a problem I cannot solve. I searched for
>>  almost two days now, but I still cannot find an answer. Here is
>> my problem:
>
>> I have a database of linestrings in wgs84 projection and points
>> in wgs84 projection. I would like to determine the distance
>> between a line and a point. The ST_distance function does this
>> very
> well, but
>> it does not take the wgs84 projection into account and also, the
>> result is in degrees. On the other hand, the ST_Distance_Spheroid
>>  does take the wgs84 into accound and does give the result in
> meters,
>> but it does not accept a linestring as an input parameter.
>
>> Is there any way i can the distance between a line and a point in
>>  meters from the wgs84 projected input? I do not need grat
> accuracy.
>> +-5 meters is still good enough. Thank you for your tips.
>
>> -- S pozdravom (regards) Ing. Peter Kuku a
>
>
> ----------------------------------------------------------------------
>
>
>> _______________________________________________ postgis-users
>> mailing list postgis-users at postgis.refractions.net
> <mailto:postgis-users at postgis.refractions.net>
>> http://postgis.refractions.net/mailman/listinfo/postgis-users

_______________________________________________
postgis-users mailing list
postgis-users at postgis.refractions.net
<mailto:postgis-users at postgis.refractions.net>
http://postgis.refractions.net/mailman/listinfo/postgis-users




> -- S pozdravom (regards) Ing. Peter Kukuča

> ----------------------------------------------------------------------
>  _______________________________________________ postgis-users
> mailing list postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

iD4DBQFKVwFs2FH5GXCfxAsRAgzVAKCUE0IUvsWUoyCtLqkRSzMKyzaq0QCY6EM2
QCdiM4Xn3ml5J/6aPRBLNA==
=VeCn
-----END PGP SIGNATURE-----




More information about the postgis-users mailing list