/ym4r-tools

YM4R (Yellow Maps for Ruby) has a Rails plugin for Google Maps (YM4R/GM), a plugin for Mapstraction (YM4R/Mapstraction), a gem with ruby helpers for geocoding and the Yahoo! Maps Building Block APIs and tools to generate tiles for custom Google Maps.

Primary LanguageRubyMIT LicenseMIT

YM4R Tools

This is the YM4R Tools distribution version 0.5.2. It includes command-line tilers that help in creating new map types to use with Google Maps.

Installing

Just unzip the zip file. The two tilers are inside the tools folder. After that, you can use them directly from there or copy them wherever you feel like. They are completely independent of the YM4R gem. However, if you are going to use the tile_image.rb command, you should install the RMagick gem since it depends on it.

Operations

The YM4R Tools package provides 2 tools to generate tiles.

tile_wms.rb

This is to generate tiles from an already existing WMS server. It can be useful if you don’t want to setup a permanent WMS server but still want to display your geographic data files in Google Maps (any format compatible with your WMS server can then be used). It can also be used to cache data from public servers, which can sometimes be very slow to answer requests. Run ruby tile_wms.rb -h to know what the options are. Most are self-explanatory.

However the arguments --[no]-geographic and --e warrant some explanation. The Google Maps are in the Simple Mercator projection in the WGS84 datum and currently do not support the display of data in projections other than that (at least if you want to display markers and lines on top of it). Unfortunately, different WMS servers do not identify this projection the same way. So you can give to tile_wms.rb the EPSG code of the Simple Mercator projection through the --e option. For UMN Mapserver the code is 54004 and for GeoServer, it is 41001. For others it may well be one of these 2 choices but you have to check yourself. On top of that, some servers just don’t support the Simple Mercator projection. This is why there is a --geographic option. It is in order to tell the tiler that it should request its tiles using LatLon coordinates in the WGS84 datum (which should be supported by any server in a consistant way). Unfortunately it is not perfect since the deformation is quite important for low zoom levels (< 5 for the US). Higher than that, the deformation is not that visible. However, if you control the WMS server, it is recommended that you don’t use --geographic and instead use the --e option and setup the Mercator projection in your server if it is not done by default.

The -g (--gmap-setting) option also needs to be explained. It uses the data that comes from this tool: www.onnyturf.com/google/latlontotile.html. Basically you need to center the map at the zoom you need to get your desired extent. When you are satisfied, the tool will give you the following data: the X and Y values of the upper left corner tile, 17 minus the zoom level (this is because the V2 of the Google Maps API reversed the zoom order), the number of horizontal and vertical tiles that you want. You will then pass to the -g option 5 integers in the order previously described, for example: -g 300,383,7,3,2 About the zoom level, if the tools tells you 7, you should pass 10 (17 - 7) to the -g option.

Note that the zoom levels passed to the -z argument must be greater or equal to the zoom level passed to the -g argument.

tile_image.rb

This is to generate tiles from local images. You will need the RMagick library for it to work.

You should use this tool: open.atlas.free.fr/GMapsTransparenciesImgOver.php. You should have an image that will be displayed at the lowest zoom level that you want and use it with this tool. You can translate and scale the image until you are statisfied. When you are, you must click a link to gather information about the transformation needed for your image. You will need to pass this data to the -p option of the tool in the following order: X and Y of the top left corner of the map, 17 minus the zoom level, X and Y padding, scale. So for example, you will have the following argument: -p 2503,3667,4,241,115,0.8702928870292888 Again, about the zoom level, if the tool tells you 7, you should pass 10 (17 - 7) to the -p option.

About the padding, I had a slight problem on Firefox: I needed to substract 10 to the X and Y paddings given by the online tool to have the correct one to pass to the -p option. Maybe it has something to do with the 10-pixel bands at the top and left of the page.

You should pass as many images to the tool as you have zoom levels in the -z argument: Each image will be used for one zoom level. The string order of the names of the image files must match the order of their corresponding zoom level. Moreover, each image should be exactly twice bigger (in both width and height) than the one in the zoom level immediately preceding it. Also note that the zoom levels passed to the -z argument must be greater or equal to the zoom level passed to the -p argument.

By default, the tool will generate transparent borders. You can pass 4 integers (R, G, B and A) from 0 to 255 to the -b option to change that: -b 255,123,456,42

Here is an example of command line execution using the image at open.atlas.free.fr/GMapsTransparenciesImgOver.php. If you place it over the satellite images, you would get the following parameters: 2503,3667,13,149,76,1.0 (I have accounted for both the reversing of the zoom for v2 and the 10-pixel drift of the padding in Firefox). I have also created another version of the image, at double the size in width and height. Normally you should do the opposite: Get the highest resolution possible (if you scan the map) and downsize it for all the desired zoom levels until you get the image to use in this online tool (lowest zoom level). If you use vector graphics, you can easily create versions at different resolutions. I placed the 2 images (called MAP_zoom1.jpg for the smallest and MAP_zoom2.jpg for the biggest) in directory ./input. And I launch the tool like this: ruby tile_image.rb -o ./tiles -z 13..14 -p 2503,3667,13,149,76,1.0 ./input/* This will create tiles of the image for zoom levels 13 and 14. It should take just a few seconds.

Changes since last version

  • Creation of the package

TODO

License

The YM4R Tools are released under the MIT license.

Support

Any questions, enhancement proposals, bug notifications or corrections can be sent to guilhem.vellut+ym4r@gmail.com.