Search in sources :

Example 1 with TrkSegment

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;
    }
}
Also used : WptPt(net.osmand.GPXUtilities.WptPt) DefaultResponseErrorHandler(org.springframework.web.client.DefaultResponseErrorHandler) PrecalculatedRouteDirection(net.osmand.router.PrecalculatedRouteDirection) ArrayList(java.util.ArrayList) IOException(java.io.IOException) TrkSegment(net.osmand.GPXUtilities.TrkSegment) QuadRect(net.osmand.data.QuadRect) LatLon(net.osmand.data.LatLon) RoutingContext(net.osmand.router.RoutingContext) ByteArrayInputStream(java.io.ByteArrayInputStream) RoutePlannerFrontEnd(net.osmand.router.RoutePlannerFrontEnd) RestTemplate(org.springframework.web.client.RestTemplate) GPXFile(net.osmand.GPXUtilities.GPXFile) ClientHttpResponse(org.springframework.http.client.ClientHttpResponse) RouteSegmentResult(net.osmand.router.RouteSegmentResult)

Example 2 with TrkSegment

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;
}
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 3 with TrkSegment

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);
}
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 4 with TrkSegment

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;
}
Also used : LatLon(net.osmand.data.LatLon) WptPt(net.osmand.GPXUtilities.WptPt) RoutingContext(net.osmand.router.RoutingContext) ArrayList(java.util.ArrayList) RoutePlannerFrontEnd(net.osmand.router.RoutePlannerFrontEnd) TrkSegment(net.osmand.GPXUtilities.TrkSegment) QuadRect(net.osmand.data.QuadRect) RouteSegmentResult(net.osmand.router.RouteSegmentResult)

Example 5 with TrkSegment

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);
    }
}
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)

Aggregations

TrkSegment (net.osmand.GPXUtilities.TrkSegment)8 WptPt (net.osmand.GPXUtilities.WptPt)8 GPXFile (net.osmand.GPXUtilities.GPXFile)5 Track (net.osmand.GPXUtilities.Track)5 LatLon (net.osmand.data.LatLon)5 ArrayList (java.util.ArrayList)4 QuadRect (net.osmand.data.QuadRect)4 Point (java.awt.Point)3 File (java.io.File)3 DataTileManager (net.osmand.data.DataTileManager)3 Entity (net.osmand.osm.edit.Entity)3 Way (net.osmand.osm.edit.Way)3 GpxPoint (net.osmand.router.RoutePlannerFrontEnd.GpxPoint)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 IndexHeightData (net.osmand.obf.preparation.IndexHeightData)2 RoutePlannerFrontEnd (net.osmand.router.RoutePlannerFrontEnd)2 RouteSegmentResult (net.osmand.router.RouteSegmentResult)2 RoutingContext (net.osmand.router.RoutingContext)2 Gson (com.google.gson.Gson)1