This plug in for QGIS is meant to be a demonstrator. It is designed to be easily extensible and adaptable. Therefore the plug-in is split in three main parts:
The imaerread module reads IMAER gml and passes its features. The module can be imported and used stand alone. Therefore it provides a basis for extending GIS (or other) software with the capability to read AERIUS IMAER output.
The module has no dependencies outside of the Python core libraries.
Reading IMAER gml from python by using the imaerread module is simple:
Start by importing the module:
import imaerread
Create a reader object by providing a filename:
ir = ImaerRead(gmlFile = 'filename.gml')
The gml file contains an unknown number of ReceptorPoint features. The nextFeature() function finds the next, parses it and returns an imaer feature object:
ft = ir.nextFeature()
It uses the pulldom parser from the standard xml library, because the gml files can be too large to fit in memory.
The features that are returned are python dictionaries with this structure:
{
u'id': u'3204036',
u'DEP_NH3': 0.0502,
u'DEP_NOX': 0.0123,
u'DEP_NO2': 0.0456,
u'DEP_PM10': 0.6783,
u'DEP_PM25': 0.354,
u'CON_NH3': 0.0789,
u'CON_NOX': 0.0234,
u'CON_NO2': 0.0567,
u'CON_PM10': 0.0678,
u'CON_PM25': 0.0345,
u'point': u'POINT(148871.0 409361.0)',
u'hexagon': u'POLYGON((148902.0 409415.0,148933.0 409361.0,148902.0 409307.0,148840.0 409307.0,148809.0 409361.0,148840.0 409415.0,148902.0 409415.0))',
u'progress': 0.54321
}
For efficiency, you can parse the parameters doPoints=False or doHexagons=False to prevent processing geometry you do not need. The returning object lacks the point or hexagon information.
Both point and and hexagon are returned in well known text (WKT) format to be parsed in most GIS libraries.
The ‘progress’ indicates is a float value between 0 and 1 and indicates how much of the file has been read. It could be used to show a progress bar or estimate the time left for importing all data.
The ImaerWriter module has a standard QGIS plug-in setup. The basics were generated using the QGIS plugin builder plugin.
The GUI was created with Qt4 Designer.
Source code can be found on github. Any issues can also be reported there. There are also some demo files available.
Iterates over the features in the featurecollection, creates QGIS features from them and adds those to the layer. This is done in a worker object that runs in a different thread to avoid freezing QGIS during reading. Note that reading large gml files can take up several minutes.
The worker object is created and started from imaer_reader_dialog.py, that also draws the progress bar and other user interaction like info enad error messages.