use of net.osmand.GPXUtilities.TrkSegment in project OsmAnd-tools by osmandapp.
the class OsmAndMapsService method routing.
public synchronized List<RouteSegmentResult> routing(String routeMode, Map<String, Object> props, LatLon start, LatLon end, List<LatLon> intermediates) throws IOException, InterruptedException {
QuadRect points = points(intermediates, start, end);
RoutePlannerFrontEnd router = new RoutePlannerFrontEnd();
RoutingServerConfigEntry[] rsc = new RoutingServerConfigEntry[1];
RoutingContext ctx = prepareRouterContext(routeMode, points, router, rsc);
if (rsc[0] != null) {
StringBuilder url = new StringBuilder(rsc[0].url);
url.append(String.format("?point=%.6f,%.6f", start.getLatitude(), start.getLongitude()));
url.append(String.format("&point=%.6f,%.6f", end.getLatitude(), end.getLongitude()));
RestTemplate restTemplate = new RestTemplate();
restTemplate.setErrorHandler(new DefaultResponseErrorHandler() {
@Override
public void handleError(ClientHttpResponse response) throws IOException {
LOGGER.error(String.format("Error handling url for %s : %s", routeMode, url.toString()));
super.handleError(response);
}
});
String gpx = restTemplate.getForObject(url.toString(), String.class);
GPXFile file = GPXUtilities.loadGPXFile(new ByteArrayInputStream(gpx.getBytes()));
TrkSegment trkSegment = file.tracks.get(0).segments.get(0);
List<LatLon> polyline = new ArrayList<LatLon>(trkSegment.points.size());
for (WptPt p : trkSegment.points) {
polyline.add(new LatLon(p.lat, p.lon));
}
return approximate(ctx, router, props, polyline);
} else {
PrecalculatedRouteDirection precalculatedRouteDirection = null;
List<RouteSegmentResult> route = router.searchRoute(ctx, start, end, intermediates, precalculatedRouteDirection);
putResultProps(ctx, route, props);
return route;
}
}
use of net.osmand.GPXUtilities.TrkSegment in project OsmAnd-tools by osmandapp.
the class MapRouterLayer method calculateAltitude.
protected GPXFile calculateAltitude(GPXFile gpxFile, File[] missingFile) {
File srtmFolder = new File(DataExtractionSettings.getSettings().getBinaryFilesDir(), "srtm");
if (!srtmFolder.exists()) {
return null;
}
IndexHeightData hd = new IndexHeightData();
hd.setSrtmData(srtmFolder);
for (Track tr : gpxFile.tracks) {
for (TrkSegment s : tr.segments) {
for (int i = 0; i < s.points.size(); i++) {
WptPt wpt = s.points.get(i);
double h = hd.getPointHeight(wpt.lat, wpt.lon, missingFile);
if (h != IndexHeightData.INEXISTENT_HEIGHT) {
wpt.ele = h;
} else if (i == 0) {
return null;
}
}
}
}
return gpxFile;
}
use of net.osmand.GPXUtilities.TrkSegment in project OsmAnd-tools by osmandapp.
the class MapRouterLayer method displayGpxFiles.
private void displayGpxFiles() {
DataTileManager<Entity> points = new DataTileManager<Entity>(9);
if (selectedGPXFile != null) {
for (Track t : selectedGPXFile.tracks) {
for (TrkSegment ts : t.segments) {
Way w = new Way(-1);
int id = 0;
for (WptPt p : ts.points) {
net.osmand.osm.edit.Node n = new net.osmand.osm.edit.Node(p.lat, p.lon, -1);
w.addNode(n);
n.putTag(OSMTagKey.NAME.getValue(), String.valueOf(id));
n.putTag("gpx", "yes");
n.putTag("colour", "blue");
points.registerObject(n.getLatitude(), n.getLongitude(), n);
id++;
}
w.putTag("gpx", "yes");
w.putTag("colour", "green");
LatLon n = w.getLatLon();
points.registerObject(n.getLatitude(), n.getLongitude(), w);
}
}
}
if (directionPointsFile != null) {
List<net.osmand.osm.edit.Node> pnts = directionPointsFile.queryInBox(new QuadRect(0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE), new ArrayList<net.osmand.osm.edit.Node>());
for (net.osmand.osm.edit.Node n : pnts) {
points.registerObject(n.getLatitude(), n.getLongitude(), n);
}
}
// load from file
map.setPoints(points);
}
use of net.osmand.GPXUtilities.TrkSegment in project OsmAnd-tools by osmandapp.
the class OsmAndMapsService method gpxApproximation.
public synchronized List<RouteSegmentResult> gpxApproximation(String routeMode, Map<String, Object> props, GPXFile file) throws IOException, InterruptedException {
if (!file.hasTrkPt()) {
return Collections.emptyList();
}
TrkSegment trkSegment = file.tracks.get(0).segments.get(0);
List<LatLon> polyline = new ArrayList<LatLon>(trkSegment.points.size());
for (WptPt p : trkSegment.points) {
polyline.add(new LatLon(p.lat, p.lon));
}
QuadRect points = points(polyline, null, null);
if (!validateAndInitConfig() || points == null) {
return Collections.emptyList();
}
RoutePlannerFrontEnd router = new RoutePlannerFrontEnd();
RoutingContext ctx = prepareRouterContext(routeMode, points, router, null);
List<RouteSegmentResult> route = approximate(ctx, router, props, polyline);
return route;
}
use of net.osmand.GPXUtilities.TrkSegment in project OsmAnd-tools by osmandapp.
the class MapPanelSelector method drawGpxFiles.
private void drawGpxFiles(Collection<GPXFile> files) {
DataTileManager<Entity> points = new DataTileManager<>(4);
List<Way> ways = new ArrayList<>();
for (GPXFile file : files) {
for (Track track : file.tracks) {
for (TrkSegment segment : track.segments) {
Way w = new Way(-1);
for (WptPt point : segment.points) {
w.addNode(new Node(point.lat, point.lon, -1));
}
ways.add(w);
}
}
for (Way w : ways) {
LatLon n = w.getLatLon();
points.registerObject(n.getLatitude(), n.getLongitude(), w);
}
panel.setPoints(points);
}
}
Aggregations