Point list to quadtree
This commit is contained in:
parent
41b4e81fa0
commit
53268f462a
5 changed files with 89 additions and 23 deletions
|
@ -183,8 +183,13 @@ public class GeocodingUtilities {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Collections.sort(lst, GeocodingUtilities.DISTANCE_COMPARATOR);
|
Collections.sort(lst, GeocodingUtilities.DISTANCE_COMPARATOR);
|
||||||
|
if (lst.size() > 0) {
|
||||||
result.put(lst.get(0).point.getRoad().id, point);
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -92,10 +92,10 @@ public class RoutingContext {
|
||||||
public int memoryOverhead = 0;
|
public int memoryOverhead = 0;
|
||||||
|
|
||||||
|
|
||||||
long timeNanoToCalcDeviation = 0;
|
public long timeNanoToCalcDeviation = 0;
|
||||||
long timeToLoad = 0;
|
public long timeToLoad = 0;
|
||||||
long timeToLoadHeaders = 0;
|
public long timeToLoadHeaders = 0;
|
||||||
long timeToFindInitialSegments = 0;
|
public long timeToFindInitialSegments = 0;
|
||||||
public long timeToCalculate = 0;
|
public long timeToCalculate = 0;
|
||||||
|
|
||||||
int distinctLoadedTiles = 0;
|
int distinctLoadedTiles = 0;
|
||||||
|
@ -289,6 +289,7 @@ public class RoutingContext {
|
||||||
public void loadSubregionTile(final RoutingSubregionTile ts, boolean loadObjectsInMemory, List<RouteDataObject> toLoad, TLongHashSet excludeNotAllowed) {
|
public void loadSubregionTile(final RoutingSubregionTile ts, boolean loadObjectsInMemory, List<RouteDataObject> toLoad, TLongHashSet excludeNotAllowed) {
|
||||||
boolean wasUnloaded = ts.isUnloaded();
|
boolean wasUnloaded = ts.isUnloaded();
|
||||||
int ucount = ts.getUnloadCont();
|
int ucount = ts.getUnloadCont();
|
||||||
|
|
||||||
if (nativeLib == null) {
|
if (nativeLib == null) {
|
||||||
long now = System.nanoTime();
|
long now = System.nanoTime();
|
||||||
try {
|
try {
|
||||||
|
@ -321,7 +322,7 @@ public class RoutingContext {
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException("Loading data exception", e);
|
throw new RuntimeException("Loading data exception", e);
|
||||||
}
|
}
|
||||||
|
// log.debug(String.format("Load subregion: %s", ts.subregion.filePointer));
|
||||||
timeToLoad += (System.nanoTime() - now);
|
timeToLoad += (System.nanoTime() - now);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -188,9 +188,9 @@ public class CurrentPositionHelper {
|
||||||
boolean allowEmptyNames,
|
boolean allowEmptyNames,
|
||||||
@Nullable ApplicationMode appMode) {
|
@Nullable ApplicationMode appMode) {
|
||||||
|
|
||||||
List<BinaryMapReaderResource> checkReaders = new ArrayList<>();
|
List<BinaryMapReaderResource> checkReaders = usedReaders;
|
||||||
for (Location loc : points) {
|
for (Location loc : points) {
|
||||||
checkReaders.addAll(checkReaders(loc.getLatitude(), loc.getLongitude(), usedReaders));
|
checkReaders = checkReaders(loc.getLatitude(), loc.getLongitude(), checkReaders);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (appMode == null) {
|
if (appMode == null) {
|
||||||
|
@ -230,11 +230,11 @@ public class CurrentPositionHelper {
|
||||||
for (BinaryMapReaderResource rep : checkReaders) {
|
for (BinaryMapReaderResource rep : checkReaders) {
|
||||||
rs[i++] = rep.getReader(BinaryMapReaderResourceType.STREET_LOOKUP);
|
rs[i++] = rep.getReader(BinaryMapReaderResourceType.STREET_LOOKUP);
|
||||||
}
|
}
|
||||||
RoutingConfiguration cfg = app.getRoutingConfig().build(p, 10,
|
RoutingConfiguration cfg = app.getRoutingConfig().build(p, 100,
|
||||||
new HashMap<String, String>());
|
new HashMap<String, String>());
|
||||||
cfg.routeCalculationTime = System.currentTimeMillis();
|
cfg.routeCalculationTime = System.currentTimeMillis();
|
||||||
ctx = new RoutePlannerFrontEnd().buildRoutingContext(cfg, null, rs);
|
ctx = new RoutePlannerFrontEnd().buildRoutingContext(cfg, null, rs);
|
||||||
RoutingConfiguration defCfg = app.getRoutingConfig().build("geocoding", 10,
|
RoutingConfiguration defCfg = app.getRoutingConfig().build("geocoding", 100,
|
||||||
new HashMap<String, String>());
|
new HashMap<String, String>());
|
||||||
defCtx = new RoutePlannerFrontEnd().buildRoutingContext(defCfg, null, rs);
|
defCtx = new RoutePlannerFrontEnd().buildRoutingContext(defCfg, null, rs);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -979,8 +979,8 @@ public class MapActivityActions implements DialogProvider {
|
||||||
@Override
|
@Override
|
||||||
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked, int[] viewCoordinates) {
|
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked, int[] viewCoordinates) {
|
||||||
app.logEvent("drawer_import_avoid_roads");
|
app.logEvent("drawer_import_avoid_roads");
|
||||||
// app.getAvoidRoadsHelper().testRun();
|
app.getAvoidRoadsHelper().testRun();
|
||||||
app.getAvoidRoadsHelper().testRunDownload();
|
// app.getAvoidRoadsHelper().testRunDownload();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}).createItem());
|
}).createItem());
|
||||||
|
|
|
@ -11,6 +11,9 @@ import net.osmand.IndexConstants;
|
||||||
import net.osmand.Location;
|
import net.osmand.Location;
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
import net.osmand.ResultMatcher;
|
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.osm.io.NetworkUtils;
|
||||||
import net.osmand.plus.ApplicationMode;
|
import net.osmand.plus.ApplicationMode;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
|
@ -27,6 +30,7 @@ import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -64,6 +68,7 @@ public class AvoidRoadsHelper {
|
||||||
completionCallback = new CompletionCallback() {
|
completionCallback = new CompletionCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onRDOSearchComplete() {
|
public void onRDOSearchComplete() {
|
||||||
|
|
||||||
if (saveResultToFile) {
|
if (saveResultToFile) {
|
||||||
File out = new File (app.getAppPath(IndexConstants.AVOID_ROADS_DIR).getAbsolutePath() + "/"
|
File out = new File (app.getAppPath(IndexConstants.AVOID_ROADS_DIR).getAbsolutePath() + "/"
|
||||||
+ "processed_ids.json");
|
+ "processed_ids.json");
|
||||||
|
@ -80,11 +85,15 @@ public class AvoidRoadsHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRun() {
|
public void testRun() {
|
||||||
File in = new File(app.getAppPath(IndexConstants.AVOID_ROADS_DIR).getAbsolutePath() + "/" + inputFileName);
|
// File in = new File(app.getAppPath(IndexConstants.AVOID_ROADS_DIR).getAbsolutePath() + "/" + inputFileName);
|
||||||
LOG.debug(String.format("Input json: %s", in.getAbsolutePath()));
|
// LOG.debug(String.format("Input json: %s", in.getAbsolutePath()));
|
||||||
if (in.exists()) {
|
// if (in.exists()) {
|
||||||
loadJson(in.getAbsolutePath(), FROM_STORAGE);
|
// 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() {
|
public void testRunDownload() {
|
||||||
|
@ -94,11 +103,40 @@ public class AvoidRoadsHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void convertPointsToRDO(List<Location> parsedPoints) {
|
public void convertPointsToRDO(final List<Location> parsedPoints) {
|
||||||
|
final Map<Long, Location> avoidedRoads = new HashMap<>();
|
||||||
|
final long timeStart = System.currentTimeMillis();
|
||||||
|
final int[] count = {0};
|
||||||
this.roadsToAvoid.clear();
|
this.roadsToAvoid.clear();
|
||||||
|
// for (final Location point : parsedPoints) {
|
||||||
|
//
|
||||||
|
// app.getLocationProvider().getRouteSegment(point, appMode, false, new ResultMatcher<RouteDataObject>() {
|
||||||
|
// @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<Map<Long, Location>>() {
|
app.getLocationProvider().getMultipleRouteSegmentsIds(parsedPoints, appMode, false,
|
||||||
|
new ResultMatcher<Map<Long, Location>>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean publish(Map<Long, Location> result) {
|
public boolean publish(Map<Long, Location> result) {
|
||||||
|
|
||||||
|
@ -139,7 +177,7 @@ public class AvoidRoadsHelper {
|
||||||
parsePointsFromJson(is, result);
|
parsePointsFromJson(is, result);
|
||||||
return result;
|
return result;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.error("Error reading json url!");
|
LOG.error("Error reading json !");
|
||||||
} finally {
|
} finally {
|
||||||
if (is != null) {
|
if (is != null) {
|
||||||
try {
|
try {
|
||||||
|
@ -195,12 +233,34 @@ public class AvoidRoadsHelper {
|
||||||
private void parsePointsFromJson(InputStream is, List<Location> result) {
|
private void parsePointsFromJson(InputStream is, List<Location> result) {
|
||||||
Gson gson = new Gson();
|
Gson gson = new Gson();
|
||||||
GeoJSON geoJSON = gson.fromJson(new BufferedReader(new InputStreamReader(is)), GeoJSON.class);
|
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) {
|
for (Point o : geoJSON.points) {
|
||||||
Location ll = new Location("geoJSON");
|
Location ll = new Location("geoJSON");
|
||||||
ll.setLatitude(o.geo.coordinates.get(1));
|
double lat = o.geo.coordinates.get(1);
|
||||||
ll.setLongitude(o.geo.coordinates.get(0));
|
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);
|
result.add(ll);
|
||||||
}
|
}
|
||||||
|
QuadRect qr = new QuadRect(minlon, minlat, maxlon, maxlat);
|
||||||
|
QuadTree<Location> qt = new QuadTree<Location>(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()));
|
LOG.debug(String.format("Points parsed: %d", result.size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue