Adding a layer to geojson.io
Cloud services have become common and geospatial maps are no exception. This recipe uses a service named geojson.io, 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 https://geospatialpython.googlecode.com/svn/union.zip.
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:
- 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
- Now, we set up the layer...