Graphics Reference
In-Depth Information
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 re-
maining 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",
QVariant.String))
crs = QgsCoordinateReferenceSystem(4326,
QgsCoordinateReferenceSystem.EpsgCrsId)
writer = QgsVectorFileWriter(dbName, 'utf-8',
fields,
QGis.WKBLineString,
crs, 'SQLite',
["SPATIALITE=YES"])
if writer.hasError() !=
QgsVectorFileWriter.NoError:
print "Error creating tracks database!"
Search WWH ::




Custom Search