Search in sources :

Example 1 with IndexHeightData

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;
}
Also used : WptPt(net.osmand.GPXUtilities.WptPt) IndexHeightData(net.osmand.obf.preparation.IndexHeightData) TrkSegment(net.osmand.GPXUtilities.TrkSegment) GPXFile(net.osmand.GPXUtilities.GPXFile) File(java.io.File) Track(net.osmand.GPXUtilities.Track) Point(java.awt.Point) GpxPoint(net.osmand.router.RoutePlannerFrontEnd.GpxPoint)

Example 2 with IndexHeightData

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;
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) WptPt(net.osmand.GPXUtilities.WptPt) HttpEntity(org.springframework.http.HttpEntity) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TrkSegment(net.osmand.GPXUtilities.TrkSegment) ContentDisposition(org.springframework.http.ContentDisposition) ByteArrayInputStream(java.io.ByteArrayInputStream) IndexHeightData(net.osmand.obf.preparation.IndexHeightData) RestTemplate(org.springframework.web.client.RestTemplate) OutputStreamWriter(java.io.OutputStreamWriter) GPXFile(net.osmand.GPXUtilities.GPXFile) GPXSessionFile(net.osmand.server.controllers.pub.UserSessionResources.GPXSessionFile) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile) MultiValueMap(org.springframework.util.MultiValueMap) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) Track(net.osmand.GPXUtilities.Track)

Aggregations

File (java.io.File)2 GPXFile (net.osmand.GPXUtilities.GPXFile)2 Track (net.osmand.GPXUtilities.Track)2 TrkSegment (net.osmand.GPXUtilities.TrkSegment)2 WptPt (net.osmand.GPXUtilities.WptPt)2 IndexHeightData (net.osmand.obf.preparation.IndexHeightData)2 Point (java.awt.Point)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 GpxPoint (net.osmand.router.RoutePlannerFrontEnd.GpxPoint)1 GPXSessionFile (net.osmand.server.controllers.pub.UserSessionResources.GPXSessionFile)1 ContentDisposition (org.springframework.http.ContentDisposition)1 HttpEntity (org.springframework.http.HttpEntity)1 HttpHeaders (org.springframework.http.HttpHeaders)1 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)1 MultiValueMap (org.springframework.util.MultiValueMap)1 RestTemplate (org.springframework.web.client.RestTemplate)1 MultipartFile (org.springframework.web.multipart.MultipartFile)1