Skip to content

Commit

Permalink
Fix injecting source tags
Browse files Browse the repository at this point in the history
  • Loading branch information
praszuk committed Sep 17, 2024
1 parent f8d956a commit 20443c0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,13 @@ static CombineNearestStrategy getImportBuildingOverlapStrategy(
return strategy;
}

public static void injectSourceTags(OsmPrimitive importedBuilding, String geometrySource, String tagsSource) {
if (!geometrySource.equals(tagsSource)) {
importedBuilding.put("source:geometry", geometrySource);
}
importedBuilding.put("source:building", tagsSource);
}

/**
* Create a new building based on provided parameters. It's cloned with new id/nodes.
*
Expand Down Expand Up @@ -225,9 +232,14 @@ public static OsmPrimitive getNearestImportedBuilding(
) {
OsmPrimitive importedBuilding;

String importedBuildingGeometrySource = profile.getGeometry();
String importedBuildingTagsSource = profile.getTags();

// One data source
if (profile.isOneDataSource()) {
importedBuilding = getNearestBuilding(importedData.get(profile.getGeometry()), latLon);
importedBuildingGeometrySource = profile.getGeometry();
importedBuildingTagsSource = profile.getGeometry();
}
// Multiple data source
else {
Expand All @@ -243,8 +255,9 @@ else if (geometryDs.isEmpty() != tagsDs.isEmpty()) {
String availableDsName = geometryDs.isEmpty() ? profile.getTags() : profile.getGeometry();

if (getImportBuildingDataOneDsStrategy(availableDsName) == ACCEPT) {
importedBuilding =
NearestBuilding.getNearestBuilding(importedData.get(availableDsName), latLon);
importedBuilding = NearestBuilding.getNearestBuilding(importedData.get(availableDsName), latLon);
importedBuildingTagsSource = availableDsName;
importedBuildingGeometrySource = availableDsName;
} else {
importedBuilding = null;
}
Expand All @@ -270,16 +283,23 @@ else if (geometryDs.isEmpty() != tagsDs.isEmpty()) {
break;
case ACCEPT_GEOMETRY:
importedBuilding = geometryBuilding;
importedBuildingGeometrySource = profile.getGeometry();
importedBuildingTagsSource = profile.getGeometry();
break;
case ACCEPT_TAGS:
importedBuilding = tagsBuilding;
importedBuildingGeometrySource = profile.getTags();
importedBuildingTagsSource = profile.getTags();
break;
default:
importedBuilding = null;
}
}
}
}
if (importedBuilding != null) {
injectSourceTags(importedBuilding, importedBuildingGeometrySource, importedBuildingTagsSource);
}
return CloneBuilding.cloneBuilding(importedBuilding);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,24 +91,6 @@ public static boolean showDialogIfFoundUncommonTags(Way resultBuilding, Building
return true;
}

public static void injectSourceTags(Way importedBuilding, BuildingsImportManager manager) {
String tagsDs = manager.getCurrentProfile().getTags();
String geomDs = manager.getCurrentProfile().getGeometry();
String sourceBuilding;

if (manager.getCurrentProfile().isOneDataSource()) {
sourceBuilding = tagsDs;
} else if (manager.getImportedData().get(tagsDs).isEmpty()) {
sourceBuilding = geomDs;
} else if (manager.getImportedData().get(geomDs).isEmpty()) {
sourceBuilding = tagsDs;
} else {
sourceBuilding = tagsDs;
importedBuilding.put("source:geometry", geomDs);
}
importedBuilding.put("source:building", sourceBuilding);
}

public static void performBuildingImport(BuildingsImportManager manager) {
importStats.addTotalImportActionCounter(1);

Expand All @@ -130,8 +112,6 @@ public static void performBuildingImport(BuildingsImportManager manager) {
// Add importedBuilding to DataSet to prevent DataIntegrityError (primitives without osm metadata)
new DataSet().addPrimitiveRecursive(importedBuilding);

injectSourceTags(importedBuilding, manager);

ImportStrategy importStrategy;
switch (BuildingsSettings.IMPORT_MODE.get()) {
case FULL:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
public enum CombineNearestStrategy {
ASK_USER("ask_user"),
CANCEL("cancel"),
ACCEPT("accept_geometry"),
ACCEPT("accept"),
ACCEPT_GEOMETRY("accept_geometry"),
ACCEPT_TAGS("accept_tags");

Expand Down

0 comments on commit 20443c0

Please sign in to comment.