Merge pull request #3587 from saemy/brouter-elevation-info
Extracts elevation data from BRouter.
This commit is contained in:
commit
96a018d543
1 changed files with 19 additions and 36 deletions
|
@ -2,6 +2,7 @@ package net.osmand.plus.routing;
|
||||||
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
@ -1252,7 +1253,7 @@ public class RouteProvider {
|
||||||
bpars.putDoubleArray("lons", lons);
|
bpars.putDoubleArray("lons", lons);
|
||||||
bpars.putString("fast", params.fast ? "1" : "0");
|
bpars.putString("fast", params.fast ? "1" : "0");
|
||||||
bpars.putString("v", mode);
|
bpars.putString("v", mode);
|
||||||
bpars.putString("trackFormat", "kml");
|
bpars.putString("trackFormat", "gpx");
|
||||||
|
|
||||||
OsmandApplication ctx = (OsmandApplication) params.ctx;
|
OsmandApplication ctx = (OsmandApplication) params.ctx;
|
||||||
List<Location> res = new ArrayList<Location>();
|
List<Location> res = new ArrayList<Location>();
|
||||||
|
@ -1262,45 +1263,27 @@ public class RouteProvider {
|
||||||
return new RouteCalculationResult("BRouter service is not available");
|
return new RouteCalculationResult("BRouter service is not available");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
String kmlMessage = brouterService.getTrackFromParams(bpars);
|
String gpxMessage = brouterService.getTrackFromParams(bpars);
|
||||||
if (kmlMessage == null)
|
if (gpxMessage == null)
|
||||||
kmlMessage = "no result from brouter";
|
gpxMessage = "no result from brouter";
|
||||||
if (!kmlMessage.startsWith("<")) {
|
if (!gpxMessage.startsWith("<")) {
|
||||||
return new RouteCalculationResult(kmlMessage);
|
return new RouteCalculationResult(gpxMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
DocumentBuilder dom = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
GPXFile gpxFile = GPXUtilities.loadGPXFile(
|
||||||
Document doc = dom.parse(new InputSource(new StringReader(kmlMessage)));
|
ctx, new ByteArrayInputStream(gpxMessage.getBytes("UTF-8")));
|
||||||
NodeList list = doc.getElementsByTagName("coordinates"); //$NON-NLS-1$
|
|
||||||
for (int i = 0; i < list.getLength(); i++) {
|
for (Track track : gpxFile.tracks) {
|
||||||
Node item = list.item(i);
|
for (TrkSegment ts : track.segments) {
|
||||||
String str = item.getFirstChild().getNodeValue();
|
for (WptPt p : ts.points) {
|
||||||
if (str == null) {
|
Location l = new Location("router"); //$NON-NLS-1$
|
||||||
continue;
|
l.setLatitude(p.lat);
|
||||||
}
|
l.setLongitude(p.lon);
|
||||||
int st = 0;
|
if (p.ele != Double.NaN) {
|
||||||
int next = 0;
|
l.setAltitude(p.ele);
|
||||||
while ((next = str.indexOf('\n', st)) != -1) {
|
|
||||||
String coordinate = str.substring(st, next + 1);
|
|
||||||
int s = coordinate.indexOf(',');
|
|
||||||
if (s != -1) {
|
|
||||||
try {
|
|
||||||
double lon = Double.parseDouble(coordinate.substring(0, s));
|
|
||||||
double lat = Double.parseDouble(coordinate.substring(s + 1));
|
|
||||||
Location l = new Location("router"); //$NON-NLS-1$
|
|
||||||
l.setLatitude(lat);
|
|
||||||
l.setLongitude(lon);
|
|
||||||
res.add(l);
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
}
|
}
|
||||||
|
res.add(l);
|
||||||
}
|
}
|
||||||
st = next + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (list.getLength() == 0) {
|
|
||||||
if (doc.getChildNodes().getLength() == 1) {
|
|
||||||
Node item = doc.getChildNodes().item(0);
|
|
||||||
return new RouteCalculationResult(item.getNodeValue());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
Loading…
Reference in a new issue