Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # just the standard initialization
- #
- from qgis.core import QgsApplication, QgsFeature, QgsGeometry
- from qgis.core import QgsMapLayerRegistry, QgsProject
- from PyQt4.QtGui import QApplication
- from PyQt4.QtCore import QFileInfo
- app = QApplication([])
- QgsApplication.setPrefixPath("/usr", True)
- QgsApplication.initQgis()
- project = QgsProject.instance()
- project.read(QFileInfo('/home/mario/Documents/GIS/heliconiaBB.qgs'))
- # import normal distribution from 'random'
- #
- from random import gauss
- # all layers are in WGS 84, or I want the code to be independent from the
- # layer coordinates reference system
- # the points in my virtual reality
- reality = QgsMapLayerRegistry.instance().mapLayersByName("points")[0]
- # the points as measured by my virtual GPS machine, to be simulated here
- gps_readings = QgsMapLayerRegistry.instance().mapLayersByName("gps")[0]
- # the two layers have the same fields set, including 'code'
- fields = reality.fields()
- gps_readings.startEditing()
- pr = gps_readings.dataProvider()
- for feat in reality.getFeatures():
- dx = gauss(0.0, 3.0)
- dy = gauss(0.0, 3.0)
- # the following line is just pseudo-code
- fake_gps_reading = feat.geometry().asPoint() + (dx, dy)
- new_feat = QgsFeature(fields)
- new_feat['code'] = feat['code']
- new_feat.setGeometry(QgsGeometry.fromPoint(fake_gps_reading))
- pr.addFeatures( [ new_feat ] )
- gps_readings.commitChanges()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement