Search in sources :

Example 1 with Track

use of net.osmand.GPXUtilities.Track 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 Track

use of net.osmand.GPXUtilities.Track 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);
}
Also used : Entity(net.osmand.osm.edit.Entity) WptPt(net.osmand.GPXUtilities.WptPt) Node(org.w3c.dom.Node) TrkSegment(net.osmand.GPXUtilities.TrkSegment) QuadRect(net.osmand.data.QuadRect) Way(net.osmand.osm.edit.Way) Point(java.awt.Point) GpxPoint(net.osmand.router.RoutePlannerFrontEnd.GpxPoint) LatLon(net.osmand.data.LatLon) DataTileManager(net.osmand.data.DataTileManager) Track(net.osmand.GPXUtilities.Track)

Example 3 with Track

use of net.osmand.GPXUtilities.Track 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);
    }
}
Also used : Entity(net.osmand.osm.edit.Entity) WptPt(net.osmand.GPXUtilities.WptPt) LatLon(net.osmand.data.LatLon) DataTileManager(net.osmand.data.DataTileManager) Node(net.osmand.osm.edit.Node) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) TrkSegment(net.osmand.GPXUtilities.TrkSegment) GPXFile(net.osmand.GPXUtilities.GPXFile) Way(net.osmand.osm.edit.Way) Track(net.osmand.GPXUtilities.Track)

Example 4 with Track

use of net.osmand.GPXUtilities.Track 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)

Example 5 with Track

use of net.osmand.GPXUtilities.Track in project OsmAnd-tools by osmandapp.

the class OsmGpxWriteContext method writeTrack.

public void writeTrack(OsmGpxFile gpxInfo, Map<String, String> extraTrackTags, GPXFile gpxFile, GPXTrackAnalysis analysis, String routeIdPrefix) throws IOException, SQLException {
    Map<String, String> gpxTrackTags = new LinkedHashMap<String, String>();
    if (qp.details < QueryParams.DETAILS_TRACKS) {
        boolean validTrack = false;
        for (Track t : gpxFile.tracks) {
            for (TrkSegment s : t.segments) {
                if (s.points.isEmpty()) {
                    continue;
                }
                if (!validatedTrackSegment(s)) {
                    continue;
                }
                validTrack = true;
            }
        }
        if (validTrack) {
            serializer.startTag(null, "node");
            serializer.attribute(null, "id", id-- + "");
            serializer.attribute(null, "action", "modify");
            serializer.attribute(null, "version", "1");
            serializer.attribute(null, "lat", latLonFormat.format(gpxFile.findPointToShow().lat));
            serializer.attribute(null, "lon", latLonFormat.format(gpxFile.findPointToShow().lon));
            tagValue(serializer, "route", "segment");
            tagValue(serializer, "route_type", "track");
            tagValue(serializer, "route_radius", gpxFile.getOuterRadius());
            addGenericTags(gpxTrackTags, null);
            addGpxInfoTags(gpxTrackTags, gpxInfo, routeIdPrefix);
            addAnalysisTags(gpxTrackTags, analysis);
            seraizeTags(extraTrackTags, gpxTrackTags);
            serializer.endTag(null, "node");
        }
    } else {
        for (Track t : gpxFile.tracks) {
            for (TrkSegment s : t.segments) {
                if (s.points.isEmpty()) {
                    continue;
                }
                if (!validatedTrackSegment(s)) {
                    continue;
                }
                segments++;
                long idStart = id;
                for (WptPt p : s.points) {
                    long nid = id--;
                    writePoint(nid, p, null, null, null);
                }
                long endid = id;
                serializer.startTag(null, "way");
                serializer.attribute(null, "id", id-- + "");
                serializer.attribute(null, "action", "modify");
                serializer.attribute(null, "version", "1");
                for (long nid = idStart; nid > endid; nid--) {
                    serializer.startTag(null, "nd");
                    serializer.attribute(null, "ref", nid + "");
                    serializer.endTag(null, "nd");
                }
                tagValue(serializer, "route", "segment");
                tagValue(serializer, "route_type", "track");
                tagValue(serializer, "route_radius", gpxFile.getOuterRadius());
                addGenericTags(gpxTrackTags, t);
                addGpxInfoTags(gpxTrackTags, gpxInfo, routeIdPrefix);
                addAnalysisTags(gpxTrackTags, analysis);
                addElevationTags(gpxTrackTags, s);
                seraizeTags(extraTrackTags, gpxTrackTags);
                serializer.endTag(null, "way");
            }
        }
        for (WptPt p : gpxFile.getPoints()) {
            long nid = id--;
            writePoint(nid, p, "point", routeIdPrefix + gpxInfo.id, gpxInfo.name);
        }
    }
    tracks++;
}
Also used : WptPt(net.osmand.GPXUtilities.WptPt) TrkSegment(net.osmand.GPXUtilities.TrkSegment) Track(net.osmand.GPXUtilities.Track)

Aggregations

Track (net.osmand.GPXUtilities.Track)5 TrkSegment (net.osmand.GPXUtilities.TrkSegment)5 WptPt (net.osmand.GPXUtilities.WptPt)5 GPXFile (net.osmand.GPXUtilities.GPXFile)3 Point (java.awt.Point)2 File (java.io.File)2 DataTileManager (net.osmand.data.DataTileManager)2 LatLon (net.osmand.data.LatLon)2 IndexHeightData (net.osmand.obf.preparation.IndexHeightData)2 Entity (net.osmand.osm.edit.Entity)2 Way (net.osmand.osm.edit.Way)2 GpxPoint (net.osmand.router.RoutePlannerFrontEnd.GpxPoint)2 TIntArrayList (gnu.trove.list.array.TIntArrayList)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 ArrayList (java.util.ArrayList)1 QuadRect (net.osmand.data.QuadRect)1 Node (net.osmand.osm.edit.Node)1 GPXSessionFile (net.osmand.server.controllers.pub.UserSessionResources.GPXSessionFile)1