Your spatial join appears to be joining streets_prov_roma to itself, and doing the LIMIT before joining to data_crash_feature. Thus you may only be getting on street to match to all the points. I think you can simplify your query a bit (see here: <a href="http://postgis.refractions.net/documentation/manual-svn/ST_DWithin.html">http://postgis.refractions.net/documentation/manual-svn/ST_DWithin.html</a>) rather than using a subquery in the join clause put the ST_DWithin spatial join directly into your join statement.<br>
<br>Mark<br><br><div class="gmail_quote">On Wed, May 6, 2009 at 4:54 AM, totom <span dir="ltr"><<a href="mailto:tommaso.lavoro@gmail.com">tommaso.lavoro@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
Hi, I'm asking help for a (maybe) simple query.<br>
I have 2 tables, p filled with points and l filled with lines.<br>
I want an outher join p and l on the closest line to each point...<br>
data_crash_feature are points, streets_prov_roma are lines, and my query<br>
obviously doesn't work...<br>
<br>
SELECT<br>
<a href="http://data_crash_feature.id" target="_blank">data_crash_feature.id</a>,data_crash_feature.description,data_crash_feature._fid<br>
,streets_prov_roma.gid,streets_prov_roma.st_name,<br>
ST_Distance(streets_prov_roma.the_geom,data_crash_feature.the_geom) as dist<br>
FROM data_crash_feature<br>
RIGHT OUTER JOIN streets_prov_roma<br>
ON streets_prov_roma.gid IN (<br>
SELECT s2.gid<br>
FROM streets_prov_roma s2<br>
WHERE ST_DWithin(streets_prov_roma.the_geom, s2.the_geom, 0.0001) AND<br>
s2.st_name != ''<br>
ORDER BY Distance(streets_prov_roma.the_geom, s2.the_geom) ASC<br>
LIMIT 1<br>
)<br>
<br>
Can anyone help me?<br>
<font color="#888888">--<br>
View this message in context: <a href="http://www.nabble.com/Join-on-closest-point-tp23402603p23402603.html" target="_blank">http://www.nabble.com/Join-on-closest-point-tp23402603p23402603.html</a><br>
Sent from the PostGIS - User mailing list archive at Nabble.com.<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>
</font></blockquote></div><br>