Add the ScrubLayer class

This commit is contained in:
Alireza Adli 2024-03-15 11:26:23 -04:00
parent c44aa661e0
commit 71270c9f6d
2 changed files with 35 additions and 1 deletions

4
.gitignore vendored
View File

@ -1 +1,5 @@
__init__.py
# Python Modules
*_test.py

30
scrub_layer_class.py Normal file
View File

@ -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.