I had the same problem.  I ended up using the Quantum GIS function, Sum Line Lengths.  Input can be your postgis line features.  It adds up the lengths of the portion of each line that crosses a particular grid cell.  You need to create a polygon fishnet matching your raster extent and resolution first, then convert to raster.  This might actually be a better measure of density then counting lines.  <div>
<br clear="all"><div><div>- John</div><div><br></div><div><br></div><div>John Callahan</div><div>Research Scientist</div><div>Delaware Geological Survey</div><div>University of Delaware<br><a href="http://www.dgs.udel.edu" target="_blank">http://www.dgs.udel.edu</a><br>
<div><a href="mailto:john.callahan@udel.edu" target="_blank">john.callahan@udel.edu</a> </div><br></div></div>
<br><br><div class="gmail_quote">On Sat, Dec 22, 2012 at 9:57 PM, Jeff Adams - NOAA Affiliate <span dir="ltr"><<a href="mailto:jeff.adams@noaa.gov" target="_blank">jeff.adams@noaa.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Thanks for the response Stephen.I will have upwards of 150,000 lines features that I will want to feed into the density. These are stored in a single table (actually will be in a CTE), and many of the lines will overlap one another. It is hard to say whether these solutions are viable as I am having a hard time visualizing the SQL. You would think that I am not the first person who has wanted to do this in PostGIS, but I haven't found example one. <br>
<div class="HOEnZb"><div class="h5">
<br><div class="gmail_quote">On Sat, Dec 22, 2012 at 6:02 PM, Stephen Woodbridge <span dir="ltr"><<a href="mailto:woodbri@swoodbridge.com" target="_blank">woodbri@swoodbridge.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div><div>On 12/22/2012 3:07 PM, Jeff Adams - NOAA Affiliate wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi,<br>
<br>
I was wondering if anybody knew of a way to create a very simple line<br>
density raster. I am not interested in interpolation or clustering,<br>
simply how many line features pass through each pixel in the raster. I<br>
know how to do this with points, but am having difficulty figuring out<br>
how to do it with lines. Any help would be greatly appreciated...<br>
</blockquote>
<br></div></div>
Separate from the SQL, you probably need to have a strategy for doing this. so with a point I assume you just increment the point in the raster for each point. So with a line we want to increment the all the raster points along the line. Some options:<br>


<br>
1. render the line into an empty raster then add that raster to your master raster. Where add will increment by one every set  raster point in the rendered line.<br>
<br>
2. segmentize the line into segments that are the size of a pixel in your master raster and then add the midpoints of those segments to your master raster.<br>
<br>
Would one of these work for you?<br>
<br>
-Steve<br>
<br>
______________________________<u></u>_________________<br>
postgis-users mailing list<br>
<a href="mailto:postgis-users@lists.osgeo.org" target="_blank">postgis-users@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users" target="_blank">http://lists.osgeo.org/cgi-<u></u>bin/mailman/listinfo/postgis-<u></u>users</a><br>
</blockquote></div><br><br clear="all"><br></div></div><span class="HOEnZb"><font color="#888888">-- <br>Jeffrey D. Adams<br>Contractor<br>OAI, Inc.<br>In support of:<br>National Marine Fisheries Service<br>Office of Protected Resources<br>
1315 East West Hwy, Building SSMC3<br>
Silver Spring, MD 20910-3282<br>phone: <a href="tel:%28301%29%20427-8434" value="+13014278434" target="_blank">(301) 427-8434</a><br>fax: <a href="tel:%28301%29%20713-0376" value="+13017130376" target="_blank">(301) 713-0376</a>
</font></span><br>_______________________________________________<br>
postgis-users mailing list<br>
<a href="mailto:postgis-users@lists.osgeo.org">postgis-users@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users" target="_blank">http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users</a><br>
<br></blockquote></div><br></div>