Anyway, many thanks Pavel. You really helped me. I was looking at the functions you used in the past, but it did not come to me to use them for this problem.<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;">Yes they are in "reverse order", there is no standard for lat or lon<br>
should be first (as I know), blame wkb/wkt :)<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>
> Hi,<br>
><br>
> Thank you a million times Pavel. I tried it out and it really works and<br>
> gives the distance from the line. It is absolutely great. I didn't think I<br>
> would have it running ever.<br>
><br>
> But, now I have another problem. Look at these two select statements:<br>
><br>
> select ST_distance_spheroid(pointfromtext('POINT(60 0)', 4326),<br>
> ST_line_interpolate_point(linestringfromtext('LINESTRING(0 0,80 0)', 4326),<br>
> ST_line_locate_point(linestringfromtext('LINESTRING(0 0,80 0)', 4326),<br>
> pointfromtext('POINT(60 1)', 4326))),<br>
> 'SPHEROID["GRS_1980",6378137,298.257222101]');<br>
><br>
> returns the same distance (110574.38861168) as<br>
><br>
> select ST_distance_spheroid(pointfromtext('POINT(0 1)', 4326),<br>
> ST_line_interpolate_point(linestringfromtext('LINESTRING(0 0,80 0)', 4326),<br>
> ST_line_locate_point(linestringfromtext('LINESTRING(0 0,80 0)', 4326),<br>
> pointfromtext('POINT(0 1)', 4326))),<br>
> 'SPHEROID["GRS_1980",6378137,298.257222101]');<br>
><br>
> What is done in the example is a calculation of the distance represented by<br>
> 1 degree of longitude at two different latitudes. While the distance at zero<br>
> latitude is correct, the distance at 60° latitude should be exactly half<br>
> that. The funny part is, that I get the same result with simple point to<br>
> point calculations. And the absolutely best part is, when I swap all<br>
> latitudes and longitudes, it works. Now the only reasonable explanation is,<br>
> that all of the functions take longitude as their first parameter and<br>
> latitude as the second, but isn't this the other way around?<br>
><br>
> 2009/7/10 Pavel Iacovlev <<a href="mailto:iacovlev.pavel@gmail.com">iacovlev.pavel@gmail.com</a>><br>
>><br>
>> ST_line_locate_point returns the location (float) of the closest point<br>
>> on a line to a specified point, read the postgis manual it's all<br>
>> written there. After this you use ST_line_interpolate_point to<br>
>> transform that location to a point geometry.<br>
>><br>
>> 2009/7/10 Peter Kukuča <<a href="mailto:pjr.kukuca@gmail.com">pjr.kukuca@gmail.com</a>>:<br>
>> > Ok, I will be more precise.<br>
>> ><br>
>> > A line in postgis is represented by a sequence of points (let's call<br>
>> > them<br>
>> > 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<br>
>> > the<br>
>> > smallest distance between any point on the line and the point X. But, by<br>
>> > any<br>
>> > point on the line, I do not mean any of the A,B,C,D... points, but also<br>
>> > any<br>
>> > 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<br>
>> > it<br>
>> > give me one of the A,B,C,D... points or does return really the closest<br>
>> > point, even if it has to find it somewhere on the connecting lines? This<br>
>> > is<br>
>> > crucial. If this can really find the closest point, then the rest is<br>
>> > great,<br>
>> > but I doubt that.<br>
>> ><br>
>> > 2009/7/10 Pavel Iacovlev <<a href="mailto:iacovlev.pavel@gmail.com">iacovlev.pavel@gmail.com</a>><br>
>> >><br>
>> >> 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>
>> >> 'SPHEROID["GRS_1980",6378137,298.257222101]')<br>
>> >><br>
>> >> 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>
>> >><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<br>
>> >> > line?<br>
>> >> > 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<br>
>> >> >> > as<br>
>> >> >> > 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<br>
>> >> >> >> >> doing<br>
>> >> >> >> >> now,<br>
>> >> >> >> >> but I<br>
>> >> >> >> >> don't know, which projection (srid) to transform the wgs84<br>
>> >> >> >> >> data<br>
>> >> >> >> >> into.<br>
>> >> >> >> >> It<br>
>> >> >> >> >> should work on all of the earth's surface, at least in all of<br>
>> >> >> >> >> europe<br>
>> >> >> >> >> for a<br>
>> >> >> >> >> start. And from what I found, the projections are usually tied<br>
>> >> >> >> >> to<br>
>> >> >> >> >> a<br>
>> >> >> >> >> small<br>
>> >> >> >> >> territory. I was thinking about mercator projection, but there<br>
>> >> >> >> >> is<br>
>> >> >> >> >> 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<br>
>> >> >> >> >>> 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.<br>
>> >> >> >> >>> > I<br>
>> >> >> >> >>> > have<br>
>> >> >> >> >>> > found a post on the postgis-users formu from *Rich Gibson<br>
>> >> >> >> >>> > *and<br>
>> >> >> >> >>> > this<br>
>> >> >> >> >>> > address was next to it.<br>
>> >> >> >> >>> ><br>
>> >> >> >> >>> > I am using postgis for a while now and it is great. It<br>
>> >> >> >> >>> > solved<br>
>> >> >> >> >>> > a<br>
>> >> >> >> >>> > lot<br>
>> >> >> >> >>> > of problems for me.<br>
>> >> >> >> >>> ><br>
>> >> >> >> >>> > However, I am now facing a problem I cannot solve. I<br>
>> >> >> >> >>> > searched<br>
>> >> >> >> >>> > for<br>
>> >> >> >> >>> > almost two days now, but I still cannot find an answer.<br>
>> >> >> >> >>> > Here<br>
>> >> >> >> >>> > is<br>
>> >> >> >> >>> > my<br>
>> >> >> >> >>> > problem:<br>
>> >> >> >> >>> ><br>
>> >> >> >> >>> > I have a database of linestrings in wgs84 projection and<br>
>> >> >> >> >>> > points<br>
>> >> >> >> >>> > in<br>
>> >> >> >> >>> > wgs84 projection. I would like to determine the distance<br>
>> >> >> >> >>> > between<br>
>> >> >> >> >>> > a<br>
>> >> >> >> >>> > line and a point. The ST_distance function does this very<br>
>> >> >> >> >>> > well,<br>
>> >> >> >> >>> > but<br>
>> >> >> >> >>> > it does not take the wgs84 projection into account and<br>
>> >> >> >> >>> > also,<br>
>> >> >> >> >>> > the<br>
>> >> >> >> >>> > result is in degrees. On the other hand, the<br>
>> >> >> >> >>> > ST_Distance_Spheroid<br>
>> >> >> >> >>> > does take the wgs84 into accound and does give the result<br>
>> >> >> >> >>> > 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<br>
>> >> >> >> >>> > point<br>
>> >> >> >> >>> > 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>
>> >> >> >> >>> ><br>
>> >> >> >> >>> > _______________________________________________<br>
>> >> >> >> >>> > postgis-users mailing list<br>
>> >> >> >> >>> > <a href="mailto:postgis-users@postgis.refractions.net">postgis-users@postgis.refractions.net</a><br>
>> >> >> >> >>> ><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>
>> >> >> >> >>><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>
>> ><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>