Exporting list of street names

Hi there,
I’m trying to get a list of all the streets in the US by name. I checked the geonames data dump and it didn’t appear to have any streets in the file, just lots of other types of places. Is there any way to export a list of streets from OSM in XML (or any format, really)?

Not off the shelf. You can get the whole world from: planet.osm that’s an xml you can filter that… Going to take you a while.

Or you can use OSMXAPI and request all highway=* ways. Going to take even longer I think.

Thanks for the response - any suggestions on how to filter the XML file? (I can’t actually view the structure because I downloaded just the Wyoming file and it was 830 MB, too big to open up directly…)

First I want to ask if you really just want to have a list of the names?

Second I’ll say I haven’t solved this for you but I can give you some experimenting that I did with XSL:s, these can extract names from XML pretty easily, but it might be slow on a 900MB file…

First rename the uncompressed Openstreetmap data file as “map.osm”, then open render.xml in a browser or as described in the Osmarender howto.
style.xsl

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable name="data" select="document('map.osm')"/>
<xsl:template match="/">
<html>
<h2>All Ways with names</h2>
<table><tr><th align="left">name</th><th>way id</th></tr>
<xsl:for-each select="$data/osm/way/tag[@k='name']">
<tr>
<td><xsl:value-of select="@v"/></td>
<td><xsl:value-of select="../@id"/></td>
</tr>
</xsl:for-each>
</table>
</html>
</xsl:template>
</xsl:stylesheet>

**
render.xml**

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="style.xsl"?>
<dummyworthlesstag/>

**
Misc examples**
All these examples require that you save the code as “style.xsl” and then a stylesheet xml tag to the osm file. like this:

<?xml-stylesheet type="text/xsl" href="style.xsl"?>

All ways that have a name, with way id:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/osm">
<html>
<h2>All ways with names</h2>
<table><tr><th align="left">name</th><th>way id</th></tr>
<xsl:for-each select="way/tag[@k='name']">
<tr>
<td><xsl:value-of select="@v"/></td>
<td><xsl:value-of select="../@id"/></td>
</tr>
</xsl:for-each>
</table>
</html>
</xsl:template>
</xsl:stylesheet>

All ways and all their tags

<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
  <html>
  <body>
    <h2>All the Ways and their tags.</h2>
    <table border="0">
    <tr bgcolor="#9acd32">
      <th align="left">way id</th>
      <th align="left">way tags</th>
    </tr>
    <xsl:for-each select="osm/way">
    <tr><td> <xsl:value-of select="@id"/> </td>    
    <td>
        <table border="1">
      <tr bgcolor="#9acd32">
            <th align="left">key</th>
            <th align="left">value</th>
          </tr>
          <xsl:for-each select="tag">
            <tr>
              <td><xsl:value-of select="@k"/></td>
              <td><xsl:value-of select="@v"/></td>
            </tr>
          </xsl:for-each>
    </table>
     </td></tr>
    </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>

All ways and names on the ones that have one

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
  <html>
  <body>
    <h2>All ways and names on the ones that have one</h2>
    <table border="0">
    <tr bgcolor="#9acd32">
      <th align="left">way id</th>
      <th align="left">name</th>
    </tr>
    <xsl:for-each select="osm/way">
    <tr><td> <xsl:value-of select="@id"/> </td>    
    <td>
        <xsl:for-each select="tag[@k='name']">
              <td><xsl:value-of select="@v"/></td>
          </xsl:for-each>
     </td></tr>
    </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>

Also it would be possible to extract a list from pgsql, import the data with osm2pgsql then this
psql gis
select name from planet_osm_line where name is not null;

Yes that is simpler, can you get a position or a bounding box for those ways that as well? But actually it would be possible from XAPI as well. Just do a [name=*] in the download parameter.

Hmm…I tried both methods above, but render.xml just rendered completely blank, and I can’t seem to get PostgreSQL up and running to use osm2pgsql without an error. Are there any other methods you guys know of to get this data into a usable format?

What error do you get from PostGIS? I think that getting data into PostGIS could be very good alternative for you. Not only could you select all names of the highways (select name from planet_osm_line where name is not null and highway is not null), but you could also sort the results by places (is_in), highway classes etc.

I used ubuntu 8.04, installed postgres 8.3 with postgis extensions installed (which I had to do add in a config). After some trial and error it worked… :slight_smile: So if you post us the error messages, I’m sure someone can helpt you.

Unfortunately, I’m running all this on windows, which seems to lack documentation. In pgAdmin I can see that I have a running server on localhost, with the postgis database properly configured. The error I get is:

“Using projection SRS 3395
Setting up table: planet_osm_point
Connection to database failed: fe_sendauth: no password supplied”

I have a pgpass.conf file set up, which, from the few posts I could find about this problem, is supposed to solve it, but it doesn’t. As far as I can tell, there’s no way to set the password in flags for osm2pgsql. Any ideas?

according to this page http://manpages.ubuntu.com/manpages/intrepid/man1/osm2pgsql.html -W should force a password prompt.

Hi,

It is in the server settings, in file pg_hba.conf. That must be set to use method “trust”. Windows version on osm2pgsql does not give any way to give username and password. Therefore you must create a user with the same name as you are logged in to Windows, and set database so that it does not ask password at all. This same information is in http://wiki.openstreetmap.org/index.php/User_talk:JRA.

I believe that nobody is going to update or improve osm2pgsql.exe for us Windows users without getting paid for it. I am ready to invest some money for the development. I fear that after new API 0.6 comes I will be without PostGIS updates.

I can only find one ticket in trac concerning Windows. So: Identify the problems, and possible solutions and people might help you out.