Search in sources :

Example 1 with TrkSegment

use of net.osmand.plus.GPXUtilities.TrkSegment in project Osmand by osmandapp.

the class RouteProvider method findBROUTERRoute.

protected RouteCalculationResult findBROUTERRoute(RouteCalculationParams params) throws MalformedURLException, IOException, ParserConfigurationException, FactoryConfigurationError, SAXException {
    int numpoints = 2 + (params.intermediates != null ? params.intermediates.size() : 0);
    double[] lats = new double[numpoints];
    double[] lons = new double[numpoints];
    int index = 0;
    String mode;
    lats[index] = params.start.getLatitude();
    lons[index] = params.start.getLongitude();
    index++;
    if (params.intermediates != null && params.intermediates.size() > 0) {
        for (LatLon il : params.intermediates) {
            lats[index] = il.getLatitude();
            lons[index] = il.getLongitude();
            index++;
        }
    }
    lats[index] = params.end.getLatitude();
    lons[index] = params.end.getLongitude();
    if (ApplicationMode.PEDESTRIAN == params.mode) {
        // $NON-NLS-1$
        mode = "foot";
    } else if (ApplicationMode.BICYCLE == params.mode) {
        // $NON-NLS-1$
        mode = "bicycle";
    } else {
        // $NON-NLS-1$
        mode = "motorcar";
    }
    Bundle bpars = new Bundle();
    bpars.putDoubleArray("lats", lats);
    bpars.putDoubleArray("lons", lons);
    bpars.putString("fast", params.fast ? "1" : "0");
    bpars.putString("v", mode);
    bpars.putString("trackFormat", "gpx");
    OsmandApplication ctx = (OsmandApplication) params.ctx;
    List<Location> res = new ArrayList<Location>();
    IBRouterService brouterService = ctx.getBRouterService();
    if (brouterService == null) {
        return new RouteCalculationResult("BRouter service is not available");
    }
    try {
        String gpxMessage = brouterService.getTrackFromParams(bpars);
        if (gpxMessage == null)
            gpxMessage = "no result from brouter";
        if (!gpxMessage.startsWith("<")) {
            return new RouteCalculationResult(gpxMessage);
        }
        GPXFile gpxFile = GPXUtilities.loadGPXFile(ctx, new ByteArrayInputStream(gpxMessage.getBytes("UTF-8")));
        for (Track track : gpxFile.tracks) {
            for (TrkSegment ts : track.segments) {
                for (WptPt p : ts.points) {
                    // $NON-NLS-1$
                    Location l = new Location("router");
                    l.setLatitude(p.lat);
                    l.setLongitude(p.lon);
                    if (p.ele != Double.NaN) {
                        l.setAltitude(p.ele);
                    }
                    res.add(l);
                }
            }
        }
    } catch (Exception e) {
        // $NON-NLS-1$
        return new RouteCalculationResult("Exception calling BRouter: " + e);
    }
    return new RouteCalculationResult(res, null, params, null, true);
}
Also used : WptPt(net.osmand.plus.GPXUtilities.WptPt) OsmandApplication(net.osmand.plus.OsmandApplication) Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) TrkSegment(net.osmand.plus.GPXUtilities.TrkSegment) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) LocationPoint(net.osmand.data.LocationPoint) JSONException(org.json.JSONException) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) LatLon(net.osmand.data.LatLon) ByteArrayInputStream(java.io.ByteArrayInputStream) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) IBRouterService(btools.routingapp.IBRouterService) Track(net.osmand.plus.GPXUtilities.Track) Location(net.osmand.Location)

Example 2 with TrkSegment

use of net.osmand.plus.GPXUtilities.TrkSegment in project Osmand by osmandapp.

the class SavingTrackHelper method collectDBTracks.

private void collectDBTracks(SQLiteDatabase db, Map<String, GPXFile> dataTracks) {
    Cursor query = db.rawQuery(// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    "SELECT " + TRACK_COL_LAT + "," + TRACK_COL_LON + "," + TRACK_COL_ALTITUDE + "," + TRACK_COL_SPEED + "," + TRACK_COL_HDOP + "," + TRACK_COL_DATE + " FROM " + TRACK_NAME + " ORDER BY " + TRACK_COL_DATE + " ASC", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    null);
    long previousTime = 0;
    long previousInterval = 0;
    TrkSegment segment = null;
    Track track = null;
    if (query.moveToFirst()) {
        do {
            WptPt pt = new WptPt();
            pt.lat = query.getDouble(0);
            pt.lon = query.getDouble(1);
            pt.ele = query.getDouble(2);
            pt.speed = query.getDouble(3);
            pt.hdop = query.getDouble(4);
            long time = query.getLong(5);
            pt.time = time;
            long currentInterval = Math.abs(time - previousTime);
            boolean newInterval = pt.lat == 0 && pt.lon == 0;
            if (track != null && !newInterval && (!ctx.getSettings().AUTO_SPLIT_RECORDING.get() || currentInterval < 6 * 60 * 1000 || currentInterval < 10 * previousInterval)) {
                // 6 minute - same segment
                segment.points.add(pt);
            } else if (track != null && (ctx.getSettings().AUTO_SPLIT_RECORDING.get() && currentInterval < 2 * 60 * 60 * 1000)) {
                // 2 hour - same track
                segment = new TrkSegment();
                if (!newInterval) {
                    segment.points.add(pt);
                }
                track.segments.add(segment);
            } else {
                // check if date the same - new track otherwise new file
                track = new Track();
                segment = new TrkSegment();
                track.segments.add(segment);
                if (!newInterval) {
                    segment.points.add(pt);
                }
                // $NON-NLS-1$
                String date = DateFormat.format("yyyy-MM-dd", time).toString();
                if (dataTracks.containsKey(date)) {
                    GPXFile gpx = dataTracks.get(date);
                    gpx.tracks.add(track);
                } else {
                    GPXFile file = new GPXFile();
                    file.tracks.add(track);
                    dataTracks.put(date, file);
                }
            }
            previousInterval = currentInterval;
            previousTime = time;
        } while (query.moveToNext());
    }
    query.close();
}
Also used : WptPt(net.osmand.plus.GPXUtilities.WptPt) TrkSegment(net.osmand.plus.GPXUtilities.TrkSegment) Cursor(android.database.Cursor) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) Track(net.osmand.plus.GPXUtilities.Track)

Example 3 with TrkSegment

use of net.osmand.plus.GPXUtilities.TrkSegment in project Osmand by osmandapp.

the class GPXLayer method onPrepareBufferImage.

@Override
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
    if (points != null) {
        updatePaints(0, false, false, settings, tileBox);
        for (TrkSegment ts : points) ts.drawRenderers(view.getZoom(), paint, canvas, tileBox);
    } else {
        List<SelectedGpxFile> selectedGPXFiles = selectedGpxHelper.getSelectedGPXFiles();
        cache.clear();
        currentTrackColor = view.getSettings().CURRENT_TRACK_COLOR.get();
        if (!selectedGPXFiles.isEmpty()) {
            drawSelectedFilesSegments(canvas, tileBox, selectedGPXFiles, settings);
            canvas.rotate(-tileBox.getRotate(), tileBox.getCenterPixelX(), tileBox.getCenterPixelY());
            if (trackChartPoints != null) {
                drawXAxisPoints(canvas, tileBox);
            }
            drawSelectedFilesSplits(canvas, tileBox, selectedGPXFiles, settings);
            drawSelectedFilesPoints(canvas, tileBox, selectedGPXFiles);
        }
        if (textLayer != null && textLayer.isVisible()) {
            textLayer.putData(this, cache);
        }
    }
}
Also used : SelectedGpxFile(net.osmand.plus.GpxSelectionHelper.SelectedGpxFile) TrkSegment(net.osmand.plus.GPXUtilities.TrkSegment)

Example 4 with TrkSegment

use of net.osmand.plus.GPXUtilities.TrkSegment in project Osmand by osmandapp.

the class TrackDetailsMenu method getRect.

private QuadRect getRect(LineChart chart, float startPos, float endPos) {
    double left = 0, right = 0;
    double top = 0, bottom = 0;
    List<ILineDataSet> ds = chart.getLineData().getDataSets();
    if (ds != null && ds.size() > 0) {
        TrkSegment segment = getTrackSegment(chart);
        OrderedLineDataSet dataSet = (OrderedLineDataSet) ds.get(0);
        if (gpxItem.chartAxisType == GPXDataSetAxisType.TIME) {
            float startTime = startPos * 1000;
            float endTime = endPos * 1000;
            for (WptPt p : segment.points) {
                if (p.time - gpxItem.analysis.startTime >= startTime && p.time - gpxItem.analysis.startTime <= endTime) {
                    if (left == 0 && right == 0) {
                        left = p.getLongitude();
                        right = p.getLongitude();
                        top = p.getLatitude();
                        bottom = p.getLatitude();
                    } else {
                        left = Math.min(left, p.getLongitude());
                        right = Math.max(right, p.getLongitude());
                        top = Math.max(top, p.getLatitude());
                        bottom = Math.min(bottom, p.getLatitude());
                    }
                }
            }
        } else {
            float startDistance = startPos * dataSet.getDivX();
            float endDistance = endPos * dataSet.getDivX();
            double previousSplitDistance = 0;
            for (int i = 0; i < segment.points.size(); i++) {
                WptPt currentPoint = segment.points.get(i);
                if (i != 0) {
                    WptPt previousPoint = segment.points.get(i - 1);
                    if (currentPoint.distance < previousPoint.distance) {
                        previousSplitDistance += previousPoint.distance;
                    }
                }
                if (previousSplitDistance + currentPoint.distance >= startDistance && previousSplitDistance + currentPoint.distance <= endDistance) {
                    if (left == 0 && right == 0) {
                        left = currentPoint.getLongitude();
                        right = currentPoint.getLongitude();
                        top = currentPoint.getLatitude();
                        bottom = currentPoint.getLatitude();
                    } else {
                        left = Math.min(left, currentPoint.getLongitude());
                        right = Math.max(right, currentPoint.getLongitude());
                        top = Math.max(top, currentPoint.getLatitude());
                        bottom = Math.min(bottom, currentPoint.getLatitude());
                    }
                }
            }
        }
    }
    return new QuadRect(left, top, right, bottom);
}
Also used : WptPt(net.osmand.plus.GPXUtilities.WptPt) ILineDataSet(com.github.mikephil.charting.interfaces.datasets.ILineDataSet) OrderedLineDataSet(net.osmand.plus.helpers.GpxUiHelper.OrderedLineDataSet) TrkSegment(net.osmand.plus.GPXUtilities.TrkSegment) QuadRect(net.osmand.data.QuadRect)

Example 5 with TrkSegment

use of net.osmand.plus.GPXUtilities.TrkSegment in project Osmand by osmandapp.

the class MeasurementToolLayer method onDraw.

@Override
public void onDraw(Canvas canvas, RotatedTileBox tb, DrawSettings settings) {
    if (inMeasurementMode) {
        lineAttrs.updatePaints(view, settings, tb);
        if (editingCtx.getSelectedPointPosition() == -1) {
            drawCenterIcon(canvas, tb, tb.getCenterPixelPoint(), settings.isNightMode());
            if (measureDistanceToCenterListener != null) {
                float distance = 0;
                if (editingCtx.getPointsCount() > 0) {
                    WptPt lastPoint = editingCtx.getPoints().get(editingCtx.getPointsCount() - 1);
                    LatLon centerLatLon = tb.getCenterLatLon();
                    distance = (float) MapUtils.getDistance(lastPoint.lat, lastPoint.lon, centerLatLon.getLatitude(), centerLatLon.getLongitude());
                }
                measureDistanceToCenterListener.onMeasure(distance);
            }
        }
        TrkSegment before = editingCtx.getBeforeTrkSegmentLine();
        TrkSegment after = editingCtx.getAfterTrkSegmentLine();
        if (before.points.size() > 0 || after.points.size() > 0) {
            path.reset();
            tx.reset();
            ty.reset();
            if (before.points.size() > 0) {
                WptPt pt = before.points.get(before.points.size() - 1);
                int locX = tb.getPixXFromLonNoRot(pt.lon);
                int locY = tb.getPixYFromLatNoRot(pt.lat);
                tx.add(locX);
                ty.add(locY);
                tx.add(tb.getCenterPixelX());
                ty.add(tb.getCenterPixelY());
            }
            if (after.points.size() > 0) {
                if (before.points.size() == 0) {
                    tx.add(tb.getCenterPixelX());
                    ty.add(tb.getCenterPixelY());
                }
                WptPt pt = after.points.get(0);
                int locX = tb.getPixXFromLonNoRot(pt.lon);
                int locY = tb.getPixYFromLatNoRot(pt.lat);
                tx.add(locX);
                ty.add(locY);
            }
            calculatePath(tb, tx, ty, path);
            canvas.drawPath(path, lineAttrs.paint);
        }
        List<WptPt> points = new ArrayList<>();
        points.addAll(editingCtx.getBeforePoints());
        points.addAll(editingCtx.getAfterPoints());
        overlapped = false;
        int drawn = 0;
        for (int i = 0; i < points.size(); i++) {
            WptPt pt = points.get(i);
            int locX = tb.getPixXFromLonNoRot(pt.lon);
            int locY = tb.getPixYFromLatNoRot(pt.lat);
            if (locX >= 0 && locX <= tb.getPixWidth() && locY >= 0 && locY <= tb.getPixHeight()) {
                drawn++;
                if (drawn > POINTS_TO_DRAW) {
                    overlapped = true;
                    break;
                }
            }
        }
        if (overlapped) {
            WptPt pt = points.get(0);
            int locX = tb.getPixXFromLonNoRot(pt.lon);
            int locY = tb.getPixYFromLatNoRot(pt.lat);
            if (locX >= 0 && locX <= tb.getPixWidth() && locY >= 0 && locY <= tb.getPixHeight()) {
                canvas.drawBitmap(pointIcon, locX - marginPointIconX, locY - marginPointIconY, bitmapPaint);
            }
            pt = points.get(points.size() - 1);
            locX = tb.getPixXFromLonNoRot(pt.lon);
            locY = tb.getPixYFromLatNoRot(pt.lat);
            if (locX >= 0 && locX <= tb.getPixWidth() && locY >= 0 && locY <= tb.getPixHeight()) {
                canvas.drawBitmap(pointIcon, locX - marginPointIconX, locY - marginPointIconY, bitmapPaint);
            }
        } else {
            for (int i = 0; i < points.size(); i++) {
                WptPt pt = points.get(i);
                int locX = tb.getPixXFromLonNoRot(pt.lon);
                int locY = tb.getPixYFromLatNoRot(pt.lat);
                if (locX >= 0 && locX <= tb.getPixWidth() && locY >= 0 && locY <= tb.getPixHeight()) {
                    canvas.drawBitmap(pointIcon, locX - marginPointIconX, locY - marginPointIconY, bitmapPaint);
                }
            }
        }
        if (editingCtx.getSelectedPointPosition() != -1) {
            int locX = tb.getCenterPixelX();
            int locY = tb.getCenterPixelY();
            canvas.drawBitmap(applyingPointIcon, locX - marginApplyingPointIconX, locY - marginApplyingPointIconY, bitmapPaint);
        }
    }
}
Also used : WptPt(net.osmand.plus.GPXUtilities.WptPt) LatLon(net.osmand.data.LatLon) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) TrkSegment(net.osmand.plus.GPXUtilities.TrkSegment) Paint(android.graphics.Paint) QuadPoint(net.osmand.data.QuadPoint)

Aggregations

TrkSegment (net.osmand.plus.GPXUtilities.TrkSegment)20 WptPt (net.osmand.plus.GPXUtilities.WptPt)12 Track (net.osmand.plus.GPXUtilities.Track)8 GPXFile (net.osmand.plus.GPXUtilities.GPXFile)6 ArrayList (java.util.ArrayList)5 LatLon (net.osmand.data.LatLon)4 TargetPoint (net.osmand.plus.TargetPointsHelper.TargetPoint)4 Paint (android.graphics.Paint)3 Location (net.osmand.Location)3 LocationPoint (net.osmand.data.LocationPoint)3 Route (net.osmand.plus.GPXUtilities.Route)3 SelectedGpxFile (net.osmand.plus.GpxSelectionHelper.SelectedGpxFile)3 ILineDataSet (com.github.mikephil.charting.interfaces.datasets.ILineDataSet)2 TIntArrayList (gnu.trove.list.array.TIntArrayList)2 File (java.io.File)2 List (java.util.List)2 GpxDataItem (net.osmand.plus.GPXDatabase.GpxDataItem)2 MapActivity (net.osmand.plus.activities.MapActivity)2 OrderedLineDataSet (net.osmand.plus.helpers.GpxUiHelper.OrderedLineDataSet)2 Renderable (net.osmand.plus.views.Renderable)2