Loading OSM Data into GeoNode¶
In this section, we will walk through the steps necessary to load OSM data into your GeoNode project. As discussed in previous sections, your GeoNode already uses OSM tiles from MapQuest and the main OSM servers as some of the available base layers. This session is specifically about extracting actual data from OSM and converting it for use in your project and potentially for Geoprocessing tasks.
The first step in this process is to get the data from OSM. We will be using the OSM Overpass API since it lets us do more complex queries than the OSM API itself. You should refer to the OSM Overpass API documentation to learn about all of its features. It is an extremely powerful API that lets you extract data from OSM using a very sophisticated API.
- http://wiki.openstreetmap.org/wiki/Overpass_API
- http://wiki.openstreetmap.org/wiki/Overpass_API/Language_Guide
In this example, we will see a couple of examples extracting:
- Southwest Platte River Road footprint, which runs through Denver
- Building footprint data around Kampala, Uganda.
To do this we will use an interactive tool that makes it easy construct a Query against the Overpass API.
Exporting OSM data to shapefile using QGIS¶
First go to openstreetmap.org, and search for “South Platte River, Denver”
Zoom in, until you see the features appearing
Select a feature. In this example we selected Way: Southwest Platte River Road (17082695)
Identify the tags and values of the features you’re after by
- Zooming all the way into the map
- Click on the layers icon on the right (the three sheets of paper)
- Click on the last menu entry (
Map data
or something similar in your language) - The features on the map turn blue (make sure you’re zoomed in far enough to see
- Click on the feature you’re after
- The Tags and Values appear on left side of the screen, and you can proceed below…
Southwest Platte River Road - Details
Point your browser at overpass-turbo.eu, and use the search box to zoom to the area of interest, in this case Colorado
Click on the
Wizard
button, and enter the search text accordingly to the information retrieved from OpenStreetMapClick on the button
Build and Run Query
, the map shows the selected dataClick on the button
Export
, and download data asGeoJSON
Save it and confirm. The file
export.geojson
will be created into theDownloads
folderRename the file to
south_platte_river_road.geojson
Open QGis Client and import the layer into it
Click with the right button over the layer and then click on
Save As
Select
ESRI Shapefile
and click onBrowse
Select the
Downloads
folder and name the filesouth_platte_river_road
This will save the layer as a Shapefile, which can be easily imported into GeoNode
Let’s see another example of export through the OverPass APIs.
Point your browser at overpass-turbo.eu, and use the search box to zoom to the area of interest, in this case Kampala
Zoom around Nakasero area
Select the desired Bounding Box around the area to export
Run the
Wizard
and writebuilding=* or highway=* in bbox
on the text box.Nakasero Query Builder
This will result in a query like the following one
/* This has been generated by the overpass-turbo wizard. The original search was: “building=* or highway=* in bbox” */ [out:json][timeout:25]; // gather results ( // query part for: “building=*” node["building"]({{bbox}}); way["building"]({{bbox}}); relation["building"]({{bbox}}); // query part for: “highway=*” node["highway"]({{bbox}}); way["highway"]({{bbox}}); relation["highway"]({{bbox}}); ); // print results out body; >; out skel qt;
Export data as
GeoJSON
like before, rename it and use QGis to export as a ShapefileThis will allow you to save all the layers as a Shapefiles, which can be easily imported into GeoNode
Note
You can also rename the file in your Operating Systems File management tool (Windows Explorer, Finder etc).
Note
You may want to switch to an imagery layer in order to more easily see the buildings on the OSM background.
Exporting OSM data to shapefile using GDAL¶
An alternative way to export the .osm
or .geojson
file to a shapefile is to use ogr2ogr combined with the GDAL osm driver, available from GDAL version 1.10.
As a first step, inspect how the GDAL osm driver sees the .osm file using the ogrinfo command:
$ ogrinfo -al -so nakasero.geojson -where "OGR_GEOMETRY='Point'"
INFO: Open of `nakasero.geojson'
using driver `GeoJSON' successful.
Layer name: OGRGeoJSON
Geometry: Unknown (any)
Feature Count: 142
Extent: (32.573864, 0.312602) - (32.593496, 0.331627)
Layer SRS WKT:
GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563,
AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],
PRIMEM["Greenwich",0,
AUTHORITY["EPSG","8901"]],
UNIT["degree",0.0174532925199433,
AUTHORITY["EPSG","9122"]],
AUTHORITY["EPSG","4326"]]
id: String (0.0)
...
$ ogrinfo -al -so nakasero.geojson -where "OGR_GEOMETRY='LineString'"
INFO: Open of `nakasero.geojson'
using driver `GeoJSON' successful.
Layer name: OGRGeoJSON
Geometry: Unknown (any)
Feature Count: 928
Extent: (32.571923, 0.306984) - (32.597590, 0.338549)
Layer SRS WKT:
GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563,
AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],
PRIMEM["Greenwich",0,
AUTHORITY["EPSG","8901"]],
UNIT["degree",0.0174532925199433,
AUTHORITY["EPSG","9122"]],
AUTHORITY["EPSG","4326"]]
id: String (0.0)
...
$ ogrinfo -al -so nakasero.geojson -where "OGR_GEOMETRY='Polygon'"
INFO: Open of `nakasero.geojson'
using driver `GeoJSON' successful.
Layer name: OGRGeoJSON
Geometry: Unknown (any)
Feature Count: 2596
Extent: (32.572918, 0.311164) - (32.594049, 0.333597)
Layer SRS WKT:
GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563,
AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],
PRIMEM["Greenwich",0,
AUTHORITY["EPSG","8901"]],
UNIT["degree",0.0174532925199433,
AUTHORITY["EPSG","9122"]],
AUTHORITY["EPSG","4326"]]
id: String (0.0)
...
$ ogrinfo -al -so nakasero.geojson -where "OGR_GEOMETRY='MultiPolygon'"
INFO: Open of `nakasero.geojson'
using driver `GeoJSON' successful.
Layer name: OGRGeoJSON
Geometry: Unknown (any)
Feature Count: 3
Extent: (32.576421, 0.315224) - (32.590876, 0.330137)
Layer SRS WKT:
GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84",6378137,298.257223563,
AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],
PRIMEM["Greenwich",0,
AUTHORITY["EPSG","8901"]],
UNIT["degree",0.0174532925199433,
AUTHORITY["EPSG","9122"]],
AUTHORITY["EPSG","4326"]]
id: String (0.0)
...
ogrinfo has detected 4 different geometric layers inside the osm data source. As we are just interested in the buildings, you will just export to a new shapefile the polygons and multipolygons layer using the GDAL ogr2ogr command utility:
$ ogr2ogr nakasero_buildings nakasero.geojson -where "OGR_GEOMETRY='Polygon' or OGR_GEOMETRY='MultiPolygon'" -nln nakasero_buildings
Now you can upload the shapefile to GeoNode using the GeoNode Upload form in the same manner as you did in the previous section.