【发布时间】:2018-03-18 16:26:17
【问题描述】:
我想编写一个脚本来提示用户输入 X 和 Y 坐标。这些坐标将为现有的形状文件添加一个点。另外,我应该使用哪个函数调用来获取这些坐标?
vectorLyr = QgsVectorLayer("D:/Projekty/qgis_projekt/forty922.shp", "Forty", "ogr")
vpr = vectorLyr.dataProvider()
x = QInputDialog.getDouble(None, 'input', 'Insert x: ')
y = QInputDialog.getDouble(None, 'input', 'Insert y: ')
pnt = QgsGeometry.fromPoint(QgsPoint(x,y))
f = QgsFeature()
f.setGeometry(pnt)
vpr.addFeatures([f])
vectorLyr.updateExtents()
QgsMapLayerRegistry.instance().addMapLayers([vectorLyr])
输入窗口工作正常,但 Python 控制台抛出此语句
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "c:/users/hubi/appdata/local/temp/tmpxkrjpx.py", line 5, in <module>
pnt = QgsGeometry.fromPoint(QgsPoint(x,y))
TypeError: arguments did not match any overloaded call:
QgsPoint(): too many arguments
QgsPoint(QgsPoint): argument 1 has unexpected type 'tuple'
QgsPoint(float, float): argument 1 has unexpected type 'tuple'
QgsPoint(QPointF): argument 1 has unexpected type 'tuple'
QgsPoint(QPoint): argument 1 has unexpected type 'tuple'
当我将常数添加到我的 pnt 变量时效果很好。
pnt = QgsGeometry.fromPoint(QgsPoint(361637,501172))
有什么想法吗?
【问题讨论】: