Skip to content

Commit

Permalink
debug fields parser
Browse files Browse the repository at this point in the history
Signed-off-by: minff <16268924+minff@users.noreply.github.com>
  • Loading branch information
minff committed Oct 10, 2023
1 parent 957bfc6 commit 2ba9806
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 7 additions & 5 deletions XYZHubConnector/xyz_qgis/layer/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ def check_same_fields(fields1: QgsFields, fields2: QgsFields):
return len_ok and name_ok and field_origin_ok


def update_feature_fields(feat: QgsFeature, fields: QgsFields):
def update_feature_fields(feat: QgsFeature, fields: QgsFields, ref: QgsFields):
"""
Update fields of feature and its data (QgsAttributes)
Expand All @@ -448,11 +448,13 @@ def update_feature_fields(feat: QgsFeature, fields: QgsFields):
:return: new QgsFeature with updated fields
"""
old_fields = feat.fields()
names, old_names = fields.names(), old_fields.names()
try:
assert set(fields.names()).issuperset(
set(old_fields.names())
), "new fields must be a super set of existing fields of feature.\nnew: {}\nold: {}".format(
fields.names(), old_fields.names()
assert set(names).issuperset(set(old_names)), (
"new fields must be a super set of existing fields of feature.\n"
+ "new: {} {}\nold: {} {}\nref: {} {}".format(
len(names), names, len(old_names), old_names, len(ref.names()), ref.names()
)
)
except AssertionError as e:
print_error(e)
Expand Down
4 changes: 3 additions & 1 deletion XYZHubConnector/xyz_qgis/layer/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ def add_feature_render(vlayer, feat, new_fields):
# assert parser.check_same_fields(new_fields, pr.fields()) # validate addAttributes

# always update feature fields according to provider fields
feat = filter(None, (parser.update_feature_fields(ft, pr.fields()) for ft in feat if ft))
feat = filter(
None, (parser.update_feature_fields(ft, pr.fields(), new_fields) for ft in feat if ft)
)

ok, out_feat = pr.addFeatures(feat)
if not ok:
Expand Down

0 comments on commit 2ba9806

Please sign in to comment.