2016-04-04 11 views
2

Ich versuche, einen schnellen und widerlichen Code zu schreiben, um Erhebungen in die Geometrie eines 3D-Punkt-Shapefiles zu schreiben. Andere haben bemerkt, dass diese Funktion in der GPS Information Panel Funktion fehlt. Ich kann jedoch keine Liste von Parametern finden, die für den QgsNMEAConnection verwendet werden können, um über die serielle Schnittstelle, z. B. COM7, eine Verbindung zu einem GPS herzustellen. Kann jemand mir diese Funktion helfen, kann ich sehen, dass es einen "Wirt" und "Hafen" haben sollte aber die anderen Parameter nicht herausfinden kann. Das Folgende ist ein Überblick über die Funktion. Sei nicht zu hart Ich bin neu in QGIS und Python. Eine andere Sache, die ich nicht tun kann, ist das Öffnen der Attribut-Popup-Tabelle, sobald ein neuer Punkt hinzugefügt wurde.Parameter für QgsNMEAConnection

layer = iface.activeLayer() 

# check the layer is a 3D point shapefile 
# check the layer is editable 

# the following line of code is WRONG. I need an example 
# of the connection parameters to a GPS to a serial port eg COM7 
c = QgsNMEAConnection(host="serial", port=7, "") 

i=c.currentGPSInformation() 

lat = i.latitude 
lon = i.longitude 
elv = i.elevation 
wkt = '%s %f %s %f %s %f %s' %('Point(', lat, ' ', lon, ' ' , elv, ')') 

feat = QgsFeature(layer.pendingFields()) 
feat.setGeometry(QgsGeometry.fromWkt(wkt)) 
(res, outFeats) = layer.dataProvider().addFeatures([feat]) 

Antwort

1

Dank des folgenden Beitrag: https://gis.stackexchange.com/questions/188002/connect-disconnect-gps-device-via-pyqgis

Ich habe in der Lage gewesen zu meinem Code neu zu schreiben, damit ich weiß, dass die Idee funktionieren wird. Ich kann jetzt anfangen, es mit robusterem Code zu verbessern. Weiß jemand, wie man das Attributeditor-Popup mit Python nach dem Hinzufügen eines neuen Features öffnet? Hier ist der aktualisierte Code zum Hinzufügen von 3D-Geometrie zu einem 3D-Shapefile.

# Connect to the GPS using the GPS Information Panel before running this code 
# Select a 3D shapefile to add data to 
# This code uses the connection from the GPS Info Panel and its data 

layer = iface.activeLayer() 

# check the layer is a 3D point shapefile 
# check the layer is editable 

connectionRegistry = QgsGPSConnectionRegistry().instance() 
connectionList = connectionRegistry.connectionList() 
GPSInfo = connectionList[0].currentGPSInformation() 

lat = GPSInfo.latitude 
lon = GPSInfo.longitude 
elv = GPSInfo.elevation 
wkt = '%s %f %s %f %s %f %s' %('Point(', lon, ' ', lat, ' ' , elv, ')') 

feat = QgsFeature(layer.pendingFields()) 
feat.setGeometry(QgsGeometry.fromWkt(wkt)) 
(res, outFeats) = layer.dataProvider().addFeatures([feat]) 
iface.mapCanvas().refresh()