<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 12 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri","sans-serif";
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal>Hi,<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>I have a really simple problem but I am not able to solve the problem.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>I have a point data and a have polygon data and I want to merge the data of the polygon to the points based on the nearest distance to polygon.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>The problem is that my point data is 2,5 million observations and the polygon are approximately 700 observations resulting in 1,75 billion rows where I have to minimize over 700.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Currently I have the following query:<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>SELECT<o:p></o:p></p><p class=MsoNormal>a.key,<o:p></o:p></p><p class=MsoNormal>b.gid, <o:p></o:p></p><p class=MsoNormal>st_distance(a.the_geom, b.the_geom) as dist,<o:p></o:p></p><p class=MsoNormal>s.min_dist<o:p></o:p></p><p class=MsoNormal>FROM<o:p></o:p></p><p class=MsoNormal> Neighbor as b, point as a<o:p></o:p></p><p class=MsoNormal>LEFT JOIN<o:p></o:p></p><p class=MsoNormal> (SELECT <o:p></o:p></p><p class=MsoNormal> a.key, MIN(st_distance(a.the_geom, b.the_geom)) as min_dist<o:p></o:p></p><p class=MsoNormal> FROM<o:p></o:p></p><p class=MsoNormal> Neighbor as b, point as a<o:p></o:p></p><p class=MsoNormal> GROUP BY <o:p></o:p></p><p class=MsoNormal> a.key) s<o:p></o:p></p><p class=MsoNormal>ON<o:p></o:p></p><p class=MsoNormal> a."key" = S."key"<o:p></o:p></p><p class=MsoNormal>ORDER by a.key <o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>This querty gives all the 1,75 billion possibilities which then can be used to minimize over a.key restricted by dist=min_dist, the problem is that by the first query the computer run out of memory, so the second query is not working.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>In arcgis the problem is joining by closed distance but I need to do it in postgis.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Hope you can help my,<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Faroek<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p></div></body></html>