qgis-tem-loader

qgis plugin for loading TEM geophysical inversion XYZ files as 3D objects
git clone git://src.adamsgaard.dk/qgis-tem-loader # fast
git clone https://src.adamsgaard.dk/qgis-tem-loader.git # slow
Log | Files | Refs | README | LICENSE Back to index

commit c8183a0efe82a168156f724f4f53fb63a43849e0
parent ca9ee470f4174e301c1d2f2e61c13dd149cc99f2
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Fri, 10 Apr 2026 09:31:04 +0200

fix(qgis): correct Windows layer file URIs

Diffstat:
Mtem_loader/metadata.txt | 2+-
Mtem_loader/tem_loader.py | 20++++++++++++--------
Mtest/test_core.py | 21+++++++++++++++++++++
3 files changed, 34 insertions(+), 9 deletions(-)

diff --git a/tem_loader/metadata.txt b/tem_loader/metadata.txt @@ -3,7 +3,7 @@ name=TEM Loader qgisMinimumVersion=3.40.0 qgisMaximumVersion=4.1.0 description=Load TEM inversion XYZ files as styled 3D vector layers -version=0.1.2 +version=0.1.3 author=Anders Damsgaard email=andam@geus.dk about=QGIS plugin for loading geophysical inversion mdels. Adds a menu item to the "Plugin" menu. The models are loaded as 3D points for the terrain surface with line numbers as labels, 3D points for DOI at depth, and model layers as 3D lines. The plugin supports profile visualization using the "Elevation Profile" tool in QGIS. diff --git a/tem_loader/tem_loader.py b/tem_loader/tem_loader.py @@ -13,6 +13,17 @@ from . import core STYLES_DIR = Path(__file__).parent / 'styles' +def _build_delimited_text_uri(csv_path, geom_type, crs_str): + base_uri = csv_path.resolve().as_uri() + return ( + f'{base_uri}?type={geom_type}' + f'&crs={crs_str}' + f'&wktField=Geometry' + f'&delimiter=,' + f'&xField=X&yField=Y' + ) + + class TEMLoaderPlugin: def __init__(self, iface): self.iface = iface @@ -76,14 +87,7 @@ class TEMLoaderPlugin: ('points', pts_csv, 'Point'), ] for name, csv_path, geom_type in source_layers: - uri = ( - f'file://{csv_path.as_posix()}' - f'?type={geom_type}' - f'&crs={crs_str}' - f'&wktField=Geometry' - f'&delimiter=,' - f'&xField=X&yField=Y' - ) + uri = _build_delimited_text_uri(csv_path, geom_type, crs_str) layer = QgsVectorLayer(uri, name, 'delimitedtext') if not layer.isValid(): continue diff --git a/test/test_core.py b/test/test_core.py @@ -271,3 +271,24 @@ class PluginTests(unittest.TestCase): self.assertEqual(len(message_box.warnings), 1) self.assertIn("bad.xyz", message_box.warnings[0][2]) self.assertIn("Row 3 has 4 columns, expected 6", message_box.warnings[0][2]) + + def test_build_delimited_text_uri_preserves_local_file_uri(self): + module, _, _ = self._import_plugin_module() + csv_path = Mock() + resolved = Mock() + resolved.as_uri.return_value = "file:///C:/temp/model.layers.csv" + csv_path.resolve.return_value = resolved + + uri = module._build_delimited_text_uri( + csv_path, "LineString", "EPSG:32632" + ) + + self.assertEqual( + uri, + "file:///C:/temp/model.layers.csv" + "?type=LineString" + "&crs=EPSG:32632" + "&wktField=Geometry" + "&delimiter=," + "&xField=X&yField=Y", + )