O'Reilly logo

Building Mapping Applications with QGIS by Erik Westra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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", ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required