collapse

M4OPS

For our prototype mapping system try the Demo at mapping4ops.org/M4OPS.

You can also view a demo and discussion about M4OPS on YouTube.

* Forum Staff

PeterC admin PeterC
Administrator
admin webmasterOPS
Administrator

Author Topic: Tiling a map ready for serving  (Read 592 times)

PeterC

  • Administrator
  • Member
  • *****
  • Posts: 478
  • Passionate about my one-place study
    • View Profile
    • Holywell-cum-Needingworth History
Tiling a map ready for serving
« on: 18 October 2016, 15:38:39 »
Once we have a georeferenced .tif file in the working folder we can convert it into tiles by using suitable software (such as maptiler). The free version is OK but leaves a watermark in the final images, and we have a paid subscription to the 'Plus' version which is better.  There is a guide to using MapTiler at on the NLS site, and there is official documentation here. We are using version 7.1 of maptiler.

(Note that there is a way to use free software to prepare tiles but this is much more time-consuming.)

A pdf version of the maptiler documentation is also available, and has more details - particularly command line parameters.

The 'Plus' version of maptiler can cope with only a single file as input. If we need to merge image files then see the [/iurl=http://mapping4ops.org/raster-map-technicalities/how-to-prepare-an-image-as-a-map-georeferencing/]merge instructions[/iurl]. However there should be no need for this, as M4OPS can cope with grouping tiled layers together as a single layer.

The 'Plus' version of maptiler can cope with a file whose size is 900 megapixels (30K * 30K) as a maximum. At 2 bytes per pixel this is 1.8 GB, which is more than enough for most single map images - however if it is not enough see the footnote.

If the map is going to be stored in the AWS S3 (cloud) store for use by M4OPS, then the steps to follow to convert the tif file into map tiles using MapTiler and upload them to the cloud is:
  • Start MapTiler, opting for Standard tiles (for Google Maps etc)
  • Drag and Drop, or browse for the tif file
  • You can usually leave the options (coordinate system, geographic location) as their defaults, but to specify a different coordinate system:
    • select Search results in the top right dropdown
    • enter the country (eg UK)
    • select the coordinate system you want (eg EPSG:27700)
    • click on 'Set'
    • (See documentation)
  • click on 'Continue'
  • Select the 'MBTiles' option (see the meaning of this)
  • Select the required zoom levels (this article is useful on zoom levels, but usually the defaults [13/14-19] are OK - for the free version you can choose only the default values)
  • Click on 'Advanced options', and consider Transparency settings (ie the Alpha channel)
    • in the normal case for purchased georeferenced tifs (and many others) the default is fine
    • if the area outside the georeferenced map is black, you may need to set 'Color to Alpha' to black
  • Also under 'Advanced options', change the output name (eg remove _modified)
    • [Note the name must be a string rather just a number, so eg if it is just a number put a 'T' in front of it]
  • Click on 'Render', and when asked:
    • navigate to where we want the output file to be placed - often \Mapping\Software\M4OPS\OPS\(area)\(ops)\AA for tileserver\(category)\ folder
    • alter the .mbtiles filename if required
  • When rendering is complete, View Map to check that there is no opaque border round the map
  • We can then either Upload to the cloud (see below), Go back (twice and repeat the process for a different Tif file - having removed the current one first), or Quit MapTiler

To upload a .mbtiles file to the cloud the steps are:
  • (If we want to upload a file that we have not just rendered) Select the File/View a file menu option and select the file, then Close preview
  • Click on Upload to the cloud
  • Enter the Access key ID, Secret access key (credentials), and the AWS S3 Bucket name (m4opsprod)
  • (We can expect anything up to 4000 objects for one map)
  • Note that there is no OPS or category structure within the Bucket
  • On completion we can either Go back (three times and repeat the process for a different Tif/mbtiles file), or Quit MapTiler

In the AWS S3 Bucket, we should end up with:
  • a folder for this image containing:
    • Folders of tiles for each zoom level we specified (eg 14, 15, 16, 17, 18, 19 )
    • metadata.json - data which describes the map uploaded, including the bounds
  • and at the top level:
    • index.html - if opened in a browser this enables us to look at the tiled map(s) in various ways
    • index.json - data about all the maps uploaded, including the bounds (ie a concatenation of all metadata.json files, and used by index.html)

We then need to update the OPS.


As an alternative, if the map is going to be stored in our own website storage then the steps to convert the tif file into map tiles using MapTiler is:
  • Create an empty subfolder in the \Mapping\Software\M4OPS\OPS\(area)\(ops)\AA for tileserver\(category)\ folder with name of the image eg 00430_1764_Cosmo_Wallaceb, or T109724304 (it must not be a simple number) - this is where the result will be placed by MapTiler
  • Start MapTiler, opting for Standard tiles (for Google Maps etc)
  • Drag and Drop, or browse for the tif file
  • (Only if we had the PRO version) We can add more tifs if we want (using Open a File..)
  • The only Advanced Option that might be worth considering is the transparency colour
  • Leave the options (coordinate system, geographic location) as their defaults, and click on 'Continue'
  • Select the 'Folders' option (see the meaning of this)
  • Select the required zoom levels (we can only choose the default unless we have a paid version) (this article is useful on zoom levels, but usually the defaults are OK)
  • When we click on 'Render' we will be asked for the name of the (empty) folder we created above for the results
  • When rendering is complete, we can see a preview of the map if we wish
  • When ready Quit MapTiler

In the results folder for this image, we should end up with:
  • Folders of tiles for each zoom level we specified (eg 14, 15, 16, 17, 18 etc)
  • index.html - if opened in a browser this enables us to look at the tiled map in various ways
  • googlemaps.html - showing the tiles over a Google Maps satellite view
  • openlayers.html and leaflet.html - showing the tiles over an OSM map using the two different technologies
  • metadata.json - data which describes the parameters of the tiles at each zoom level from zero to the maximum

Once we have tiled the map we need to:
  • Upload the folder structure from the \Mapping\Software\M4OPS\OPS\(area)\(ops)\AA for tileserver\(category)\ folder into the ShowMaps/tileserver-php-master/(ops)/(category)/ directory; Note that:
    • for technical reasons this has to be in the tileserver-php-master directory,
    • the ops is just represented by its code (eg HcN),
    • the area is not relevant, but the category is

We then need to update the OPS.


If the map might be too big:
We need to find out the width (W) and Height (H) of the tif file in pixels, and calculate the number of megapixels (millions of pixels) it has - say P (= W * H / 1,000,000). Then if P > 900, we need to reduce the number of megapixels:
  • calculate the linear reduction factor % = 100 * sqrt(900/P) - say F
  • calculate the new width in pixels - say Z (= W * F)
  • gdalwarp -overwrite -s_srs EPSG:27700 -t_srs EPSG:27700 -r lanczos -ts Z 0 -dstnodata 0 -of GTiff infile outfile (where we replace Z by the value from above)
  • (we can do gdalwarp from within QGIS using option Raster Warp, or at the command line, but either way be aware that gdal uses resources without showing it is busy - just wait till it has finished)
« Last Edit: 14 March 2018, 07:10:11 by PeterC »

 

mapping4ops.org is a Society for One-Place Studies project supported by Grassroots Giving from Skipton Building Society
Glossary | BBCodes | Feedback