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.

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

  1. First go to openstreetmap.org, and search for “South Platte River, Denver”

    Search on OpenStreetMap

    Search on OpenStreetMap

  2. Zoom in, until you see the features appearing

    Features on OpenStreetMap

    Features on OpenStreetMap

  3. Select a feature. In this example we selected Way: Southwest Platte River Road (17082695)

    Southwest Platte River Road

    Southwest Platte River Road

  4. 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

    Southwest Platte River Road - Details

  5. Point your browser at overpass-turbo.eu, and use the search box to zoom to the area of interest, in this case Colorado

    Colorado

    Colorado

  6. Click on the Wizard button, and enter the search text accordingly to the information retrieved from OpenStreetMap

    Southwest Platte River Road

    Southwest Platte River Road

    name="Southwest Platte River Road" and highway=tertiary and railway=abandoned
    
  7. Click on the button Build and Run Query, the map shows the selected data

    Southwest Platte River Road Data

    Southwest Platte River Road Data

  8. Click on the button Export, and download data as GeoJSON

    Southwest Platte River Road Export

    Southwest Platte River Road Export

  9. Save it and confirm. The file export.geojson will be created into the Downloads folder

    export.geojson

    export.geojson

  10. Rename the file to south_platte_river_road.geojson

    south_platte_river_road.geojson

    south_platte_river_road.geojson

  11. Open QGis Client and import the layer into it

    QGis Client

    QGis Client

  12. Click with the right button over the layer and then click on Save As

    QGis Client - Save As

    QGis Client - Save As

  13. Select ESRI Shapefile and click on Browse

    QGis Client - Save As SHP

    QGis Client - Save As SHP

  14. Select the Downloads folder and name the file south_platte_river_road

    QGis Client - Save As SHP

    QGis Client - Save As SHP

  15. This will save the layer as a Shapefile, which can be easily imported into GeoNode

    South Platte River Road into GeoNode

    South Platte River Road into GeoNode

Let’s see another example of export through the OverPass APIs.

  1. Point your browser at overpass-turbo.eu, and use the search box to zoom to the area of interest, in this case Kampala

    Kampala

    Kampala

  2. Zoom around Nakasero area

    Nakasero

    Nakasero

  3. Select the desired Bounding Box around the area to export

    Nakasero BBOX Nakasero BBOX

    Nakasero BBOX

  4. Run the Wizard and write building=* or highway=* in bbox on the text box.

    Nakasero Query Builder

    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;
    
  5. Export data as GeoJSON like before, rename it and use QGis to export as a Shapefile

    Nakasero Query Builder

    Nakasero Query Builder

  6. This will allow you to save all the layers as a Shapefiles, which can be easily imported into GeoNode

    Nakasero into GeoNode

    Nakasero 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.