Add the ScrubLayer class
This commit is contained in:
parent
c44aa661e0
commit
71270c9f6d
6
.gitignore
vendored
6
.gitignore
vendored
|
@ -1 +1,5 @@
|
|||
__init__.py
|
||||
__init__.py
|
||||
|
||||
|
||||
# Python Modules
|
||||
*_test.py
|
30
scrub_layer_class.py
Normal file
30
scrub_layer_class.py
Normal 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.
|
Loading…
Reference in New Issue
Block a user