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
About the Author
About the Reviewers

Adding a layer to

Cloud services have become common and geospatial maps are no exception. This recipe uses a service named, which serves vector layers online, which you can upload from QGIS using Python.

Getting ready

For this recipe, you will need to install the qgisio plugin using the QGIS Plugin Manager.

You will also need a shapefile in a geodetic coordinate system (WGS84) from

Decompress the ZIP file and place it in your qgis_data directory named shapes.

How to do it...

We will convert our shapefile to GeoJSON using a temporary file. We'll then use Python to call the qgisio plugin in order to upload the data to be displayed online. To do this, we need to perform the following steps:

  1. First, we need to import all the relevant Python libraries:

    from PyQt4.QtCore import *
    from PyQt4.QtGui import *
    from qgis.core import *
    from tempfile import mkstemp
    import os
    from qgisio import geojsonio
  2. Now, we set up the layer and get...