Different straightening algorithm, dist based instead of time based.
Added a 30-meter distance check to prevent big editing disasters but I'm not fully satisfied with this feature yet. I think this is a little better than before though.
This commit is contained in:
parent
a181d67150
commit
2899bb992d
1 changed files with 20 additions and 7 deletions
|
@ -638,21 +638,34 @@ class TrackFragment : Fragment(), MapListener, YesNoDialog.YesNoDialogListener
|
||||||
|
|
||||||
fun straighten_points(a: Trkpt, b: Trkpt)
|
fun straighten_points(a: Trkpt, b: Trkpt)
|
||||||
{
|
{
|
||||||
|
val al = a.toLocation()
|
||||||
|
val bl = b.toLocation()
|
||||||
val subtrack = Track(track.database, track.device_id)
|
val subtrack = Track(track.database, track.device_id)
|
||||||
subtrack.load_trkpts(trackbook.database.select_trkpt_start_end(
|
subtrack.load_trkpts(trackbook.database.select_trkpt_start_end(
|
||||||
track.device_id,
|
track.device_id,
|
||||||
start_time=min(a.time, b.time),
|
start_time=min(a.time, b.time),
|
||||||
end_time=max(a.time, b.time),
|
end_time=max(a.time, b.time),
|
||||||
|
max_accuracy=PreferencesHelper.load_max_accuracy(),
|
||||||
))
|
))
|
||||||
val lat_step = (b.latitude - a.latitude) / (b.time - a.time)
|
val lat_span = b.latitude - a.latitude
|
||||||
val lon_step = (b.longitude - a.longitude) / (b.time - a.time)
|
val lon_span = b.longitude - a.longitude
|
||||||
val ele_step = (b.altitude - a.altitude) / (b.time - a.time)
|
val ele_span = b.altitude - a.altitude
|
||||||
for (trkpt in subtrack.trkpts)
|
for (trkpt in subtrack.trkpts)
|
||||||
{
|
{
|
||||||
val index = trkpt.time - a.time
|
val new_location = Location("test")
|
||||||
trkpt.latitude = a.latitude + (index * lat_step)
|
val tl = trkpt.toLocation()
|
||||||
trkpt.longitude = a.longitude + (index * lon_step)
|
val dist_a = tl.distanceTo(al)
|
||||||
trkpt.altitude = a.altitude + (index * ele_step)
|
val dist_b = tl.distanceTo(bl)
|
||||||
|
val proportion = dist_a / (dist_a + dist_b)
|
||||||
|
new_location.latitude = a.latitude + (lat_span * proportion)
|
||||||
|
new_location.longitude = a.longitude + (lon_span * proportion)
|
||||||
|
if (trkpt.toLocation().distanceTo(new_location) > 30.0)
|
||||||
|
{
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
trkpt.latitude = new_location.latitude
|
||||||
|
trkpt.longitude = new_location.longitude
|
||||||
|
trkpt.altitude = a.altitude + (ele_span * proportion)
|
||||||
trackbook.database.update_trkpt(trkpt, commit=false)
|
trackbook.database.update_trkpt(trkpt, commit=false)
|
||||||
}
|
}
|
||||||
trackbook.database.commit()
|
trackbook.database.commit()
|
||||||
|
|
Loading…
Reference in a new issue