IndexError: list index out of range-QGIS



我尝试在qgis中制作插件,我有一个问题。下面是我的代码:

destination_layer =  QgsProject.instance().mapLayersByName('Destination')[0]
matrix =  QgsProject.instance().mapLayersByName('join')[0]
for f in matrix.getFeatures():
origin_expr = QgsExpression('Site Name={}'.format(f['Site Name']))
destination_expr = QgsExpression('Site Name={}'.format(f['Site Name_2']))
origin_feature = origin_layer.getFeatures(QgsFeatureRequest(origin_expr))
origin_coords =  [(f.geometry().asPoint().x(), f.geometry().asPoint().y())
for f in origin_feature]
destination_feature = destination_layer.getFeatures(QgsFeatureRequest(destination_expr))
destination_coords =  [(f.geometry().asPoint().x(), f.geometry().asPoint().y())
for f in destination_feature]
params = {
'INPUT':'NCR Road',
'START_POINT':'{},{}'.format(origin_coords[0][0], origin_coords[0][1]),
'END_POINT':'{},{}'.format(destination_coords[0][0], destination_coords[0][1]),
'STRATEGY':0,
'ENTRY_COST_CALCULATION_METHOD':0,
'DIRECTION_FIELD':'',
'VALUE_FORWARD':'',
'VALUE_BACKWARD':'',
'VALUE_BOTH':'',
'DEFAULT_DIRECTION':2,
'SPEED_FIELD':'',
'DEFAULT_SPEED':50,
'TOLERANCE':0,
'OUTPUT': 'Shortest Path Layer' }
print('Executing analysis')
processing.runAndLoadResults("qneat3:shortestpathpointtopoint", params) 
当我运行我的代码时,它显示了这个错误:
Traceback (most recent call last):
File "C:PROGRA~1QGIS32~1.0appsPython39libcode.py", line 90, in runcode
exec(code, self.locals)
File "<input>", line 1, in <module>
File "<string>", line 16, in <module>
IndexError: list index out of range

为什么它不能在插件中工作?

我们需要更多的信息,如第90行是哪个代码?无论如何,我要再次检查确保你的索引是正确的

'START_POINT':'{},{}'.format(origin_coords[0][0], origin_coords[0][1]),
'END_POINT':'{},{}'.format(destination_coords[0][0], destination_coords[0][1]),

destination_layer =  QgsProject.instance().mapLayersByName('Destination')[0]
matrix =  QgsProject.instance().mapLayersByName('join')[0]

相关内容

  • 没有找到相关文章

最新更新