GeoServer and OpenStreetMap

OpenStreetMap is a free and editable map of the world. Founded in 2004 in the United Kingdom in response to the need for a free geospatial data source, it is a community-driven project, allowing for anyone to edit and contribute information. It has since grown to include data from almost all countries in the world. The map generated from their data can be used as an alternative to commercial map layers such as those found in Google Maps. The OpenStreetMap base layer is rendered using Mapnik, however since the data is free to download and distribute, it is possible to serve it using GeoServer. I recently went through the process of rendering OpenStreetMap’s data with GeoServer.

The data

OpenStreetMap provides instructions on downloading their data. The full data set is a large file, currently about 4GB when compressed and about 100GB when uncompressed. (You can download sections of the data set as well.) This data is an XML-based data format that GeoServer cannot read natively. PostGIS is the optimal way of storing such a large volume of data when using GeoServer. Luckily, there is a converter that allows you to load the OpenStreetMap data into PostGIS called osm2pgsql. This program is a package available on Debian-based distributions (such as Ubuntu), and is also available as a binary on Windows.

Run the following command:

osm2psql -E 900913 -d osm planet.osm

This will process the XML information and load the data into a PostGIS database called “osm”. The -E defines the projection of the source data, which in this case is 900913, the projection used in Google Maps, and the default for OpenStreetMap.

If successful, the database will contain the following tables:

planet_osm_line
planet_osm_point
planet_osm_polygon
planet_osm_roads

Making sense of the data

OpenStreetMap’s data can be a bit confusing. For a first time user like myself, just trying to figure out their naming convention was challenging. They do, however, have a wonderful map key hidden away in their wiki. This page is a lifesaver.

There are two different tables that contain line data, planet_osm_line and planet_osm_roads. The former includes railroads, subways, and other linear information. The latter is made up exclusively of roads. The planet_osm_point table has a range of data: subway stations, shopping centers, universities, and even brothels. Lastly the planet_osm_polygon table has, but is not limited to, parks, bodies of water, and even buildings in certain urban areas.

Styling

On my map I grouped the roads into three major groups; residential, secondary, and limited-access (highways). To achieve this grouping I used the following SLD filters.

Road class

PropertyName

Values

Residential

highway

residential OR unclassified

Secondary

highway

primary OR secondary

Limited-access

highway

motorway OR trunk

I then styled the map to distinctly display the three groups of roads, and also varied their widths depending on the zoom level. This was the most time-consuming part of the process, as I needed to create and evaluate styles for each zoom level. The final SLD is very large, but is available for those interested.

Final touches

Since the purpose of this map was to create a viable base layer that anyone can incorporate into their mapping projects, performance was a concern. To address this, I used GeoWebCache, a tile cache mechanism built into GeoServer. The GeoWebCache documentation has details on this process.

Feel free to link to this map. Use this OpenLayers code to get started. This map is a work in progress. Future enhancements will include adding public transportation systems, railroads, buildings, and more. If you have any feedback on this map please email me at iwillig at opengeo dot org.

With GeoServer, PostGIS, OpenLayers and the OpenStreetMap data set, it is possible to build high-quality, professional-looking maps, allowing you to take control of what data you present, define your own mapping aesthetic, and free yourself from having to use commercial map layers.

I really need your help. I’ve been learning Geoserver for a while now and i already know how to use it to an extent but i seem to be hanging. I don’t understand how to move further. I can’t create a complete webmap site yet. Please get back to me.

please i can not use the file with extension .osm
can you told me how to uncompress this file and if there is a program used to that send the link to my email .
than you
sorry my email (amir_1988_ghazaly@hotmail.com)

Nice tutorial, buth not tottaly complete. Please write somewhere, which table should be visualized? lines or roads? Probably result is the same, buth Iam not sure.

After importing all like described here, I have an offset of open street map layer. About 25 kilometers. What to do now? 😀 Iam just na gis beginer. Please kick me to right way. What to check? (data in postgre postgis db is in 900913, geoserver feature is reading automaticaly this srs, srid, or what it is. Projection to quantum gis is done in 4326 (gps, wgs84) and it doesnt fit any other wms data. Offset is realy big)

I’ve run into a snag with this, and I was wondering if you’ve noticed anything similar. The issue is that, on my map, regardless of what I put in the SLD, any ways that are marked with highway=residential are not displayed unless they also have admin_level=*. That is, GeoServer will not render any residential streets unless they are also administrative boundaries. Is this something you’ve noticed?

Found that my earlier issue was caused by using the planet_osm_roads table instead of the planet_osm_line table. It’s worth noting that osm2pgsql only adds major roads (highway=tertiary or higher) to the planet_osm_roads table. Lower classified roads are included only if the way also constitutes part of something else (such as an administrative boundary).

Thanks for the SLD Ivan. After a bit of playing around I was able to successfully get it working.

I have downloaded a shapefile of the OSM data from the Geofabrik website as suggested by Facundo above. I then imported this shapefile into a PostGIS database.

Initially when I loaded the SLD into Geoserver I received the same parsing error as Jovie above i.e.

org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element ‘Name’. One of ‘{”http://www.opengis.net/sld”:Symbolizer}’ is expected.

The issue was the location of the lines containing the and tags which I moved to after the tag in each instance. The lines beginning <VendorOption… also had to be moved to just before the tag in each instance.

I removed the section from the SLD relating to runways as these are not present in my OSM dataset and replaced all occurances of ‘highway’ with ‘type’ to reference the correct field name in the OSM roads database table that I have in PostGIS.

The SLD then successfully parsed and I was able to assign it to my OSM roads feature type in Geoserver. The SLD now symbolises my roads dataset according to the different zoom levels.

I would make my version of the SLD available but there is no attachment facility. Hopefully I have explained my amendments well enough for others to follow.

I downloaded the iwillig-openstreetmap-sld sld’s and I don’t know what feature to assign to the various styles and what order to layer the features.

First I assigned the osm_roads.sld and osm_roads1.sld styles from the default directory to the planet_osm_roads feature.

Then I replaced the osm_roads.sld and osm_roads1.sld styles with the global_roads.sld (Note: within this sld I had to do I a global replace of type with highway) from the bright directory and assigned to the planet_osm_roads feature.

The global_roads.sld style is definitely a brighter color compared to the default directory styles.

Since the bright directory styles look better than what is in the default directory what styles will these 5 bright styles replace within the default directory and what style will be assigned to what feature (planet_osm_line, planet_osm_point, planet_osm_polygon, planet_osm_roads)?

Summary: In addition to all the Bright styles what additional Default styles do I use and for each style what feature do I assign them.

Ivan Great Work!
Donna Mills, can you explain more detailed what you said about the expect?

org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element ‘Name’. One of ‘{”http://www.opengis.net/sld”:Symbolizer}’ is expected.

The issue was the location of the lines containing the and tags which I moved to after the tag in each instance. The lines beginning <VendorOption… also had to be moved to just before the tag in each instance.

I removed the section from the SLD relating to runways as these are not present in my OSM dataset and replaced all occurances of ‘highway’ with ‘type’ to reference the correct field name in the OSM roads database table that I have in PostGIS.

As Marcel says, osm2pgsql seems to have difficulty with the -E option, only it’s not limited to the Windows version. I’ve encountered a buffer overflow in the latest version on Ubuntu 10.4, and the when compiling latest copy from svn (think they’re both 0.66)

Removing the -E option from:
osm2psql -E 900913 -d osm planet.osm

to:
osm2pgsql -d osm planet.osm

seems to resolve the issue. There’s a missing ‘g’ in the osm2psql as well 😉

Yes, can someone please explain how to fix “org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element ‘Name’. One of ‘{”http://www.opengis.net/sld”:Symbolizer}’ is expected.” in more detail. I don’t understand Donna’s explanation. Move what where? What tags?
Please Help!
Thanks,
Matt

“As Marcel says, osm2pgsql seems to have difficulty with the -E option, only it’s not limited to the Windows version. I’ve encountered a buffer overflow in the latest version on Ubuntu 10.4, and the when compiling latest copy from svn (think they’re both 0.66)”

It seems to also be a problem on SLES11, so probably also in Redhat5 then too.