From 71270c9f6dcbee97a54b1d5a91d187ac697cb454 Mon Sep 17 00:00:00 2001 From: Alireza Adli Date: Fri, 15 Mar 2024 11:26:23 -0400 Subject: [PATCH] Add the ScrubLayer class --- .gitignore | 6 +++++- scrub_layer_class.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 scrub_layer_class.py diff --git a/.gitignore b/.gitignore index 93f5256..b41eb46 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,5 @@ -__init__.py \ No newline at end of file +__init__.py + + +# Python Modules +*_test.py \ No newline at end of file diff --git a/scrub_layer_class.py b/scrub_layer_class.py new file mode 100644 index 0000000..ad3d299 --- /dev/null +++ b/scrub_layer_class.py @@ -0,0 +1,30 @@ +from qgis.core import * + + +class ScrubLayer: + def __init__(self, layer_path, layer_name): + self.layer_path = layer_path + self.layer_name = layer_name + self.layer = self._layer() + + @property + def layer(self): + return self._layer + + @layer.setter + def layer(self): + the_layer = QgsVectorLayer(self.layer_path, self.layer_name, "ogr") + if not the_layer.isValid(): + print(f'{self.layer_name} failed to load!') + else: + self._layer = QgsProject.instance().addMapLayer(the_layer) + + +if __name__ == '__main__': + new_path = \ + 'C:/Users/a_adli/PycharmProjects/' \ + 'hydroquebec_archetype_gispy/data/' \ + 'test_data/mtl_north/test_north_mtl.shp' + data_layer_name = 'mtl_north' + handle_layer = ScrubLayer(new_path, 'mtl_north') + handle_layer.layer. \ No newline at end of file