Book Image

QGIS Python Programming Cookbook

Book Image

QGIS Python Programming Cookbook

Overview of this book

Table of Contents (16 chapters)
QGIS Python Programming Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Using OpenStreetMap's points of interest in QGIS


OpenStreetMap has an API called Overpass that lets you access OSM data dynamically. In this recipe, we'll add some OSM tourism points of interest to a map.

Getting ready

You will need to use the QGIS Plugin Manager to install the Quick OSM plugin.

You will also need to download the following shapefile and unzip it to your qgis_data/ms directory:

https://geospatialpython.googlecode.com/svn/MSCoast_geo.zip

How to do it...

We will load our base layer that defines the area of interest. Then, we'll use the Processing Toolbox to build a query for OSM, download the data, and add it to the map. To do this, we need to perform the following steps:

  1. First, we need to import the processing module:

    import processing
    
  2. Next, we need to load the base layer:

    lyr = QgsVectorLayer("/qgis_data/ms/MSCoast_geo.shp", "MS Coast", "ogr")
    
  3. Then, we'll need the layer's extents for the processing algorithms:

    ext = lyr.extent()
    w =  ext.xMinimum()
    s =  ext.yMinimum()
    e =  ext.xMaximum...