Last active
February 18, 2021 15:49
-
-
Save thbaumann/28f262612cafcaa0c454df5fdcd44f72 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from qgis.core import * | |
from qgis.gui import * | |
import os.path | |
@qgsfunction(args='auto', group='Custom',usesgeometry=False) | |
def layername_aus_pfad(current_path, feature, parent): | |
""" | |
Layername aus dem Pfad ermitteln | |
current_path: an die Funktion uebergebener pfad, wie z.B. layer_by_path('D:\loeschen\gemarkungen.shp') | |
""" | |
path=os.path.normpath(current_path) | |
print(path) | |
for layer in QgsProject.instance().mapLayers().values(): | |
print('pfad: '+os.path.normpath(layer.dataProvider().dataSourceUri()).split('|')[0]) | |
if path in (os.path.normpath(layer.dataProvider().dataSourceUri()).split('|')[0]): | |
return(layer.name()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment