There are a few main python scripts created to help perform various tasks with Maperitive, which are described here. There are also a number of "test scripts" which are one-offs or works in progress stored on the maps USB drive.
convert_georef.py
This script is used to read in a directory of images (such as created by the Maperitive export-bitmap or save-source command), and convert all the Maperitive .georef text files in that folder to GDAL-compatible world files. The folder to be worked on must be manually entered at the top of the python script by editing the file.
Example:
Matperitive .georef <georef> <srs> <id>EPSG:3857</id> </srs> <origin> <x>-20037508.342789244</x> <y>-7558415.6560817827</y> </origin> <cell-width>61.844161551818772</cell-width> <cell-height>105.31808356728818</cell-height> </georef> | World File (.pngw) 61.844161551818772 0 0 105.31808356728818 -20037508.342789244 -7558415.6560817827 |
fill_terrain_tiles.py
The NASA SRTM dataset does not include areas of the earth containing no height data (ie: the ocean). However, Maperitive is dumb about what to do if it tries to get SRTM data for an ocean and none exists, and it will fail. This script fills in the SRTM data by generating blank files to fill in the gaps. SRTM files are named for their latitude and longitude (ex: 32N042W.hgt), so the file iterates through all possible images and when a file is missing, creates it.
This python script can be run on the command line and passed command line options. Run python fill_terrain_tiles.py -h
to see these options.
This command has already been run on the USB drive, to create the SRTMGL1_full and SRTMGL3_full folders. These folders are linked in the Maperitive cache folder using directory softlinks.
gen_terrain_image_script.py
One of the ideas for generating a terrain map of the entire world was to have Maperitive load in the SRTM height data, shade it, and create a set of geo-referenced images. Then another program (either Maperitive itself or GDAL) could be used to stitch these images together and create a set of web tiles from them. You can perform this step with gen_tiles_from_images_script.py.
This Python script outputs a Maperitive script based on the options passed into the Python. Run it with -h
to see the available options. Run the script output with Maperitive.Console.exe.
This script divides the world into square "slices" based on a lat/long range, creates an image for this slice, and clears out the memory to create the next slice. Be cautious of the memory limitation here! A 15 degree slice contains 255 SRTM images. At sample rate 1, using SRTM3 (lower-resolution) data, this still requires 650MB of RAM per slice.
The script has an "index" parameter. If Maperitive crashes or runs out of RAM after slice 103, for example, you can run this script again and tell it to start at slice 103, so the work doesn't need to be repeated.
This script was run to create the Images folder on the USB drive, but those images are so large as to be impossible to load into Maperitive at the same time. It was also used, with SRTMGL3 at sample rate 6, to create the full world map up to zoom level 6. This worked well because each slice of the world was a very small image at this resolution, but still looked good on the map. The output of this process is incorporated into the Tiles folder on the USB drive, up to zoom 6.
gen_tiles_from_images_script.py
If you used gen_terrain_image_script.py to create a folder of georeferenced images, this script can be used to create a Maperitive script which loads all the images back into Maperitive and generates a web tileset from them all. Be sure you have enough RAM to do this! It is recommended to have image data created at a high sample rate and/or with SRTMGL3 data.
This Python script outputs a Maperitive script based on the options passed into the Python. Run it with -h
to see the available options.
Note that each zoom level takes four times more hard drive space than the one before it. Zoom 7 takes 100 MB. Zoom 8 takes 400 MB. Be sure you have enough for the zoom level requested. Also, very high zoom levels will look ugly if the input image data is too low-resolution.
gen_terrain_tiles_script.py
This script fixes some of the problems of generating the world map from images. It is capable of producing a higher resolution map from zoom levels 7 up. To go any lower will require some tweaking for the map not to have white stripes of missing data. The Python script can generate a Maperitive script to perform this task, or preferably, use the -r
option to instruct the Python code to run Maperitive itself. This automates the process, allowing Python to detect that Maperitive has failed somehow and automatically retry.
This script divides the world into slices 6x6 degrees square, but loads in a 1-degree border around each slice for an 8x8 degree total. Then, slices are overlapped by 2 degrees in an attempt to ensure that at the minimum zoom (7), there are no gaps in the map. By default, Maperitive will generate web tiles that cover the entire range of the input data, even if some of those tiles will only be partially filled. This script uses a setting, generate-tiles exclude-partial=true
so that these partial tiles are never created. This is the reason for the 1 degree bleed, to reduce the number of partial tiles at the edges of each slice. In theory, any tile not generated should be generated by the next slice to the North or East, since they overlap by 2 degrees and a tile at zoom 7 is 2.813 degrees wide. In practice this still misses some regions.
The script has an "index" parameter. If Maperitive crashes or runs out of RAM after slice 103, for example, you can run this script again and tell it to start at slice 103, so the work doesn't need to be repeated.
Attachments (5)
-
convert_georef.py (864 bytes) - added by 7 years ago.
This script reads in all the maperitive georef files in a folder and converts them to GDAL-compatible world files ex: image.tif.georef to image.tifw
-
fill_terrain_tiles.py (2.0 KB) - added by 7 years ago.
Script to complete an SRTM dataset by filling in blank data
-
gen_terrain_image_script.py (4.7 KB) - added by 7 years ago.
Use Maperitive to generate the entire world (or a portion) as geo-referenced images.
-
gen_terrain_tiles_script.py (5.8 KB) - added by 7 years ago.
This script can be used to generate a web tiles set of terrain shading for the entire world from zoom levels 7 and up.
-
gen_tiles_from_images_script.py (2.3 KB) - added by 7 years ago.
Converts a set of geo-referenced images to a set of web tiles.
Download all attachments as: .zip