Fix an issue where OSM servers couldn't be used as a mapwithai server

Signed-off-by: Taylor Smock <taylor.smock@kaart.com>
pull/1/head v1.1.0
Taylor Smock 2020-01-13 12:06:10 -07:00
rodzic 4b0a07bb2f
commit 49f6ff7527
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 625F6A74A3E4311A
1 zmienionych plików z 39 dodań i 12 usunięć

Wyświetl plik

@ -167,7 +167,7 @@ public class GetDataRunnable extends RecursiveTask<DataSet> {
final List<DataSet> osmData = MainApplication.getLayerManager().getLayersOfType(OsmDataLayer.class)
.parallelStream().map(OsmDataLayer::getDataSet).filter(ds -> !ds.equals(dataSet))
.collect(Collectors.toList());
dataSet.getWays().parallelStream().filter(way -> !way.isDeleted())
dataSet.getWays().parallelStream().filter(way -> !way.isDeleted() && way.getOsmId() <= 0)
.filter(way -> osmData.stream().anyMatch(ds -> checkIfPrimitiveDuplicatesPrimitiveInDataSet(way, ds)))
.forEach(way -> {
final List<Node> nodes = way.getNodes();
@ -279,17 +279,7 @@ public class GetDataRunnable extends RecursiveTask<DataSet> {
.collect(Collectors.toList());
for (int i = 0; i < nodes.size(); i++) {
final Node n1 = nodes.get(i);
final BBox bbox = new BBox();
bbox.addPrimitive(n1, 0.001);
final List<Node> nearbyNodes = dataSet.searchNodes(bbox).parallelStream().filter(node -> !node.isDeleted()
&& !node.equals(n1) && node.getReferrers().parallelStream().allMatch(prim -> prim.hasKey("highway"))
&& (((n1.getKeys().equals(node.getKeys()) || n1.getKeys().isEmpty() || node.getKeys().isEmpty())
&& (n1.getCoor().greatCircleDistance(node.getCoor()) < MapWithAIPreferenceHelper
.getMaxNodeDistance()))
|| (!n1.getKeys().isEmpty() && n1.getKeys().equals(node.getKeys())
&& (n1.getCoor().greatCircleDistance(
node.getCoor()) < (MapWithAIPreferenceHelper.getMaxNodeDistance() * 10)))))
.collect(Collectors.toList());
final List<Node> nearbyNodes = nearbyNodes(dataSet, n1);
final Command mergeCommand = MergeNodesAction.mergeNodes(nearbyNodes, n1);
if (mergeCommand != null) {
mergeCommand.executeCommand();
@ -298,6 +288,43 @@ public class GetDataRunnable extends RecursiveTask<DataSet> {
}
}
private static List<Node> nearbyNodes(DataSet ds, Node nearNode) {
final BBox bbox = new BBox();
bbox.addPrimitive(nearNode, 0.001);
return ds.searchNodes(bbox).parallelStream().filter(node -> usableNode(nearNode, node))
.collect(Collectors.toList());
}
private static boolean usableNode(Node nearNode, Node node) {
return basicNodeChecks(nearNode, node) && onlyHasHighwayParents(node)
&& ((keyCheck(nearNode, node)
&& distanceCheck(nearNode, node, MapWithAIPreferenceHelper.getMaxNodeDistance()))
|| (!nearNode.getKeys().isEmpty() && nearNode.getKeys().equals(node.getKeys())
&& distanceCheck(nearNode, node, MapWithAIPreferenceHelper.getMaxNodeDistance() * 10)));
}
private static boolean distanceCheck(Node nearNode, Node node, Double distance) {
try {
return nearNode.getCoor().greatCircleDistance(node.getCoor()) < distance;
} catch (Exception e) {
Logging.error(e);
return false;
}
}
private static boolean keyCheck(Node nearNode, Node node) {
return nearNode.getKeys().equals(node.getKeys()) || nearNode.getKeys().isEmpty() || node.getKeys().isEmpty();
}
private static boolean onlyHasHighwayParents(Node node) {
return node.getReferrers().parallelStream().allMatch(prim -> prim.hasKey("highway"));
}
private static boolean basicNodeChecks(Node nearNode, Node node) {
return node != null && nearNode != null && !node.isDeleted() && !nearNode.isDeleted() && !nearNode.equals(node)
&& node.isLatLonKnown() && nearNode.isLatLonKnown();
}
private static void mergeWays(DataSet dataSet) {
final List<Way> ways = dataSet.getWays().parallelStream().filter(way -> !way.isDeleted())
.collect(Collectors.toList());