QgsNMEAConnection的参数

时间:2016-04-04 12:02:22

标签: 3d gps qgis

我正在尝试编写一些快速而讨厌的代码来将高程写入3D点shapefile的几何体。其他人已经注意到GPS信息面板功能中缺少此功能。但是,我找不到用于QgsNMEAConnection通过串口连接到GPS的参数列表,例如COM7。有人可以帮助我这个功能,我可以看到它应该有一个'主机'和'端口',但无法弄清楚其他参数。以下是该功能的概述。不要太苛刻我是QGIS和python的新手。另一件事我不能做的是在添加新点后打开属性弹出表。

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])

1 个答案:

答案 0 :(得分:1)

感谢以下帖子: https://gis.stackexchange.com/questions/188002/connect-disconnect-gps-device-via-pyqgis

我已经能够重新编写代码了,所以我知道这个想法会有效。我现在可以通过更强大的代码开始改进它。有人知道如何在添加新功能后使用python打开属性编辑器弹出窗口吗?这是将3D几何图形添加到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()