kopia lustrzana https://github.com/JOSM/MapWithAI
FIXUP: Avoid source tag conflicts
* Merging addresses and buildings will now merge sources _in alphabetical_ order. This fixes #96. Signed-off-by: Taylor Smock <tsmock@fb.com>pull/1/head
rodzic
10e3ad76a7
commit
8e71690ed1
|
@ -8,8 +8,11 @@ import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import org.openstreetmap.josm.command.ChangePropertyCommand;
|
||||||
import org.openstreetmap.josm.command.Command;
|
import org.openstreetmap.josm.command.Command;
|
||||||
import org.openstreetmap.josm.command.SequenceCommand;
|
import org.openstreetmap.josm.command.SequenceCommand;
|
||||||
import org.openstreetmap.josm.data.osm.DataSet;
|
import org.openstreetmap.josm.data.osm.DataSet;
|
||||||
|
@ -31,6 +34,7 @@ import org.openstreetmap.josm.tools.Geometry;
|
||||||
*/
|
*/
|
||||||
public class MergeAddressBuildings extends AbstractConflationCommand {
|
public class MergeAddressBuildings extends AbstractConflationCommand {
|
||||||
public static final String KEY = "building";
|
public static final String KEY = "building";
|
||||||
|
public static final String SOURCE = "source";
|
||||||
|
|
||||||
public MergeAddressBuildings(DataSet data) {
|
public MergeAddressBuildings(DataSet data) {
|
||||||
super(data);
|
super(data);
|
||||||
|
@ -85,16 +89,27 @@ public class MergeAddressBuildings extends AbstractConflationCommand {
|
||||||
if (nodesWithAddresses.size() == 1
|
if (nodesWithAddresses.size() == 1
|
||||||
&& nodesWithAddresses.parallelStream().allMatch(n -> n.getParentWays().isEmpty())) {
|
&& nodesWithAddresses.parallelStream().allMatch(n -> n.getParentWays().isEmpty())) {
|
||||||
String currentKey = null;
|
String currentKey = null;
|
||||||
|
Node node = nodesWithAddresses.get(0);
|
||||||
|
List<String> sources = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
// Remove the key to avoid the popup from utilsplugin2
|
// Remove the key to avoid the popup from utilsplugin2
|
||||||
currentKey = object.get(KEY);
|
currentKey = object.get(KEY);
|
||||||
|
sources.add(object.get(SOURCE));
|
||||||
object.remove(KEY);
|
object.remove(KEY);
|
||||||
GuiHelper.runInEDTAndWait(() -> commandList
|
object.remove(SOURCE);
|
||||||
.add(ReplaceGeometryUtils.buildUpgradeNodeCommand(nodesWithAddresses.get(0), object)));
|
GuiHelper.runInEDTAndWait(
|
||||||
|
() -> commandList.add(ReplaceGeometryUtils.buildUpgradeNodeCommand(node, object)));
|
||||||
} finally {
|
} finally {
|
||||||
if (currentKey != null) {
|
if (currentKey != null) {
|
||||||
object.put(KEY, currentKey);
|
object.put(KEY, currentKey);
|
||||||
}
|
}
|
||||||
|
sources.add(node.get(SOURCE));
|
||||||
|
sources.removeIf(Objects::isNull);
|
||||||
|
sources = sources.stream().flatMap(source -> Stream.of(source.split(";", 0))).distinct()
|
||||||
|
.filter(Objects::nonNull).sorted().collect(Collectors.toList());
|
||||||
|
if (!sources.isEmpty()) {
|
||||||
|
commandList.add(new ChangePropertyCommand(object, SOURCE, String.join(";", sources)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return commandList;
|
return commandList;
|
||||||
|
|
|
@ -8,7 +8,9 @@ import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import org.openstreetmap.josm.command.ChangePropertyCommand;
|
import org.openstreetmap.josm.command.ChangePropertyCommand;
|
||||||
import org.openstreetmap.josm.command.Command;
|
import org.openstreetmap.josm.command.Command;
|
||||||
|
@ -92,12 +94,27 @@ public class MergeBuildingAddress extends AbstractConflationCommand {
|
||||||
.filter(prim -> checkInside(node, prim)).collect(Collectors.toList());
|
.filter(prim -> checkInside(node, prim)).collect(Collectors.toList());
|
||||||
|
|
||||||
final List<Command> commandList = new ArrayList<>();
|
final List<Command> commandList = new ArrayList<>();
|
||||||
|
List<String> sources = new ArrayList<>();
|
||||||
|
OsmPrimitive object = null;
|
||||||
|
sources.add(node.get(MergeAddressBuildings.SOURCE));
|
||||||
if (possibleDuplicates.size() == 1) {
|
if (possibleDuplicates.size() == 1) {
|
||||||
commandList.add(new ChangePropertyCommand(possibleDuplicates, node.getKeys()));
|
commandList.add(new ChangePropertyCommand(possibleDuplicates, node.getKeys()));
|
||||||
commandList.add(DeleteCommand.delete(Collections.singleton(node)));
|
commandList.add(DeleteCommand.delete(Collections.singleton(node)));
|
||||||
|
object = possibleDuplicates.get(0);
|
||||||
} else if (buildings.size() == 1 && getAddressPoints(buildings.get(0)).size() == 1) {
|
} else if (buildings.size() == 1 && getAddressPoints(buildings.get(0)).size() == 1) {
|
||||||
commandList.add(new ChangePropertyCommand(buildings, node.getKeys()));
|
commandList.add(new ChangePropertyCommand(buildings, node.getKeys()));
|
||||||
commandList.add(DeleteCommand.delete(Collections.singleton(node)));
|
commandList.add(DeleteCommand.delete(Collections.singleton(node)));
|
||||||
|
object = buildings.get(0);
|
||||||
|
}
|
||||||
|
if (object != null) {
|
||||||
|
sources.add(object.get(MergeAddressBuildings.SOURCE));
|
||||||
|
}
|
||||||
|
|
||||||
|
sources.removeIf(Objects::isNull);
|
||||||
|
sources = sources.stream().flatMap(source -> Stream.of(source.split(";", 0))).distinct()
|
||||||
|
.filter(Objects::nonNull).sorted().collect(Collectors.toList());
|
||||||
|
if (!sources.isEmpty() && object != null) {
|
||||||
|
commandList.add(new ChangePropertyCommand(object, MergeAddressBuildings.SOURCE, String.join(";", sources)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return commandList;
|
return commandList;
|
||||||
|
|
Ładowanie…
Reference in New Issue