Skip to content

Commit

Permalink
Fix retrieval of file path and layer name
Browse files Browse the repository at this point in the history
GPKG layers loaded as results from processing algorithms seem to just
have their path as source, while GPKG layers loaded from files manually
have the |layername= in the source, even if filename==layername.
  • Loading branch information
Johannes Kröger committed Dec 7, 2022
1 parent d9a2c70 commit 86491b2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
19 changes: 15 additions & 4 deletions helpers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import re
import importlib
from typing import Any, List, Iterable
Expand Down Expand Up @@ -87,10 +88,20 @@ def getLayerGeomName(layer: QgsVectorLayer):


def getLayerGeomNameOgr(layer: QgsVectorLayer):
source = layer.source().split('|')
gpkg = source[0]
lname = source[1].split('=')[1]
conn = ogr.Open(gpkg)
source = layer.source()

# layer source *might* include pipe character and then the layername
# but when created from a processing algorithm, it might not
if "|" in source:
split_source = source.split('|')
filepath = split_source[0]
lname = split_source[1].split('=')[1]
else:
# assuming we simply got a full path to the file and nothing else
filepath = layer.source()
lname = os.path.splitext(os.path.basename(filepath))[0]

conn = ogr.Open(filepath)
ogrLayer = conn.GetLayerByName(lname)
columnName = ogrLayer.GetGeometryColumn()
ogrLayer = None
Expand Down
2 changes: 1 addition & 1 deletion metadata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name=Räumlicher Filter
qgisMinimumVersion=3.22
description=Spatial filters for PostGIS, GeoPackage and Spatialite layers
description[de]=Räumliche Filter für PostGIS-, GeoPackage- und Spatialite-Layer
version=1.0
version=1.1
author=WhereGroup GmbH (Peter Gipper, Mathias Gröbe, Johannes Kröger)
email=info@wheregroup.com

Expand Down

0 comments on commit 86491b2

Please sign in to comment.