Skip to content

IndexError: list index out of range When processing an OSM file where ways have been deleted #208

@kevjs1982

Description

@kevjs1982

When processing a file that you've downloaded in JSOM and deleted at way from (e.g. to delete some unnecessary objects from your own map before rendering) you get the error "IndexError: list index out of range".

(Note, all osm files references below are included in osm_files.zip )

Version

/home/kev/map-machine/bin/map-machine --version
Map Machine 0.3.0

Steps to reproduce

  1. Open JOSM and download an area - save as full.osm (example in the attached Zip)

  2. Run a render command on the unedited file:-

$ /home/kev/map-machine/bin/map-machine render -i /lindblad/scratch/full.osm -z 17 -b-1.080882,52.929350,-1.072460,52.932118 -s 1920,1080

which works as expected.

INFO Constructing ways...
INFO Constructing nodes...
INFO Drawing ways...
INFO Drawing main icons...
INFO Drawing extra icons...
INFO Drawing texts...
INFO Writing output SVG to `out/map.svg`...
Image 3. Edit the file in JSOM to delete a way - save as full_with_deletion.osm (in the attached Zip) and run the same render command (but pointing to the modified filename)
/home/kev/map-machine/bin/map-machine render -i /lindblad/scratch/full_with_deletion.osm -z 17 -b-1.080882,52.929350,-1.072460,52.932118 -s 1920,1080

results in

INFO Constructing ways...
Traceback (most recent call last):
  File "/home/kev/map-machine/bin/map-machine", line 8, in <module>
    sys.exit(main())
  File "/home/kev/map-machine/lib/python3.10/site-packages/map_machine/main.py", line 37, in main
    mapper.render_map(arguments)
  File "/home/kev/map-machine/lib/python3.10/site-packages/map_machine/mapper.py", line 541, in render_map
    constructor.construct()
  File "/home/kev/map-machine/lib/python3.10/site-packages/map_machine/constructor.py", line 175, in construct
    self.construct_ways()
  File "/home/kev/map-machine/lib/python3.10/site-packages/map_machine/constructor.py", line 193, in construct_ways
    is_cycle(way.nodes)
  File "/home/kev/map-machine/lib/python3.10/site-packages/map_machine/osm/osm_util.py", line 8, in is_cycle
    return nodes[0] == nodes[-1]
IndexError: list index out of range

Workaround

  1. Run the commands (using xmlstartlet to delete matching nodes)
xmlstarlet ed -d '//osm/way[@action="delete"]' full_with_deletion.osm > full_with_deletion_cleaned.osm
/home/kev/map-machine/bin/map-machine render -i /lindblad/scratch/full_with_deletion_cleaned.osm -z 17 -b-1.080882,52.929350,-1.072460,52.932118 -s 1920,1080

This also works successfully

INFO Constructing ways...
INFO Constructing nodes...
INFO Drawing ways...
INFO Drawing main icons...
INFO Drawing extra icons...
INFO Drawing texts...
INFO Writing output SVG to `out/map.svg`...
Image

Expected behaviour

Render successfully

Looking at the code the is_cycle function seems to be the eventual culprit as no nodes exist when a way is deleted in JOSM.

def is_cycle(nodes: list[OSMNode]) -> bool:
    """Check whether the way is a cycle or an area boundary."""
    return nodes[0] == nodes[-1]

Metadata

Metadata

Assignees

Labels

enhancementAny new feature or improvement

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions