我想从qgs要素迭代器对象中减去两个值,并根据条件将要素ID的值附加到列表中。
在qgis的上下文中,我有两个层次: roadsLayer pathsLayer
我到目前为止返回一个空列表:
evenList = []
azimuthRoadsIDX = roadsLayer.fieldNameIndex('azimuth')
azimuthPathsIDX = pathsLayer.fieldNameIndex('azimuth')
roads = roadsLayer.getFeatures()
paths = pathsLayer.getFeatures()
for feat in roads:
for feature in paths:
roadsAzimuth = feat.attributes()[azimuthRoadsIDX]
pathsAzimuth = feature.attributes()[azimuthPathsIDX]
if (roadsAzimuth - pathsAzimiuth == 90) or (roadsAzimuth - pathsAzimth == -270):
evenList.append(feature.id())
不知道为什么,但这有效。唯一的问题是它在所有情况下都不起作用(即使在roadsAzimuth - pathsAzimuth == 90时,在某些情况下也没有附加):
for feat in roadsLayer.getFeatures():
roadsAzimuth = feat.attributes()[azimuthRoadsIDX]
for feature in pathsLayer.getFeatures():
pathsAzimuth = feature.attributes()[azimuthPathsIDX]
if (roadsAzimuth - pathsAzimiuth == 90) or (roadsAzimuth - pathsAzimth == -270):
evenList.append(feature.id())