diff --git a/OsmAnd-java/src/main/java/net/osmand/binary/GeocodingUtilities.java b/OsmAnd-java/src/main/java/net/osmand/binary/GeocodingUtilities.java index 6b696dc900..324cf9813f 100644 --- a/OsmAnd-java/src/main/java/net/osmand/binary/GeocodingUtilities.java +++ b/OsmAnd-java/src/main/java/net/osmand/binary/GeocodingUtilities.java @@ -183,8 +183,13 @@ public class GeocodingUtilities { } } Collections.sort(lst, GeocodingUtilities.DISTANCE_COMPARATOR); - result.put(lst.get(0).point.getRoad().id, point); + if (lst.size() > 0) { + result.put(lst.get(0).point.getRoad().id, point); +// log.debug(String.format("Road %s", lst.get(0).point.getRoad())); + } } + log.debug(String.format("Time to load %d, time to findInitialSegment %d, timeToLoadHeaders %d, tiles loaded %d", + ctx.timeToLoad,ctx.timeToFindInitialSegments, ctx.timeToLoadHeaders, ctx.loadedTiles)); return result; } diff --git a/OsmAnd-java/src/main/java/net/osmand/router/RoutingContext.java b/OsmAnd-java/src/main/java/net/osmand/router/RoutingContext.java index a078817543..c2d3674476 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/RoutingContext.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/RoutingContext.java @@ -92,10 +92,10 @@ public class RoutingContext { public int memoryOverhead = 0; - long timeNanoToCalcDeviation = 0; - long timeToLoad = 0; - long timeToLoadHeaders = 0; - long timeToFindInitialSegments = 0; + public long timeNanoToCalcDeviation = 0; + public long timeToLoad = 0; + public long timeToLoadHeaders = 0; + public long timeToFindInitialSegments = 0; public long timeToCalculate = 0; int distinctLoadedTiles = 0; @@ -289,6 +289,7 @@ public class RoutingContext { public void loadSubregionTile(final RoutingSubregionTile ts, boolean loadObjectsInMemory, List toLoad, TLongHashSet excludeNotAllowed) { boolean wasUnloaded = ts.isUnloaded(); int ucount = ts.getUnloadCont(); + if (nativeLib == null) { long now = System.nanoTime(); try { @@ -321,7 +322,7 @@ public class RoutingContext { } catch (IOException e) { throw new RuntimeException("Loading data exception", e); } - +// log.debug(String.format("Load subregion: %s", ts.subregion.filePointer)); timeToLoad += (System.nanoTime() - now); } else { diff --git a/OsmAnd/src/net/osmand/plus/CurrentPositionHelper.java b/OsmAnd/src/net/osmand/plus/CurrentPositionHelper.java index 0dd8fe4987..241b5cf56a 100644 --- a/OsmAnd/src/net/osmand/plus/CurrentPositionHelper.java +++ b/OsmAnd/src/net/osmand/plus/CurrentPositionHelper.java @@ -188,9 +188,9 @@ public class CurrentPositionHelper { boolean allowEmptyNames, @Nullable ApplicationMode appMode) { - List checkReaders = new ArrayList<>(); + List checkReaders = usedReaders; for (Location loc : points) { - checkReaders.addAll(checkReaders(loc.getLatitude(), loc.getLongitude(), usedReaders)); + checkReaders = checkReaders(loc.getLatitude(), loc.getLongitude(), checkReaders); } if (appMode == null) { @@ -230,11 +230,11 @@ public class CurrentPositionHelper { for (BinaryMapReaderResource rep : checkReaders) { rs[i++] = rep.getReader(BinaryMapReaderResourceType.STREET_LOOKUP); } - RoutingConfiguration cfg = app.getRoutingConfig().build(p, 10, + RoutingConfiguration cfg = app.getRoutingConfig().build(p, 100, new HashMap()); cfg.routeCalculationTime = System.currentTimeMillis(); ctx = new RoutePlannerFrontEnd().buildRoutingContext(cfg, null, rs); - RoutingConfiguration defCfg = app.getRoutingConfig().build("geocoding", 10, + RoutingConfiguration defCfg = app.getRoutingConfig().build("geocoding", 100, new HashMap()); defCtx = new RoutePlannerFrontEnd().buildRoutingContext(defCfg, null, rs); } else { diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java index 34574936f8..f63f0d8c6c 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java @@ -979,8 +979,8 @@ public class MapActivityActions implements DialogProvider { @Override public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int pos, boolean isChecked, int[] viewCoordinates) { app.logEvent("drawer_import_avoid_roads"); -// app.getAvoidRoadsHelper().testRun(); - app.getAvoidRoadsHelper().testRunDownload(); + app.getAvoidRoadsHelper().testRun(); +// app.getAvoidRoadsHelper().testRunDownload(); return true; } }).createItem()); diff --git a/OsmAnd/src/net/osmand/plus/avoidroads/AvoidRoadsHelper.java b/OsmAnd/src/net/osmand/plus/avoidroads/AvoidRoadsHelper.java index 2d962c6593..395e4f8ff0 100644 --- a/OsmAnd/src/net/osmand/plus/avoidroads/AvoidRoadsHelper.java +++ b/OsmAnd/src/net/osmand/plus/avoidroads/AvoidRoadsHelper.java @@ -11,6 +11,9 @@ import net.osmand.IndexConstants; import net.osmand.Location; import net.osmand.PlatformUtil; import net.osmand.ResultMatcher; +import net.osmand.binary.RouteDataObject; +import net.osmand.data.QuadRect; +import net.osmand.data.QuadTree; import net.osmand.osm.io.NetworkUtils; import net.osmand.plus.ApplicationMode; import net.osmand.plus.OsmandApplication; @@ -27,6 +30,7 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.net.URLConnection; import java.util.ArrayList; +import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -64,6 +68,7 @@ public class AvoidRoadsHelper { completionCallback = new CompletionCallback() { @Override public void onRDOSearchComplete() { + if (saveResultToFile) { File out = new File (app.getAppPath(IndexConstants.AVOID_ROADS_DIR).getAbsolutePath() + "/" + "processed_ids.json"); @@ -80,11 +85,15 @@ public class AvoidRoadsHelper { } public void testRun() { - File in = new File(app.getAppPath(IndexConstants.AVOID_ROADS_DIR).getAbsolutePath() + "/" + inputFileName); - LOG.debug(String.format("Input json: %s", in.getAbsolutePath())); - if (in.exists()) { - loadJson(in.getAbsolutePath(), FROM_STORAGE); - } +// File in = new File(app.getAppPath(IndexConstants.AVOID_ROADS_DIR).getAbsolutePath() + "/" + inputFileName); +// LOG.debug(String.format("Input json: %s", in.getAbsolutePath())); +// if (in.exists()) { +// loadJson(in.getAbsolutePath(), FROM_STORAGE); +// } + //String url = "https://gist.githubusercontent.com/MadWasp79/1238d8878792572e343eb2e296c3c7f5/raw/494f872425993797c3a3bc79a4ec82039db6ee46/point_100.json"; + String url = "https://gist.githubusercontent.com/MadWasp79/45f362ea48e9e8edd1593113593993c5/raw/6e817fb3bc7eaeaa3eda24847fde4855eb22485d/points_500.json"; + LOG.debug(String.format("Loading json from url: %s", url)); + loadJson(url, FROM_URL); } public void testRunDownload() { @@ -94,11 +103,40 @@ public class AvoidRoadsHelper { } - public void convertPointsToRDO(List parsedPoints) { - + public void convertPointsToRDO(final List parsedPoints) { + final Map avoidedRoads = new HashMap<>(); + final long timeStart = System.currentTimeMillis(); + final int[] count = {0}; this.roadsToAvoid.clear(); +// for (final Location point : parsedPoints) { +// +// app.getLocationProvider().getRouteSegment(point, appMode, false, new ResultMatcher() { +// @Override +// public boolean publish(RouteDataObject result) { +// count[0]++; +// if (result == null) { +// LOG.error("Error! Find no result for point []"); +// } else { +// avoidedRoads.put(result.id, point); +// } +// if (count[0] == parsedPoints.size()) { +// completionCallback.onRDOSearchComplete(); +// } +// if (count[0]%10 == 0) { +// app.showShortToastMessage(String.format("Found %d roads", count[0])); +// } +// return true; +// } +// +// @Override +// public boolean isCancelled() { +// return false; +// } +// }); +// } - app.getLocationProvider().getMultipleRouteSegmentsIds(parsedPoints, appMode, false, new ResultMatcher>() { + app.getLocationProvider().getMultipleRouteSegmentsIds(parsedPoints, appMode, false, + new ResultMatcher>() { @Override public boolean publish(Map result) { @@ -139,7 +177,7 @@ public class AvoidRoadsHelper { parsePointsFromJson(is, result); return result; } catch (Exception e) { - LOG.error("Error reading json url!"); + LOG.error("Error reading json !"); } finally { if (is != null) { try { @@ -195,12 +233,34 @@ public class AvoidRoadsHelper { private void parsePointsFromJson(InputStream is, List result) { Gson gson = new Gson(); GeoJSON geoJSON = gson.fromJson(new BufferedReader(new InputStreamReader(is)), GeoJSON.class); + double minlat = 0 , maxlat = 0, minlon = 0, maxlon= 0; + boolean first = true; for (Point o : geoJSON.points) { Location ll = new Location("geoJSON"); - ll.setLatitude(o.geo.coordinates.get(1)); - ll.setLongitude(o.geo.coordinates.get(0)); + double lat = o.geo.coordinates.get(1); + double lon = o.geo.coordinates.get(0); + if(first) { + minlat = maxlat = lat; + minlon = maxlon = lon; + first = false; + } else { + minlat = Math.min(minlat, lat); + minlon = Math.min(minlon, lon); + maxlat = Math.max(maxlat, lat); + maxlon = Math.max(maxlon, lon); + } + ll.setLatitude(lat); + ll.setLongitude(lon); result.add(ll); } + QuadRect qr = new QuadRect(minlon, minlat, maxlon, maxlat); + QuadTree qt = new QuadTree(qr, 8, 0.55f); + for(Location l : result) { + qt.insert(l, (float)l.getLongitude(), (float) l.getLatitude()); + } + qt.queryInBox(qr, result); + + app.showShortToastMessage(String.format("Loaded and parsed %d avoid points from JSON. Starting segment search.", result.size())); LOG.debug(String.format("Points parsed: %d", result.size())); }