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

Defining the map layers


We know that we want to have a total of five map layers in our application. The basemap layer will display the basemap.tif file we just downloaded, while the track layer will use a SpatiaLite database to store and display the track data entered by the user. The remaining map layers will display temporary features held in memory.

Let's start by defining a new method in our forestTrails.py module to initialize the SpatiaLite database we will use for the track layer:

    def setupDatabase(self):
        cur_dir = os.path.dirname(os.path.realpath(__file__))
        dbName = os.path.join(cur_dir, "data", "tracks.sqlite")
        if not os.path.exists(dbName):
            fields = QgsFields()
            fields.append(QgsField("id", QVariant.Int))
            fields.append(QgsField("type", QVariant.String))
            fields.append(QgsField("name", QVariant.String))
            fields.append(QgsField("direction", QVariant.String))
            fields.append(QgsField("status...