How do I use libchamplain to load local chunks or OSM XML in Python?

I am trying to use GTK and libchamplain to display a map from local map data. The application must run on computers without an Internet connection.

After viewing, mapbox.py

it seems that the source should be replaced NetworkTileSource

with FileTileSource

. So I used minimal.py

an example to work with FileTileSource:

widget = GtkChamplain.Embed()
widget.set_size_request(640, 480)

tile_source = Champlain.FileTileSource.new_full(
        ID,
        NAME,
        LICENSE_TEXT,
        LICENSE_URL,
        MIN_ZOOM,
        MAX_ZOOM,
        TILE_SIZE,
        Champlain.MapProjection.MERCATOR,
        Champlain.ImageRenderer())

tile_source.load_map_data("map.osm")
widget.get_view().set_map_source(tile_source)

      

Unfortunately, when starting the application, the map is not displayed and I get the following error message:

(minimal.py:26308): libchamplain-WARNING **: NULL pixbuf

      

Based on some C examples ( one , two ), I guess there is a so called renderer called Memphis missing, which is only C. It seems that Champlain ImageRenderer, despite its similar name, is not suitable for this.

So my question is how will I proceed at this point. There are quite a few OSM renders out there besides Memphis, maybe some are written in Python, but which one integrates well with Champlain?

It doesn't have to be OSM either. The PNG pre-render collection will please me too. It's just that the FileTileSource Documentation specifically mentions "Loads the OpenStreetMap XML file at the specified path", so I assume better OSM support.

Any help is greatly appreciated.

+3


source to share


1 answer


I managed to do it in a very simplified way: just arrange your tiles according to the logic #z#/#x/#y#

as described in the docs , then don't change anything in this mapbox.py except for the URI. your case, for a file structure in a directory /tmp

might look like this:

    MAX_ZOOM,
    TILE_SIZE,
    Champlain.MapProjection.MERCATOR,
    "file:///tmp/tiles-#Z#/#X#/#Y#.png",
    #"https://a.tiles.mapbox.com/v4/mapbox.streets/#Z#/#X#/#Y#.png?access_token=" + ACCESS_TOKEN,
    Champlain.ImageRenderer())

      



still according to the docs, FileTileSource is meant to use a single osm file. I'm not sure how it works, I haven't tried it yet.

+1


source







All Articles