Geographic Information Systems Asked by Miha on April 9, 2021
I have two SHP files in QGIS project (points: NODES.shp and lines: BRANCH.shp). NODES.shp has one ID attribute NODE_CON. BRANCH.shp has attributes NODE1 and NODE2 which represent start and end node of topology network.
I need the tool wich at inserting feature into BRANCH.shp automaticly detect NODE_CON of the start node of the new polyline and write it into NODE1. Similar it need to detect NODE_CON of the end node and write it into NODE2.
My idea:
I am trying with Default value on BRANCH form. My idea is to write the function getNodeCon
with three parameters:
I would call the function like that:
getNodeCon('NODES', 'NODE_CON', start_point($geometry)).
———function definition start—————
import os
from qgis.core import *
from qgis.gui import *
@qgsfunction(args=3, group='Custom')
def getNodeCon(layer_name, conn_field, tocka):
layerList = QgsProject.instance().mapLayersByName(layer_name)
layer = layerList[0]
NodeCon = 'NOK'
for feat in layer.getFeatures():
if feat.geometry().within.tocka.geometry().buffer(0.5,100):
NodeCon = feat.fieldNameIndex(conn_field)
break
return NodeCon
———function definition end—————
I get error measage:
Eval Error: QgsProject.mapLayersByName(): argument 1 has unexpected type 'list'
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP