I've been working for a couple of days to get offline map tiles working for use in JXMapviewer2 but I am having trouble when using generate_tiles_multiprocess.py to process the tiles.

My intention is to allow JXMapviewer2 to process it's background tiles offline for a java project I'm working on. Online tiles work but not on the specific network that it is going to be implemented on.

My progress so far;

  • Download and install PostgreSQL with PostGIS database.
  • Update pg_hba.conf to trust
  • Download osm2pgsql and load pbf file into database using openstreetmap-carto. My tables are; planet_osm* line, nodes, point, polygon, rels, roads, ways and then pointcloud_formats, spatial_ref_sys.

osm2pgsql -k -c -S openstreetmap-carto.style -d gis -U postgres new-zealand-latest.osm.pbf

  • Edit carto project.mml to contain PostGIS connection info
  • Download and place shapefiles in correct carto directory
  • Generate XML file and remove font references

carto project.mml > osm.xml

  • Update generate_tiles_multiprocess.py to point to my osm.xml file and tile_dir. Include bbox and zoom levels.
if __name__ == "__main__":

    #home = os.environ['$HOME']
        mapfile = os.environ['MAPNIK_MAP_FILE']
    except KeyError:
           mapfile = 'C:/Mapnik Tiles/osm_tiles/openstreetmap-carto-master/osm.xml'
        tile_dir = os.environ['MAPNIK_TILE_DIR']
    except KeyError:
        tile_dir = 'C:/Mapnik Tiles/osm_tiles/openstreetmap-carto-master/tiles/'

    if not tile_dir.endswith('/'):
        tile_dir = tile_dir + '/'

    # Change the following for different bounding boxes and zoom levels
    # Start with an overview
    # NZ
    bbox = (166.245, -47.339, 178.660, -33.943)
    render_tiles(bbox, mapfile, tile_dir, 0, 18, "World")

Run generate_tiles_multiprocess.py

This is where I have the issues. The folder structure gets created, eg. 0, 1, 2 etc but no tiles are created. The console output displays multiple lines of "* attribute 'repeat-distance' with value '50' at line 39259" and sits. (more than 999 lines of this with varying line references) I then have to Keyboard interrupt to get back to command line.

If I use generate_image.py it creates a map of New Zealand and shows the same attribute lines as above.

Is it a case of leaving it to create the tiles?

I've left it for 10 minutes with no images being output.

JXMapviewer2 java example code;

// Create a zip-file based TileFactoryInfo for OpenStreetMap
// See https://docs.oracle.com/javase/8/docs/api/java/net/JarURLConnection.html for URL syntax details
// You can create such a ZIP file by zipping the content of ${HOME}/.jxmapviewer2/tile.openstreetmap.org
// The ZIP file should contain a list of folders (0, 1, 2, 3 ...) that represent the OSM path structure

TileFactoryInfo info = new OSMTileFactoryInfo("ZIP archive", "C:/Mapnik Tiles/osm_tiles/openstreetmap-carto-master/tiles/tiles.zip!");
  • Upon using osm2pgsql it processed 29,582k nodes, 737k way and 0 Relations. I'm presuming that is normal? I also left running create_tiles_multiprocess for 2 days and no tiles were created.
    – Gregws
    Commented Nov 10, 2019 at 0:24
  • When running project.mml in carto I get WARNING(s) : Amenity-points.mss Styles do not match layer selector #text-poly-low-zoom
    – Gregws
    Commented Nov 10, 2019 at 0:31

1 Answer 1


Although not a direct fix for the above situation, but it seems as though the issue was with the XML file that carto project.mml > osm.xml was creating.

My work around was to;

  • Install TileMill
  • Download and process an openstreet map project from https://github.com/mapbox/open-streets-style
  • Open the new project in TileMill
  • Set bounds, initial zoom and zoom levels
  • Set PostgreSQL settings
  • Setup absolute references in the XML for wetlands-8.png (etc) and shapefiles
  • Export XML
  • Using that XML file in generate_tiles_multiprocess.py it would create the tiles

All tiles are then zipped to be fed into Java.

  • Do you have that XML? Can you share it? I wonder why do we have to generate our XML using carto command instead of using a pre-generated XML?
    – Capan
    Commented Mar 6, 2020 at 9:28
  • Hiya, I have since removed all the files I had, but if you follow my process as above it will work. I ended up not using tiles as there were too many at a reasonable zoom level. Instead I used mapsforge and a .map file. For Java I found mapsforge as a great library
    – Gregws
    Commented Mar 7, 2020 at 10:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.