<html>
<head>
        <title></title>
        
<meta name="GENERATOR" content="MSHTML 8.00.6001.18854"></meta>
</head>

<body>
        
<div align="left">Great</div>
        
<div align="left"> </div>
        
<div align="left">I have several different versions but I think the one I sent is the one best working. I have tried it on a big table and as far as I recall this version does it right.</div>
        
<div align="left"> </div>
        
<div align="left">I forgot to mention:</div>
        
<div align="left">I see that I have used both CTE and window function</div>
        
<div align="left">So you will need PostgreSQL 8.4 to get it working</div>
        
<div align="left"> </div>
        
<div align="left">/Nicklas</div>
        
<div align="left"> </div>
        
<div align="left"><br />
                2010-01-15 Nicolas Gillet - MARKET-IP wrote:<br />
                <br />
                ></div>
        
<p><span style="FONT-FAMILY: Calibri, 'sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt">Hello,</span></p>
        
<p> </p>
        
<p><span style="FONT-FAMILY: Calibri, 'sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
        
<p> </p>
        
<p><span style="FONT-FAMILY: Calibri, 'sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt">Thank you for this input.</span></p>
        
<p> </p>
        
<p><span style="FONT-FAMILY: Calibri, 'sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
        
<p> </p>
        
<p><span style="FONT-FAMILY: Calibri, 'sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt">At a first glance I did not understand it fully but Ill take time to go deeper.</span></p>
        
<p> </p>
        
<p><span style="FONT-FAMILY: Calibri, 'sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
        
<p> </p>
        
<p><span style="FONT-FAMILY: Calibri, 'sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt">Indeed a tutorial might be useful for several users as I think merging road elements is a redundant issue for GIS users.</span></p>
        
<p> </p>
        
<p><span style="FONT-FAMILY: Calibri, 'sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
        
<p> </p>
        
<p><span style="FONT-FAMILY: Calibri, 'sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt">Nicolas.</span></p>
        
<p> </p>
        
<p><span style="FONT-FAMILY: Calibri, 'sans-serif'; COLOR: #1f497d; FONT-SIZE: 11pt"> </span></p>
        
<p> </p>
        
<div>></div>
        
<div>>
                
<div>
                        
<p><b><span style="FONT-FAMILY: Tahoma, 'sans-serif'; FONT-SIZE: 10pt">De :</span></b><span style="FONT-FAMILY: Tahoma, 'sans-serif'; FONT-SIZE: 10pt"> 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</span></p>
                        
<p> </p></div></div>
        
<p> </p>
        
<p> </p>
        
<p>Hallo </p>
        
<p> </p>
        
<p> </p>
        
<p> </p>
        
<p> </p>
        
<p> </p>
        
<p>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.</p>
        
<p> </p>
        
<p> </p>
        
<p> </p>
        
<p>So, no guarantees :-)</p>
        
<p> </p>
        
<p> </p>
        
<p> </p>
        
<p>/Nicklas<br />
                ><br />
                > 2010-01-14 Nicolas Gillet - MARKET-IP wrote:<br />
                ><br />
                > ></p>
        
<p> </p>
        
<p>Hello,</p>
        
<p> </p>
        
<p>I have a big shape file to process (about 300 Mo,  1.5 million records)</p>
        
<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.</p>
        
<p> </p>
        
<p>Here is the query :</p>
        
<p> </p>
        
<p>SELECT subQ.id, subQ.feattyp, subQ.frc, subQ.shieldnum, subQ.name, null, (st_dump(merged_geom)).geom AS the_geom</p>
        
<p> </p>
        
<p>FROM (</p>
        
<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</p>
        
<p> </p>
        
<p>                FROM nw</p>
        
<p> </p>
        
<p>                WHERE nw.frc >= 0</p>
        
<p> </p>
        
<p>                GROUP BY nw.name, nw.feattyp, nw.frc</p>
        
<p> </p>
        
<p>) AS subQ;</p>
        
<p> </p>
        
<p>This has worked fine on smaller shapes  but on this one I get an out of memory error.</p>
        
<p> </p>
        
<p>I used pgTune to change database default settings and the result is as follow :</p>
        
<p> </p>
        
<p>#custom_variable_classes = ''                   # list of custom variable class names</p>
        
<p> </p>
        
<p>default_statistics_target = 50 # pgtune wizard 2010-01-13</p>
        
<p> </p>
        
<p>maintenance_work_mem = 120MB # pgtune wizard 2010-01-13</p>
        
<p> </p>
        
<p>constraint_exclusion = on # pgtune wizard 2010-01-13</p>
        
<p> </p>
        
<p>effective_cache_size = 1408MB # pgtune wizard 2010-01-13</p>
        
<p> </p>
        
<p>work_mem = 12MB # pgtune wizard 2010-01-13</p>
        
<p> </p>
        
<p>wal_buffers = 8MB # pgtune wizard 2010-01-13</p>
        
<p> </p>
        
<p>checkpoint_segments = 16 # pgtune wizard 2010-01-13</p>
        
<p> </p>
        
<p>shared_buffers = 480MB # pgtune wizard 2010-01-13</p>
        
<p> </p>
        
<p>max_connections = 80 # pgtune wizard 2010-01-13</p>
        
<p> </p>
        
<p>All the other parameters have their default values.</p>
        
<p> </p>
        
<p>What can I do to run my script through this heavy shape files ?</p>
        
<p> </p>
        
<p>Thank you</p>
        
<p> </p>
        
<p>Nicolas.</p>
        
<p> </p>
</body>
</html>