Skip to content

Commit

Permalink
bugfix for border coords
Browse files Browse the repository at this point in the history
  • Loading branch information
hspitzer committed Jan 30, 2022
1 parent d45269e commit ef33f07
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions hikingmap/trackfinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from .page import Page

# global constants
max_tracks_perm_calc = 6
max_tracks_perm_calc = 1

class TrackFinder:
def __init__(self, scale, pagewidth, pageheight, pageoverlap, debugmode):
Expand Down Expand Up @@ -65,9 +65,11 @@ def calculate_pages(self, tracks):

try:
for track in trackpermutation:
#print(track)
self.pointskipped = True
prev_coord = Coordinate(0.0, 0.0)
for coord in track:
#print(coord.lon, prev_coord.lon)
prev_coord = self.__add_point(prev_coord, coord)
self.__flush()
except:
Expand Down Expand Up @@ -120,17 +122,20 @@ def __add_first_point(self, coord):

def __add_next_point(self, prev_coord, coord):
outside_page = self.currentpage.add_next_point(prev_coord, coord)

if outside_page:
self.currentpage.remove_last_point()
if not self.pointskipped:
border_coord = self.currentpage.calc_border_point(prev_coord, coord)
self.currentpage.add_next_point(prev_coord, border_coord)
if border_coord:
self.currentpage.add_next_point(prev_coord, border_coord)
self.currentpage.center_map()
self.renderedareas.append(self.currentpage)
if not self.pointskipped:
self.__add_first_point(border_coord)
self.__add_next_point(border_coord, coord)
if border_coord:
self.__add_first_point(border_coord)
self.__add_next_point(border_coord, coord)
else:
self.__add_first_point(coord)
else:
self.__add_first_point(coord)

Expand Down

4 comments on commit ef33f07

@roelderickx
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @hspitzer
Interesting bugfix. I'd expect border_coord not to be None if the next point is outside the page. Can you point me to an example gpx track demonstrating this problem?
I noticed some undesirable behaviour a while ago when a track touches the page overlap zone but returns back into the same page again. Hikingmap will create a new page anyway in this case, but I consider that incorrect. I haven't had the time to look into this issue though, but maybe it is the problem you're trying to resolve here?

@hspitzer
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @roelderickx
I implemented this fix a few months ago while I was using Hikingmap (which is awesome by the way, thanks a lot!) to prepare a large set of maps. I did not look into it too deeply, but I agree, I also would not have expected border_coord to be None, but exactly that happens with the GPX that I was using. I did not really get to the bottom of this once I figured out that with this extra check everything works as expected.
I attach the GPX that throws the error (its actually three tracks combined in one).
I'm running the following command:
hikingmap --pagewidth 28.1 --pageheight 40.4 --pageoverlap 1 --overview --gpx render_osm/data/GPX_all.gpx -- hm_render_maperitive/hm_render_maperitive.py -d 300

output and error traceback without my fix
  Reading file render_osm/data/GPX_all.gpx
Found track HRP
=> new track 0
Found track GR10
=> new track 1
Found track GR11
=> new track 2
Generating waypoints for track 0: -1.773994,43.373254 - 3.129561,42.481879
Total track distance: 741.91 km
Generating waypoints for track 1: -1.77406,43.373138 - 3.129097,42.482052
Total track distance: 892.09 km
Generating waypoints for track 2: -1.792386,43.393209 - 3.321879,42.319296
Total track distance: 818.52 km
Too many tracks to calculate all track permutations
Traceback (most recent call last):
  File "/Users/hannah.spitzer/opt/miniconda3/envs/hrp/bin/hikingmap", line 33, in <module>
    sys.exit(load_entry_point('hikingmap', 'console_scripts', 'hikingmap')())
  File "/Users/hannah.spitzer/projects/personal/render_osm/hikingmap/hikingmap/hikingmap.py", line 74, in main
    trackfinder.calculate_pages(tracks)
  File "/Users/hannah.spitzer/projects/personal/render_osm/hikingmap/hikingmap/trackfinder.py", line 80, in calculate_pages
    prev_coord = self.__add_point(prev_coord, coord)
  File "/Users/hannah.spitzer/projects/personal/render_osm/hikingmap/hikingmap/trackfinder.py", line 101, in __add_point
    prev_coord = self.__add_next_point(prev_coord, coord)
  File "/Users/hannah.spitzer/projects/personal/render_osm/hikingmap/hikingmap/trackfinder.py", line 137, in __add_next_point
    self.__currentpage.add_next_point(border_coord)
  File "/Users/hannah.spitzer/projects/personal/render_osm/hikingmap/hikingmap/page.py", line 133, in add_next_point
    self.__add_point_to_track_area(coord)
  File "/Users/hannah.spitzer/projects/personal/render_osm/hikingmap/hikingmap/page.py", line 99, in __add_point_to_track_area
    if coord.lon < self.track_area.minlon:
AttributeError: 'NoneType' object has no attribute 'lon'
Removing temp file /var/folders/s9/0d6yy20d44v60qd0nfkjlqdd541mvv/T/hikingmap_temp_waypointsmue94igj.gpx

I'm happy to open an issue on Hikingmap and move the conversation there, but I won't have much time to do actual debugging I'm afraid.
GPX_all.gpx.zip

@roelderickx
Copy link

@roelderickx roelderickx commented on ef33f07 Feb 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I see, it is the track from your render_osm project, a very popular route among hikingmap users 😉 Good to see creativity based on my work too, I can only encourage that.

I think the same problem exists between pages 39 and 40. A small section of about 150 meters is not on any map but at that point there is no error. The result is still usable but it shouldn't happen.
image

I'll see if I can free up some time to investigate, but unfortunately there is no easy way to debug this. It may take a while.

@roelderickx
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to know what the problem was, after half a day I finally found it 🙂 As usual the fix is just 1 character... Issue roelderickx#7 was created which is merged now.
For the gap between the pages I created issue roelderickx#6. I know what the problem is and have a solution, but it is not yet working as expected. I'll keep you up to date in the issue.

Please sign in to comment.