Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 0.9.4 #501

Merged
merged 13 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions CHANGELIST.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
# QRiS Plugin

## [0.9.4] 2024 SEPT 17

### Added
- Added the generate centerline tool to Riverscapes Valley Bottoms #440
- Allow cross section clipping to be VB Polygon from Riverscapes Node #441
- Structural Elements form updated to include attributes based on logic #304
- Ability to update existing project export #363

### Fixed
- Error importing existing profiles when using mask/AOI clip #472
- Metrics Failing to update due to Unique name constraint #491
- Error when trying to edit properties of DCE (As Built) #451

### Changed
- Moved QRiS Symbology folder to RiverscapesStudio resources folder #487
- Changes to Vegetation Extents layer #455
- Changes to Geomorphic Units Layers #466
- Make Sample Frames 'create from QRIS features' defualt polygon layer to Riverscapes node Valley Bottom #443

### Removed
- Removed the generate centerline tool from Context Polygons #440
- Temporarily disbale BRAT CIS layers #454


## [0.9.3] 2024 SEPT 11

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion __version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.9.3"
__version__ = "0.9.4"
2 changes: 1 addition & 1 deletion src/QRiS/qrave_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self, parent):
self.name = plugins_lower_case[matched_lower_case_name]
self.plugin_instance = plugins[self.name]
self.qrave_map_layer = importlib.import_module(f'{self.name}.src.classes.qrave_map_layer')
self.symbology_folders = [parse_posix_path(os.path.join(self.qrave_map_layer.SYMBOLOGY_DIR, 'QRiS')),
self.symbology_folders = [parse_posix_path(os.path.join(self.qrave_map_layer.SYMBOLOGY_DIR, 'RiverscapesStudio')),
parse_posix_path(os.path.join(self.qrave_map_layer.SYMBOLOGY_DIR, 'Shared'))]
self.metric_definitions_folder = parse_posix_path(os.path.join(self.qrave_map_layer.SYMBOLOGY_DIR, '..', 'QRiS', 'metrics'))

Expand Down
14 changes: 14 additions & 0 deletions src/db/migrations/026_ltpbr_v2_layer_fixes.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-- Changes to Vegetation Extents layer #455
UPDATE layers SET metadata = '{"hierarchy": ["Observations", "Vegetation Mapping"], "fields": [{"machine_code": "vegetation_type", "label": "Type", "type": "list", "lookup": "vegetation_types"}, {"machine_code": "vegetation_tier_2_type", "label": "Type 2 Tier", "type": "list", "lookup": "vegetation_tier2_types", "allow_custom_values": "true"}, {"machine_code": "suitability", "label": "Brat Suitability", "type": "list", "lookup": "vegetation_suitability"}]}' WHERE fc_name = 'vegetation_extents';

-- Changes to Geomorphic Unit Layers #446
UPDATE layers SET metadata = '{"hierarchy": ["Observations", "Geomorphic Mapping", "Channel"], "fields": [{"machine_code": "geomorphic_unit_type", "label": "Type", "type": "list", "lookup": "geomorphic_unit_types", "required": true}, {"machine_code": "geomorphic_unit_type_2_tier", "label": "Type 2 Tier", "type": "list", "lookup": "geomorphic_units_tier2_types"}]}' WHERE fc_name = 'geomorphic_unit_extents';
UPDATE layers SET metadata = '{"hierarchy": ["Observations", "Geomorphic Mapping", "Channel"], "fields": [{"machine_code": "geomorphic_unit_type", "label": "Type", "type": "list", "lookup": "geomorphic_unit_types", "required": true}, {"machine_code": "geomorphic_unit_type_2_tier", "label": "Type 2 Tier", "type": "list", "lookup": "geomorphic_units_tier2_types"}, {"machine_code": "length", "label": "Length", "type": "float"}, {"machine_code": "width", "label": "Width", "type": "float"}, {"machine_code": "depth", "label": "Depth", "type": "float"}]}' WHERE fc_name = 'geomorphic_units';

-- Fix Structural Elements layer #304
UPDATE layers SET metadata = '{"hierarchy": ["Observations", "Structural Elements"], "fields": [{"machine_code": "structural_element_type", "label": "Type", "type": "list", "lookup": "structural_element_points"}, {"machine_code": "structure_count", "label": "Structure Count", "type": "integer", "default": 1, "visibility": {"field_name": "structural_element_type", "values": ["Dam Complex","Jam Complex"]}}, {"machine_code": "length", "label": "Length", "type": "float", "visibility": {"field_name": "structural_element_type", "values": ["Dam","Jam","Other","Root Mass"]}}, {"machine_code": "width", "label": "Width", "type": "float", "visibility": {"field_name": "structural_element_type", "values": ["Dam","Jam","Other","Root Mass"]}}, {"machine_code": "height", "label": "Height", "type": "float", "visibility": {"field_name": "structural_element_type", "values": ["Dam","Jam","Other","Root Mass"]}}, {"machine_code": "large_wood_count", "label": "Large Wood Count", "type": "integer"}]}' WHERE fc_name = 'structural_element_points';

-- Clean up gpkg_contents table
DELETE FROM gpkg_contents WHERE table_name = 'zoi_types';
DELETE FROM gpkg_contents WHERE table_name = 'structure_types';
DELETE FROM gpkg_contents WHERE table_name = 'lkp_zoi_stage';
31 changes: 18 additions & 13 deletions src/gp/feature_class_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def layer_path_parser(path: str) -> Tuple[str, str, object]:
return path, vl.name(), "memory"


def import_existing(source_path: str, dest_path: str, dest_layer_name: str, output_id: int, output_id_field: str, attributes: dict = {}, clip_mask_id: int = None) -> None:
def import_existing(source_path: str, dest_path: str, dest_layer_name: str, output_id: int, output_id_field: str, attributes: dict = {}, clip_mask: tuple = None) -> None:
"""
Copy the features from a source feature class to a destination mask feature class.
The mask record must already exist. The attributes is a dictionary of source column
Expand All @@ -74,33 +74,38 @@ def import_existing(source_path: str, dest_path: str, dest_layer_name: str, outp
src_layer_name = None
else:
src_path, src_layer_name = source_path.split('|layername=')
src_dataset = ogr.Open(src_path)
src_layer = src_dataset.GetLayer(src_layer_name if src_layer_name is not None else 0)
src_dataset: ogr.DataSource = ogr.Open(src_path)
src_layer: ogr.Layer = src_dataset.GetLayer(src_layer_name if src_layer_name is not None else 0)
src_srs = src_layer.GetSpatialRef()
fid_field_name = src_layer.GetFIDColumn()

gpkg_driver = ogr.GetDriverByName('GPKG')
dst_dataset = gpkg_driver.Open(dest_path, 1)
dst_layer = dst_dataset.GetLayerByName(dest_layer_name)
gpkg_driver: ogr.Driver = ogr.GetDriverByName('GPKG')
dst_dataset: ogr.DataSource = gpkg_driver.Open(dest_path, 1)
dst_layer: ogr.Layer = dst_dataset.GetLayerByName(dest_layer_name)
dst_srs = dst_layer.GetSpatialRef()
dst_layer_def = dst_layer.GetLayerDefn()

clip_geom = None
if clip_mask_id is not None:
clip_layer = dst_dataset.GetLayer('aoi_features')
clip_layer.SetAttributeFilter(f'mask_id = {clip_mask_id}')
clip_feat = clip_layer.GetNextFeature()
clip_geom:ogr.Geometry = None
if clip_mask is not None:
clip_layer: ogr.Layer = dst_dataset.GetLayer(clip_mask[0])
clip_layer.SetAttributeFilter(f'{clip_mask[1]} = {clip_mask[2]}')
clip_feat: ogr.Feature = clip_layer.GetNextFeature()
clip_geom = clip_feat.GetGeometryRef()

transform = osr.CoordinateTransformation(src_srs, dst_srs)

feats = 0
src_feature: ogr.Feature = None
for src_feature in src_layer:
geom = src_feature.GetGeometryRef()
geom:ogr.Geometry = src_feature.GetGeometryRef()
geom.Transform(transform)
if clip_geom is not None:
geom = clip_geom.Intersection(geom)
if geom.IsEmpty() or geom.GetArea() == 0.0:
if geom.IsEmpty() or geom is None:
continue
if geom.GetGeometryType() in [ogr.wkbPolygon, ogr.wkbMultiPolygon] and geom.GetArea() == 0.0:
continue
if geom.GetGeometryType() in [ogr.wkbLineString, ogr.wkbMultiLineString] and geom.Length() == 0.0:
continue

dst_feature = ogr.Feature(dst_layer_def)
Expand Down
11 changes: 5 additions & 6 deletions src/gp/import_feature_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ class ImportFeatureClass(QgsTask):
# Signal to notify when done and return the PourPoint and whether it should be added to the map
import_complete = pyqtSignal(bool, int, int, int)

def __init__(self, source_path: str, dest_path: str, attributes:dict= None, field_map: List[ImportFieldMap] = None, clip_mask_id=None, attribute_filter: str = None, proj_gpkg=None):
def __init__(self, source_path: str, dest_path: str, attributes: dict=None, field_map: List[ImportFieldMap]=None, clip_mask: tuple=None, attribute_filter: str=None, proj_gpkg=None):
super().__init__(f'Import Feature Class Task', QgsTask.CanCancel)

self.source_path = source_path
self.clip_mask_id = clip_mask_id
self.clip_mask = clip_mask # (fc_name, field_name, feature_id)
self.output_path = dest_path
self.field_map = field_map
self.attributes = attributes
Expand Down Expand Up @@ -89,13 +89,13 @@ def run(self):
dst_fid_column = dst_layer.GetFIDColumn()

clip_geom = None
if self.clip_mask_id is not None:
if self.clip_mask is not None:
if self.proj_gpkg is not None:
mask_dataset = ogr.Open(self.proj_gpkg)
else:
mask_dataset = dst_dataset
clip_layer: ogr.Layer = mask_dataset.GetLayer('aoi_features')
clip_layer.SetAttributeFilter(f'mask_id = {self.clip_mask_id}')
clip_layer: ogr.Layer = mask_dataset.GetLayer(self.clip_mask[0]) # 'aoi_features'
clip_layer.SetAttributeFilter(f'{self.clip_mask[1]} = {self.clip_mask[2]}') # 'mask_id'
# Gather all of the geoms and merge into a multipart geometry
clip_geom = ogr.Geometry(ogr.wkbMultiPolygon)
for clip_feat in clip_layer:
Expand All @@ -112,7 +112,6 @@ def run(self):

geom: ogr.Geometry = src_feature.GetGeometryRef()


if geom is None:
self.skipped_feats += 1
continue
Expand Down
12 changes: 6 additions & 6 deletions src/gp/import_temp_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ class ImportTemporaryLayer(QgsTask):
# Signal to notify when done and return the PourPoint and whether it should be added to the map
import_complete = pyqtSignal(bool, int, int, int)

def __init__(self, source_layer: QgsVectorLayer, dest_path: str, attributes: dict=None, field_map: List[ImportFieldMap]=None, clip_mask_id=None, attribute_filter: str=None, proj_gpkg=None):
def __init__(self, source_layer: QgsVectorLayer, dest_path: str, attributes: dict=None, field_map: List[ImportFieldMap]=None, clip_mask: tuple=None, attribute_filter: str=None, proj_gpkg=None):
super().__init__(f'Import Temporary Layer', QgsTask.CanCancel)

self.source_layer = source_layer.clone()
self.clip_mask_id = clip_mask_id
self.clip_mask = clip_mask # (fc_name, field_name, feature_id)
self.dest_path = dest_path
self.attributes = attributes
self.proj_gpkg = proj_gpkg
Expand Down Expand Up @@ -79,9 +79,9 @@ def run(self):
self.source_layer.dataProvider().addAttributes(fields)
self.source_layer.updateFields()

if self.clip_mask_id is not None:
clip_layer = QgsVectorLayer(f'{self.proj_gpkg}|layername=aoi_features')
clip_layer.setSubsetString(f'mask_id = {self.clip_mask_id}')
if self.clip_mask is not None:
clip_layer = QgsVectorLayer(f'{self.proj_gpkg}|layername={self.clip_mask[0]}') # aoi_features
clip_layer.setSubsetString(f'{self.clip_mask[1]} = {self.clip_mask[2]}') # mask_id
clip_transform = QgsCoordinateTransform(clip_layer.sourceCrs(), self.source_layer.sourceCrs(), QgsProject.instance().transformContext())
clip_feat = clip_layer.getFeatures()
clip_feat = next(clip_feat)
Expand Down Expand Up @@ -153,7 +153,7 @@ def run(self):
feat['metadata'] = json.dumps(metadata)

geom = feat.geometry()
if self.clip_mask_id is not None:
if self.clip_mask is not None:
geom = geom.intersection(clip_geom)
geom.transform(out_transform)
feat.setGeometry(geom)
Expand Down
13 changes: 11 additions & 2 deletions src/view/frm_asbuilt.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,16 @@ def __init__(self, parent, qris_project: Project, event_type_id: int, event: Eve
if 'constructionDate' in self.metadata_widget.metadata['system']:
# parse the date string
construction_date_json = self.metadata_widget.metadata['system']['constructionDate']
construction_date_dict = json.loads(construction_date_json)
try:
construction_date_dict = json.loads(construction_date_json)
except json.JSONDecodeError:
construction_date_dict = None
# manually extract the date parts from the string
construction_date_parts = construction_date_json.strip('{}').split(', ')
construction_date_dict = {}
for part in construction_date_parts:
key, value = part.split(': ')
construction_date_dict[key.strip('"\'')] = int(value.strip('"\'')) if value.strip('"\'') != 'None' else None
# create a DateSpec object from the dictionary
construction_date = DateSpec(
construction_date_dict.get('year', None),
Expand Down Expand Up @@ -218,7 +227,7 @@ def accept(self):
self.metadata_widget.delete_item('system', 'constructionDate')
else:
# Remove the None values from the dictionary, then convert to a json string
construction_date_str = str({key: value for key, value in dict_construction_date.items() if value is not None})
construction_date_str = json.dumps({key: value for key, value in dict_construction_date.items() if value is not None})
self.metadata_widget.add_system_metadata('constructionDate', construction_date_str)

design_source_ids = []
Expand Down
30 changes: 18 additions & 12 deletions src/view/frm_cross_sections.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,12 @@ def __init__(self, parent, project: Project, import_source_path: str = None, cro
self.cboAttribute.setModel(self.attribute_model)
self.cboAttribute.setCurrentIndex(self.attribute_model.getItemIndex(self.no_attribute))
if show_mask_clip:
# Masks (filtered to just AOI)
self.masks = {id: mask for id, mask in self.qris_project.masks.items() if mask.mask_type.id == AOI_MASK_TYPE_ID}
# combine the valley bottom and aoi dicts; wwe need to adjust the keys for the aois to avoid conflicts
self.masks = {}
for key, value in self.qris_project.valley_bottoms.items():
self.masks[key] = value
for key, value in self.qris_project.aois.items():
self.masks[key + 1000] = value
no_clipping = DBItem('None', 0, 'None - Retain full dataset extent')
self.masks[0] = no_clipping
self.masks_model = DBItemModel(self.masks)
Expand Down Expand Up @@ -124,32 +128,34 @@ def accept(self):
self.buttonBox.button(QtWidgets.QDialogButtonBox.Ok).setEnabled(True)
return
try:
clip_mask = self.cboMaskClip.currentData(QtCore.Qt.UserRole)
clip_mask_id = None
if clip_mask is not None:
clip_mask_id = clip_mask.id if clip_mask.id > 0 else None
clip_mask = None
clip_item:DBItem = self.cboMaskClip.currentData(QtCore.Qt.UserRole)
if clip_item is not None:
if clip_item.id > 0:
clip_mask = (clip_item.fc_name, clip_item.fc_id_column_name, clip_item.id)

if self.import_source_path is not None:
attributes = {'cross_section_id': self.cross_sections.id}
# if the selected value of cboAttribute is not the no_attribute, then set the attribute to the display_label
if self.cboAttribute.isVisible() and self.cboAttribute.currentData(QtCore.Qt.UserRole) != self.no_attribute:
attributes['display_label'] = self.cboAttribute.currentData(QtCore.Qt.UserRole).name
if self.layer_id == 'memory':
fc_name = f'{self.qris_project.project_file}|layername=cross_section_features'
task = ImportTemporaryLayer(self.import_source_path, fc_name, attributes, clip_mask_id=clip_mask_id, proj_gpkg=self.qris_project.project_file)
task = ImportTemporaryLayer(self.import_source_path, fc_name, attributes, clip_mask=clip_mask, proj_gpkg=self.qris_project.project_file)
result = task.run()
self.on_import_complete(result)
# this is getting stuck if run as a task:
# task.import_complete.connect(self.on_import_complete)
# QgsApplication.taskManager().addTask(task)
else:
import_existing(self.import_source_path, self.qris_project.project_file, 'cross_section_features', self.cross_sections.id, 'cross_section_id', attributes, clip_mask_id)
import_existing(self.import_source_path, self.qris_project.project_file, 'cross_section_features', self.cross_sections.id, 'cross_section_id', attributes, clip_mask)
super(FrmCrossSections, self).accept()
elif self.output_features is not None:
out_layer = QgsVectorLayer(f'{self.qris_project.project_file}|layername=cross_section_features')
clip_geom = None
if clip_mask_id is not None:
clip_layer = QgsVectorLayer(f'{self.qris_project.project_file}|layername=aoi_features')
clip_layer.setSubsetString(f'mask_id = {clip_mask_id}')
if clip_mask is not None:
clip_layer = QgsVectorLayer(f'{self.qris_project.project_file}|layername={clip_mask[0]}')
clip_layer.setSubsetString(f'{clip_mask[1]} = {clip_mask[2]}')
clip_feats = clip_layer.getFeatures()
clip_feat = QgsFeature()
clip_feats.nextFeature(clip_feat)
Expand Down Expand Up @@ -215,7 +221,7 @@ def setupUi(self):
self.cboAttribute = QtWidgets.QComboBox()
self.grid.addWidget(self.cboAttribute, 1, 1, 1, 1)

self.lblMaskClip = QtWidgets.QLabel('Clip to AOI')
self.lblMaskClip = QtWidgets.QLabel('Clip to AOI/Valley Bottom')
self.grid.addWidget(self.lblMaskClip, 2, 0, 1, 1)

self.cboMaskClip = QtWidgets.QComboBox()
Expand Down
Loading