Book Image

Building Mapping Applications with QGIS

By : Erik Westra
Book Image

Building Mapping Applications with QGIS

By: Erik Westra

Overview of this book

Table of Contents (16 chapters)
Building Mapping Applications with QGIS
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Free Chapter
1
Getting Started with QGIS
Index

Using memory-based layers


While a map layer would normally display geospatial data taken from an external data source such as a shapefile, a raster DEM file, or a database, it is also possible to create geospatial features directly from your Python code. For example, imagine that you write a program to display the halfway point along a road. This halfway point could be represented as a QgsPoint geometry, which would be displayed on the map using an appropriate marker symbol. Since you are calculating the point, this isn't a feature you would want to store in a shapefile or database. Rather, the feature is calculated and displayed when your program is run.

This is an ideal application for a memory-based layer. This type of layer stores geospatial features in memory, allowing you to create new features on the fly and display them within a map layer.

To create a memory-based map layer, instantiate a new QgsVectorLayer object, just like normal. The initializer for this class looks like the following...