Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mhhd2020 committed Jul 22, 2023
1 parent 081a988 commit 79fdc62
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
25 changes: 11 additions & 14 deletions sketch_map_tool/upload_processing/qgis_scripts/count_duplicates.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,14 @@ def processAlgorithm(self, parameters, context, feedback):
out_fields = source.fields()
out_fields.append(QgsField("COUNT", QVariant.Int, "", 10, 0))

# Add id fields, used to TODO
# Add fields identifying different sketch maps, i.e. the filenames
name_index = source.fields().indexOf("name")
values = source.uniqueValues(name_index)

for id_value in values:
#out_fields.append(QgsField(str(id_value), QVariant.Int, "", 10, 0))
out_fields.append(QgsField(f"{id_value}", QVariant.Int, "", 10, 0))
print("BEFORE:")
print(out_fields)
for out_f in out_fields:
print(out_f)

out_fields.remove(name_index)
print("AFTER:")
print(out_fields)
for out_f in out_fields:
print(out_f)
# TODO: Contents of out_fields now -> Can the initialisation be made more clearly?

# The 'dest_id' variable is used to uniquely identify the feature sink
(sink, dest_id) = self.parameterAsSink(
Expand All @@ -105,15 +97,19 @@ def processAlgorithm(self, parameters, context, feedback):

features = source.getFeatures()

# print(f"{len(features)=}")
print(f"{features=}")
for i, feature in enumerate(features):
print(f"Feature loop, iteration {i=}, {feature=}")
attributes = feature.attributes()
del attributes[name_index]
attributes += [0] * (len(out_fields) - len(attributes)) # TODO: Why?
attributes += [0] * (len(out_fields) - len(attributes)) # Initialise new fields with zero

count = 0
add_feature = True

for j, other_feature in enumerate(features):
features_ = source.getFeatures()
for j, other_feature in enumerate(features_):
print(f"Inner Feature loop, iteration {j=}, {other_feature=}")
if feature.geometry().equals(other_feature.geometry()):
feature_id = other_feature.attributes()[name_index]
attributes[out_fields.indexOf("{}".format(feature_id))] += 1
Expand All @@ -124,4 +120,5 @@ def processAlgorithm(self, parameters, context, feedback):
out_feature.setAttributes(attributes)
out_feature.setGeometry(feature.geometry())
sink.addFeature(out_feature, QgsFeatureSink.FastInsert)
print("Finished inner loop")
return {self.OUTPUT: dest_id}
16 changes: 9 additions & 7 deletions sketch_map_tool/upload_processing/qgis_scripts/cout_overlaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,16 @@ def processAlgorithm(self, parameters, context, model_feedback):
out_fields = source.fields()
out_fields.append(QgsField("COUNT", QVariant.Int, "", 10, 0))

# Add id fields identifying different sketch maps, i.e. the filenames
# Add fields identifying different sketch maps, i.e. the filenames
# They will be used to indicate to which sketch maps each part of the markings belongs to
name_index = source.fields().indexOf("name")
unique_ids = source.uniqueValues(name_index)
sketch_map_indicator_fields_indices = []
for id_ in unique_ids:
sketch_map_indicator_fields_indices.append(len(out_fields))
out_fields.append(QgsField(str(id_), QVariant.Int, "", 10, 0))
print("BEFORE:")
print(out_fields)
out_fields.remove(name_index)
print("AFTER:")
print(out_fields)
# TODO: Contents of out_fields now -> Can the initialisation be made more clearly?

# The 'dest_id' variable is used to uniquely identify the feature sink
(sink, dest_id) = self.parameterAsSink(
parameters,
Expand All @@ -124,7 +123,7 @@ def processAlgorithm(self, parameters, context, model_feedback):
for i, feature in enumerate(features):
attributes = feature.attributes()
del attributes[name_index]
attributes += [0] * (len(out_fields) - len(attributes)) # TODO: Why?
attributes += [0] * (len(out_fields) - len(attributes)) # Initialise new fields with zero

count = 0
add_feature = True
Expand All @@ -140,6 +139,9 @@ def processAlgorithm(self, parameters, context, model_feedback):
out_feature.setAttributes(attributes)
out_feature.setGeometry(feature.geometry())
sink.addFeature(out_feature, QgsFeatureSink.FastInsert)

for indicator_field_index in sketch_map_indicator_fields_indices:
out_fields.remove(indicator_field_index)
return {self.OUTPUT: dest_id}

out_layers.append(overlap_counts)
Expand Down

0 comments on commit 79fdc62

Please sign in to comment.