<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<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 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;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","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;}
p
        {mso-style-priority:99;
        mso-margin-top-alt:auto;
        margin-right:0cm;
        mso-margin-bottom-alt:auto;
        margin-left:0cm;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page Section1
        {size:612.0pt 792.0pt;
        margin:70.85pt 70.85pt 70.85pt 70.85pt;}
div.Section1
        {page:Section1;}
-->
</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=FR-BE link=blue vlink=purple>

<div class=Section1>

<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>Hello,<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>

<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>Thank you for this input.<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>

<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>At a first glance I did not understand it fully but I’ll take
time to go deeper.<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>

<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>Indeed a tutorial might be useful for several users as I think
merging road elements is a redundant issue for GIS users.<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>

<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>Nicolas.<o:p></o:p></span></p>

<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>

<div>

<div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm'>

<p class=MsoNormal><b><span lang=FR style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>De :</span></b><span
lang=FR style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>
postgis-users-bounces@postgis.refractions.net
[mailto:postgis-users-bounces@postgis.refractions.net] <b>De la part de</b>
Nicklas Avén<br>
<b>Envoyé :</b> jeudi 14 janvier 2010 14:38<br>
<b>À :</b> PostGIS Users Discussion<br>
<b>Objet :</b> Re: [postgis-users] Huge query, out of memory<o:p></o:p></span></p>

</div>

</div>

<p class=MsoNormal><o:p> </o:p></p>

<p class=MsoNormal>Hallo <o:p></o:p></p>

<p class=MsoNormal> <o:p></o:p></p>

<p class=MsoNormal> <o:p></o:p></p>

<p class=MsoNormal>I have been struggling with the same task. I don't know if I
have solved it because I ran out of time a few months ago. But I attach the sql
as a file with some descriptive texts. I intend to check it more properly and
write some tutorial, but that will take some time before I can do.<o:p></o:p></p>

<p class=MsoNormal> <o:p></o:p></p>

<p class=MsoNormal>So, no guarantees :-)<o:p></o:p></p>

<p class=MsoNormal> <o:p></o:p></p>

<p class=MsoNormal>/Nicklas<br>
<br>
2010-01-14 Nicolas Gillet - MARKET-IP wrote:<br>
<br>
><o:p></o:p></p>

<p>Hello,<o:p></o:p></p>

<p> <o:p></o:p></p>

<p> <o:p></o:p></p>

<p> <o:p></o:p></p>

<p>I have a big shape file to process (about 300 Mo,  1.5 million records)<o:p></o:p></p>

<p> <o:p></o:p></p>

<p>I have to aggregate the touching linestrings having the same attributes
therefore the best way I could find (with help of this mailing list) was to
aggregate all the linestrings with the same attribute and then splitting the
ones that dont touch.<o:p></o:p></p>

<p> <o:p></o:p></p>

<p> <o:p></o:p></p>

<p> <o:p></o:p></p>

<p>Here is the query :<o:p></o:p></p>

<p> <o:p></o:p></p>

<p>SELECT subQ.id, subQ.feattyp, subQ.frc, subQ.shieldnum, subQ.name, null,
(st_dump(merged_geom)).geom AS the_geom<o:p></o:p></p>

<p> <o:p></o:p></p>

<p>FROM (<o:p></o:p></p>

<p> <o:p></o:p></p>

<p>               
SELECT MAX(id) AS id, feattyp, frc, MAX(shieldnum) AS shieldnum, nw.name,
ST_LineMerge(ST_Collect(the_geom)) AS merged_geom<o:p></o:p></p>

<p> <o:p></o:p></p>

<p>               
FROM nw<o:p></o:p></p>

<p> <o:p></o:p></p>

<p>               
WHERE nw.frc >= 0<o:p></o:p></p>

<p> <o:p></o:p></p>

<p>               
GROUP BY nw.name, nw.feattyp, nw.frc<o:p></o:p></p>

<p> <o:p></o:p></p>

<p>) AS subQ;<o:p></o:p></p>

<p> <o:p></o:p></p>

<p> <o:p></o:p></p>

<p> <o:p></o:p></p>

<p>This has worked fine on smaller shapes  but on this one I get an out of
memory error.<o:p></o:p></p>

<p> <o:p></o:p></p>

<p> <o:p></o:p></p>

<p> <o:p></o:p></p>

<p>I used pgTune to change database default settings and the result is as
follow :<o:p></o:p></p>

<p> <o:p></o:p></p>

<p> <o:p></o:p></p>

<p> <o:p></o:p></p>

<p>#custom_variable_classes =
''                  
# list of custom variable class names<o:p></o:p></p>

<p> <o:p></o:p></p>

<p>default_statistics_target = 50 # pgtune wizard 2010-01-13<o:p></o:p></p>

<p> <o:p></o:p></p>

<p>maintenance_work_mem = 120MB # pgtune wizard 2010-01-13<o:p></o:p></p>

<p> <o:p></o:p></p>

<p>constraint_exclusion = on # pgtune wizard 2010-01-13<o:p></o:p></p>

<p> <o:p></o:p></p>

<p>effective_cache_size = 1408MB # pgtune wizard 2010-01-13<o:p></o:p></p>

<p> <o:p></o:p></p>

<p>work_mem = 12MB # pgtune wizard 2010-01-13<o:p></o:p></p>

<p> <o:p></o:p></p>

<p>wal_buffers = 8MB # pgtune wizard 2010-01-13<o:p></o:p></p>

<p> <o:p></o:p></p>

<p>checkpoint_segments = 16 # pgtune wizard 2010-01-13<o:p></o:p></p>

<p> <o:p></o:p></p>

<p>shared_buffers = 480MB # pgtune wizard 2010-01-13<o:p></o:p></p>

<p> <o:p></o:p></p>

<p>max_connections = 80 # pgtune wizard 2010-01-13<o:p></o:p></p>

<p> <o:p></o:p></p>

<p> <o:p></o:p></p>

<p> <o:p></o:p></p>

<p>All the other parameters have their default values.<o:p></o:p></p>

<p> <o:p></o:p></p>

<p> <o:p></o:p></p>

<p> <o:p></o:p></p>

<p>What can I do to run my script through this heavy shape files ?<o:p></o:p></p>

<p> <o:p></o:p></p>

<p> <o:p></o:p></p>

<p> <o:p></o:p></p>

<p>Thank you<o:p></o:p></p>

<p> <o:p></o:p></p>

<p> <o:p></o:p></p>

<p> <o:p></o:p></p>

<p>Nicolas.<o:p></o:p></p>

<p> <o:p></o:p></p>

</div>

</body>

</html>