enzet / map-machine

Python renderer for OpenStreetMap with custom icons intended to display as many map features as possible
MIT License
504 stars 31 forks source link

[Maybe Bug] Not handling "--boundary-box" when "--input" is specified in tile generation mode. #99

Closed edward17829991 closed 2 years ago

edward17829991 commented 2 years ago

https://github.com/enzet/map-machine/blob/014e11b826d9aff2fa0e4a54b886654e42d70a7a/map_machine/slippy/tile.py#L477

When I tried map-machine tile --input test.osm.xml --boundary-box 121.462,24.963,121.667,25.198 --zoom 16 The program complains about AttributeError: 'NoneType' object has no attribute 'get_left_top'

I looked at the source code a bit, noticed that when in "--input"-specified branch, --boundary-box was never been ingested. The original code set the view_box only by the bound elements in the input XML files. But as stated in Generate a set of tiles, the --boundary-box argument should override other sources.

I've temporary fixed the problem by setting the view_box from arguments prior then XMLs.

        boundary_box: Optional[BoundaryBox] = BoundaryBox.from_text(
            options.boundary_box
        )
        osm_data.view_box = boundary_box or osm_data.view_box

Edward Chen

enzet commented 2 years ago

Hello Edward! Thank you for reporting this!

You're right, in input mode, it deliberately ignores --boundary-box option, tries to read <bounds> tag from input XML, and obviously may fail. 🥲

Your fix seems quite reasonable. Do you want to make a pull request? Or I can fix it.

edward17829991 commented 2 years ago

Hi @enzet ,

Thanks for your fast response! Since it's a quick fix, you can fix it directly.

Overall, this is a great project and tool, it's quite flexible and hustle-free with custom xml files. I just stumbled upon this few days ago on the open-street-map wiki about rendering, and I got great result quite easily. Thank you and the community.

Edward Chen

enzet commented 2 years ago

@edward17829991

Yeah, and I definitely should review usage of other options as well. In some cases they are conflicting.

Thank you for your interest! It's nice to hear the project is useful. Please, feel free to tell me if you have any suggestions on how to improve it.