use of net.osmand.obf.preparation.IndexHeightData 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.obf.preparation.IndexHeightData in project OsmAnd-tools by osmandapp.
the class GpxController method calculateSrtmAltitude.
public GPXFile calculateSrtmAltitude(GPXFile gpxFile, File[] missingFile) {
if (srtmLocation == null) {
return null;
}
if (srtmLocation.startsWith("http://") || srtmLocation.startsWith("https://")) {
String serverUrl = srtmLocation + "/gpx/process-srtm";
ByteArrayOutputStream baos = new ByteArrayOutputStream();
GPXUtilities.writeGpx(new OutputStreamWriter(baos), gpxFile, null);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
MultiValueMap<String, String> fileMap = new LinkedMultiValueMap<>();
ContentDisposition contentDisposition = ContentDisposition.builder("form-data").name("file").filename("route.gpx").build();
fileMap.add(HttpHeaders.CONTENT_DISPOSITION, contentDisposition.toString());
HttpEntity<byte[]> fileEntity = new HttpEntity<>(baos.toByteArray(), fileMap);
MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
body.add("file", fileEntity);
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers);
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<byte[]> response = restTemplate.postForEntity(serverUrl, requestEntity, byte[].class);
if (response.getStatusCode().is2xxSuccessful()) {
return GPXUtilities.loadGPXFile(new ByteArrayInputStream(response.getBody()));
} else {
return null;
}
} else {
File srtmFolder = new File(srtmLocation);
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;
}
Aggregations