Ok, I will be more precise.<br><br>A line in postgis is represented by a sequence of points (let's call them A,B,C,D...) connected with straight lines, right?<br><br>Now, for me, the distance between a point (X) and a line in general is the smallest distance between any point on the line and the point X. But, by any point on the line, I do not mean any of the A,B,C,D... points, but also any point on the straight lines between A and B, B and C, C and D....<br>
<br>So, the function you suggested - ST_line_locate_point(line, point), does it give me one of the A,B,C,D... points or does return really the closest point, even if it has to find it somewhere on the connecting lines? This is crucial. If this can really find the closest point, then the rest is great, but I doubt that.<br>
<br><div class="gmail_quote">2009/7/10 Pavel Iacovlev <span dir="ltr"><<a href="mailto:iacovlev.pavel@gmail.com">iacovlev.pavel@gmail.com</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
The length of the line, you can't calculate a distance between a point<br>
and a line in general. You can calculate a distance between a point<br>
and a point on a line.<br>
<br>
ST_distance_spheroid(point, ST_line_interpolate_point(line,<br>
ST_line_locate_point(line, point)),<br>
<div class="im">'SPHEROID["GRS_1980",6378137,298.257222101]')<br>
<br>
</div>ST_line_locate_point(line, point) - a point on the line that is most<br>
close to your initial point<br>
<br>
ST_line_interpolate_point - get that point as a point geometry<br>
<br>
ST_distance_spheroid - calculate the length between 2 points<br>
<div><div></div><div class="h5"><br>
2009/7/10 Peter Kukuča <<a href="mailto:pjr.kukuca@gmail.com">pjr.kukuca@gmail.com</a>>:<br>
> How is your query calculating the distance between a point and a line? Are<br>
> you not just calculating the length of the line?<br>
><br>
> 2009/7/10 Pavel Iacovlev <<a href="mailto:iacovlev.pavel@gmail.com">iacovlev.pavel@gmail.com</a>><br>
>><br>
>> Works on lines for me:<br>
>><br>
>> QUERY:<br>
>> select ST_length_spheroid(st_transform(the_geom, 4326),<br>
>> 'SPHEROID["GRS_1980",6378137,298.257222101]') as ellps_distance,<br>
>> st_distance(the_geom) as normal_distance from fondcart_layers.roads<br>
>> limit 1<br>
>><br>
>> RESULT:<br>
>> ellps_distance: 9214.65310341668<br>
>> normal_distance: 9214.10811677981<br>
>><br>
>> 2009/7/10 Peter Kukuča <<a href="mailto:pjr.kukuca@gmail.com">pjr.kukuca@gmail.com</a>>:<br>
>> > ST_Length_spheroid is perfectly great, but it does not take a line as an<br>
>> > input :-(<br>
>> ><br>
>> > 2009/7/10 Pavel Iacovlev <<a href="mailto:iacovlev.pavel@gmail.com">iacovlev.pavel@gmail.com</a>><br>
>> >><br>
>> >> And for geometry length use ST_length_spheroid(geometry,spheroid)<br>
>> >><br>
>> >> On Fri, Jul 10, 2009 at 11:48 AM, Pavel<br>
>> >> Iacovlev<<a href="mailto:iacovlev.pavel@gmail.com">iacovlev.pavel@gmail.com</a>> wrote:<br>
>> >> > you can take the middle of the line,<br>
>> >> > st_line_interpolate_point(the_geom,<br>
>> >> > 0.5)<br>
>> >> ><br>
>> >> > 2009/7/10 Peter Kukuča <<a href="mailto:pjr.kukuca@gmail.com">pjr.kukuca@gmail.com</a>>:<br>
>> >> >> Hi Pedro,<br>
>> >> >><br>
>> >> >> thank you for your reply.<br>
>> >> >><br>
>> >> >> I cannot use pointn, the line can be up to several hundred<br>
>> >> >> kilometers<br>
>> >> >> long<br>
>> >> >> and consits of up to 800 points, so this would be too rough.<br>
>> >> >><br>
>> >> >> Regardinf the decond suggestion, that is exactly what I am doing<br>
>> >> >> now,<br>
>> >> >> but I<br>
>> >> >> don't know, which projection (srid) to transform the wgs84 data<br>
>> >> >> into.<br>
>> >> >> It<br>
>> >> >> should work on all of the earth's surface, at least in all of europe<br>
>> >> >> for a<br>
>> >> >> start. And from what I found, the projections are usually tied to a<br>
>> >> >> small<br>
>> >> >> territory. I was thinking about mercator projection, but there is a<br>
>> >> >> zillion<br>
>> >> >> of them in postgis. And I found a post, that the one with srid<br>
>> >> >> 900913<br>
>> >> >> is<br>
>> >> >> working great, but I don't have that one in my postgis.<br>
>> >> >><br>
>> >> >> 2009/7/10 Pedro Doria Meunier <<a href="mailto:pdoria@netmadeira.com">pdoria@netmadeira.com</a>><br>
>> >> >>><br>
>> >> >>> -----BEGIN PGP SIGNED MESSAGE-----<br>
>> >> >>> Hash: SHA1<br>
>> >> >>><br>
>> >> >>> Hi Peter<br>
>> >> >>><br>
>> >> >>> You could use the pointn(geometry, n) for the first point of the<br>
>> >> >>> linestring as a first approach.<br>
>> >> >>> As far as meters are concerned here's a little example of<br>
>> >> >>> transforming<br>
>> >> >>> the geometry to the desired projected system:<br>
>> >> >>><br>
>> >> >>> select distance(transform(u.coordinates,srid),<br>
>> >> >>> transform(p.geometry,srid)) AS thedistance<br>
>> >> >>><br>
>> >> >>> HTH,<br>
>> >> >>><br>
>> >> >>> Pedro Doria Meunier<br>
>> >> >>> GSM: +351 96 17 20 188<br>
>> >> >>> Skype: pdoriam<br>
>> >> >>><br>
>> >> >>><br>
>> >> >>><br>
>> >> >>><br>
>> >> >>> Peter Kukuča wrote:<br>
>> >> >>> > Dear sir,<br>
>> >> >>> ><br>
>> >> >>> > I am not sure if I am writing to the correct email address. I<br>
>> >> >>> > have<br>
>> >> >>> > found a post on the postgis-users formu from *Rich Gibson *and<br>
>> >> >>> > this<br>
>> >> >>> > address was next to it.<br>
>> >> >>> ><br>
>> >> >>> > I am using postgis for a while now and it is great. It solved a<br>
>> >> >>> > lot<br>
>> >> >>> > of problems for me.<br>
>> >> >>> ><br>
>> >> >>> > However, I am now facing a problem I cannot solve. I searched for<br>
>> >> >>> > almost two days now, but I still cannot find an answer. Here is<br>
>> >> >>> > my<br>
>> >> >>> > problem:<br>
>> >> >>> ><br>
>> >> >>> > I have a database of linestrings in wgs84 projection and points<br>
>> >> >>> > in<br>
>> >> >>> > wgs84 projection. I would like to determine the distance between<br>
>> >> >>> > a<br>
>> >> >>> > line and a point. The ST_distance function does this very well,<br>
>> >> >>> > but<br>
>> >> >>> > it does not take the wgs84 projection into account and also, the<br>
>> >> >>> > result is in degrees. On the other hand, the ST_Distance_Spheroid<br>
>> >> >>> > does take the wgs84 into accound and does give the result in<br>
>> >> >>> > meters,<br>
>> >> >>> > but it does not accept a linestring as an input parameter.<br>
>> >> >>> ><br>
>> >> >>> > Is there any way i can the distance between a line and a point in<br>
>> >> >>> > meters from the wgs84 projected input? I do not need grat<br>
>> >> >>> > accuracy.<br>
>> >> >>> > +-5 meters is still good enough. Thank you for your tips.<br>
>> >> >>> ><br>
>> >> >>> > --<br>
>> >> >>> > S pozdravom (regards)<br>
>> >> >>> > Ing. Peter Kukuča<br>
>> >> >>> ><br>
>> >> >>> ><br>
>> >> >>> ><br>
>> >> >>> > ----------------------------------------------------------------------<br>
>> >> >>> ><br>
>> >> >>> > _______________________________________________<br>
>> >> >>> > postgis-users mailing list<br>
>> >> >>> > <a href="mailto:postgis-users@postgis.refractions.net">postgis-users@postgis.refractions.net</a><br>
>> >> >>> > <a href="http://postgis.refractions.net/mailman/listinfo/postgis-users" target="_blank">http://postgis.refractions.net/mailman/listinfo/postgis-users</a><br>
>> >> >>> -----BEGIN PGP SIGNATURE-----<br>
>> >> >>> Version: GnuPG v1.4.7 (GNU/Linux)<br>
>> >> >>> Comment: Using GnuPG with Fedora - <a href="http://enigmail.mozdev.org" target="_blank">http://enigmail.mozdev.org</a><br>
>> >> >>><br>
>> >> >>> iD8DBQFKVv052FH5GXCfxAsRAqS1AJ0dfphFX3wrMuo+FdXVRTgmUzHRUACfUmvH<br>
>> >> >>> 146yGHfxoVmlnt9a91rpWmE=<br>
>> >> >>> =G70f<br>
>> >> >>> -----END PGP SIGNATURE-----<br>
>> >> >>><br>
>> >> >>> _______________________________________________<br>
>> >> >>> postgis-users mailing list<br>
>> >> >>> <a href="mailto:postgis-users@postgis.refractions.net">postgis-users@postgis.refractions.net</a><br>
>> >> >>> <a href="http://postgis.refractions.net/mailman/listinfo/postgis-users" target="_blank">http://postgis.refractions.net/mailman/listinfo/postgis-users</a><br>
>> >> >><br>
>> >> >><br>
>> >> >><br>
>> >> >> --<br>
>> >> >> S pozdravom (regards)<br>
>> >> >> Ing. Peter Kukuča<br>
>> >> >><br>
>> >> >> _______________________________________________<br>
>> >> >> postgis-users mailing list<br>
>> >> >> <a href="mailto:postgis-users@postgis.refractions.net">postgis-users@postgis.refractions.net</a><br>
>> >> >> <a href="http://postgis.refractions.net/mailman/listinfo/postgis-users" target="_blank">http://postgis.refractions.net/mailman/listinfo/postgis-users</a><br>
>> >> >><br>
>> >> >><br>
>> >> ><br>
>> >> ><br>
>> >> ><br>
>> >> > --<br>
>> >> > <a href="http://iap.md" target="_blank">http://iap.md</a>, The future is open<br>
>> >> ><br>
>> >><br>
>> >><br>
>> >><br>
>> >> --<br>
>> >> <a href="http://iap.md" target="_blank">http://iap.md</a>, The future is open<br>
>> >> _______________________________________________<br>
>> >> postgis-users mailing list<br>
>> >> <a href="mailto:postgis-users@postgis.refractions.net">postgis-users@postgis.refractions.net</a><br>
>> >> <a href="http://postgis.refractions.net/mailman/listinfo/postgis-users" target="_blank">http://postgis.refractions.net/mailman/listinfo/postgis-users</a><br>
>> ><br>
>> ><br>
>> ><br>
>> > --<br>
>> > S pozdravom (regards)<br>
>> > Ing. Peter Kukuča<br>
>> ><br>
>> > _______________________________________________<br>
>> > postgis-users mailing list<br>
>> > <a href="mailto:postgis-users@postgis.refractions.net">postgis-users@postgis.refractions.net</a><br>
>> > <a href="http://postgis.refractions.net/mailman/listinfo/postgis-users" target="_blank">http://postgis.refractions.net/mailman/listinfo/postgis-users</a><br>
>> ><br>
>> ><br>
>><br>
>><br>
>><br>
>> --<br>
>> <a href="http://iap.md" target="_blank">http://iap.md</a>, The future is open<br>
>> _______________________________________________<br>
>> postgis-users mailing list<br>
>> <a href="mailto:postgis-users@postgis.refractions.net">postgis-users@postgis.refractions.net</a><br>
>> <a href="http://postgis.refractions.net/mailman/listinfo/postgis-users" target="_blank">http://postgis.refractions.net/mailman/listinfo/postgis-users</a><br>
><br>
><br>
><br>
> --<br>
> S pozdravom (regards)<br>
> Ing. Peter Kukuča<br>
><br>
> _______________________________________________<br>
> postgis-users mailing list<br>
> <a href="mailto:postgis-users@postgis.refractions.net">postgis-users@postgis.refractions.net</a><br>
> <a href="http://postgis.refractions.net/mailman/listinfo/postgis-users" target="_blank">http://postgis.refractions.net/mailman/listinfo/postgis-users</a><br>
><br>
><br>
<br>
<br>
<br>
--<br>
<a href="http://iap.md" target="_blank">http://iap.md</a>, The future is open<br>
_______________________________________________<br>
postgis-users mailing list<br>
<a href="mailto:postgis-users@postgis.refractions.net">postgis-users@postgis.refractions.net</a><br>
<a href="http://postgis.refractions.net/mailman/listinfo/postgis-users" target="_blank">http://postgis.refractions.net/mailman/listinfo/postgis-users</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>S pozdravom (regards)<br>Ing. Peter Kukuča<br>