EXPORT_RASTER script problem - Google Maps
Hajo Schmitt
Global Mapper User
I wrote a Global Mapper script generator, that exports raster maps in the Google Maps (GMaps) tile format (to see for what this is usefull for see http://www.runwayfinder.com/).
Essentialy the GMaps format is a regular quad-tree with fixed 256*256 pixel raster tiles, based one some obscure Mercator projection. My script generator generates the Lat/Lon bound boxes for the tiles and the GMaps naming convention ("Zoomlevel, tilenumber X, tilenumber Y"). When run in Global Mapper, the tiles get cut out of the (Mercator projected) loaded map.
And here is my problem: I found no obvious way to specify the target tile size in PIXEL (i.e. 256*256), so i generate at the moment the tiles in there "natural" scale and resize them in a second step with a image tool to the fixed 256 * 256. You can imagine that this is very time consuming, cause especially in the upper layers Global Mapper renders multi-megabyte files that get condensed in the second step to 256*256.
I could have tried to compute the SPATIAL_RES parameters that will lead to the required 256*256 pixel. I fideled around with the gridding parameters GRID_TYPE_PIXEL_SIZE, but to no avail.
What is missing in my opinion: an optional EXPORT_RASTER parameter PIXEL_RES, similar to SPATIAL_RES, determining a fixed pixel (not ground units) size. From a implementation point of view this should be rather simple: I assume that Global Mapper computes this pixel dimension of the target tile from the SPATIAL_RES parameters, just skip that step and set the hardcoded pixel values.
If you have a better idea on how to generate fixed size tiles, please let me know !
TIA
Hans-Jochen Schmitt
PS: Mike - it would be cool anyway to have a "Export to Google Maps" feature in Global Mapper, you could even shell the generated map with a browser immeadetly after generating the tiles. If you are interested in the technical details of user-provided Google Maps raster layers, give me a note, i can provide links for the needed stuff (it's rather simple, took me one day, so it will cost you 1/2 day ;-).
Essentialy the GMaps format is a regular quad-tree with fixed 256*256 pixel raster tiles, based one some obscure Mercator projection. My script generator generates the Lat/Lon bound boxes for the tiles and the GMaps naming convention ("Zoomlevel, tilenumber X, tilenumber Y"). When run in Global Mapper, the tiles get cut out of the (Mercator projected) loaded map.
And here is my problem: I found no obvious way to specify the target tile size in PIXEL (i.e. 256*256), so i generate at the moment the tiles in there "natural" scale and resize them in a second step with a image tool to the fixed 256 * 256. You can imagine that this is very time consuming, cause especially in the upper layers Global Mapper renders multi-megabyte files that get condensed in the second step to 256*256.
I could have tried to compute the SPATIAL_RES parameters that will lead to the required 256*256 pixel. I fideled around with the gridding parameters GRID_TYPE_PIXEL_SIZE, but to no avail.
What is missing in my opinion: an optional EXPORT_RASTER parameter PIXEL_RES, similar to SPATIAL_RES, determining a fixed pixel (not ground units) size. From a implementation point of view this should be rather simple: I assume that Global Mapper computes this pixel dimension of the target tile from the SPATIAL_RES parameters, just skip that step and set the hardcoded pixel values.
If you have a better idea on how to generate fixed size tiles, please let me know !
TIA
Hans-Jochen Schmitt
PS: Mike - it would be cool anyway to have a "Export to Google Maps" feature in Global Mapper, you could even shell the generated map with a browser immeadetly after generating the tiles. If you are interested in the technical details of user-provided Google Maps raster layers, give me a note, i can provide links for the needed stuff (it's rather simple, took me one day, so it will cost you 1/2 day ;-).
Comments
-
Currently there is not a way to specify the pixel size directly for a raster export, it is computed from the export bounds and the specified spatial resolution. I will consider adding support for directly specifying the pixel bounds.
We are planning to add support for Google Maps export, so any information that you can provide could be helpful.
Thanks,
Mike
Global Mapper Support
support@globalmapper.com -
For those interessted to support Google Maps from Global Mapper, here the recipy of a Google Maps Export
Google Maps (GM) part
- understand the tile architecture of GM: quad-Tree, regular 256*256 pixel tiles, Mercator based, globaly unique tilenumbers within zoomlevel. Read the GM API link below.
- See GTileLayer API description, especially the ".getTileUrl = function CustomGetTileUrl(tile,zoom)" part. "tile" is a point structure, tile.x gives the col-tileindex, tile.y the row index, Zoomlevel the level (sic - please note that in pre-2.0 versions the zoomlevel was swapped: "17 - whole earth", now "0 - whole earth")
- Zoomlevels (GM API Version 2!): numbered from 0 to 17 (or more). "0" means "whole earth - one tile", "1" means "whole earth-4 tiles", "2" means "16 tiles" etc ..
- X/Y Tilenumbers: zero-based row/col index within the zoomlevel.
- find a suited storage/naming schema for the tiles, that can be referenced by "getTileUrl": e.g. a directory based schema like "\<Mapname>\<Zoomlevel>\<rowindex>\<colindex>.png"
- Tipp: normaly you need a GM API Key number to test GM, that is checked during runtime. When you open a local HTML file ("file:///"-URL), this is intentionally skipped. Idea: you can develop on a local machine without a webserver. Even the tile source for the custom raster overlay can come from "file:///" URLs .... so you need no webserver to see your generated tiles.
- Tipp: if you are new to Ajax/Javascript-programming, go and get Firefox (www.firefox.com) and the Firebug-debugger (https://addons.mozilla.org/de/firefox/addon/1843), which is a great debugging tool.
Global Mapper part
- project the basemap to GM Mercator projection (watch special non-WGS84 projection parameters)
- find a heuristic for the zoomlevels "FromLevel - ToLevel" needed to cover the loaded map, so that the map is tiled at the "natural" scale in nice regular 256*256 tiles and on the top level fully covered with a reasonable number (4?) of tiles.
- for each zoomlevel found: find the "hull" of the global unique tilenumbers needed to fully cover the map extents
- for each tilenumber needed: compute the LatLon-Bound boxes according to the global unique GM tile schema, depending on "Tile-X, TileY,Zoomlevel" (see "google-maps-deconstructed" link below to get an idea how to do this), generate each of that 256*256 pixel tiles (I do this at the moment by a generated Global Mapper script with EXPORT_RASTER commands).
- try to load tiles with a local minimum GM HTML page (Mike: one could generate a minimum HTML page within the Global Mapper export, so one can see immeatetly the effect of the newly generated custom map)
Here some links for implementing a Google Maps exporter:
Original API documentation by Google:
http://www.google.com/apis/maps/documentation/overlays.html#Tile_Overlays
Intro and some Javascript code (that could be translated to a "real" language ;-):
http://cfis.savagexi.com/articles/2006/05/03/google-maps-deconstructed
Have a look at the comments on the formentioned link too ! Especially the used Mercator projection is not "standard WGS84", there is no flatening used. In proj4 terms: +proj=merc +latts=0 +lon0=0 +k=1.0 +x0=0 +y0=0
+a=6378137.0 +b=6378137.0 +units=m
And finaly a minimum HTML-page for the newly created layer:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google Maps JavaScript API Example</title>
<script src="http://maps.google.com/maps?file=api&v=2&key=your API key here" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
function load() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
var copyCollection = new GCopyrightCollection('MyMap');
var copyright = new GCopyright(1, new GLatLngBounds(new GLatLng(44, 5), new GLatLng(56, 16)), 0, "(c) my company");
copyCollection.addCopyright(copyright);
var tilelayer = new GTileLayer(copyCollection, 5, 10 );
tilelayer.getTileUrl = function CustomGetTileUrl(a,b) {
return "file:///C:/Projects/GoogleMaps/Z"+b+"/R"+a.x+"/C"+a.y+".png"; // replace that with a "real" URL
}
var custommap = new GMapType([tilelayer], new GMercatorProjection(11), "MyNewMap", {errorMessage:"No chart data available"});
map.addMapType(custommap);
}
//]]>
</script>
</head>
<body onload="load()" onunload="GUnload()">
<div id="map" style="width: 640px; height: 480px"></div>
</body>
</html> -
Thanks for the detailed information. We hope to add Google Maps tiled export in the next release (v9.01) of Global Mapper.
Thanks,
Mike
Global Mapper Support
support@globalmapper.com -
I have completed adding support to the scripting language for specifying a pixel size rather than sample spacing/resolution when using the EXPORT_RASTER script command. You can now specify a pixel size value in the format PIXEL_SIZE="1024x768" (using whatever numbers that you need of course) as a parameter for the EXPORT_RASTER script command.
I have placed a new build of Global Mapper 9 with the change at http://www.globalmapper.com/global_mapper9.zip . Simply download that file and extract the contents over your existing v9.xx installation to give it a try.
Let me know if I can be of further assistance.
Thanks,
Mike
Global Mapper Support
support@globalmapper.com -
I must say that this is a great addition to the GM functionality. With Ver 9 export Raster as KML to open in Google Earth was also very useful and powerful
Thanks
Smile -
I am now ready to add direct Google Maps export support to Global Mapper. Do you happen to have a small sample with HTML and PNG files that you could zip up and email to support@globalmapper.com? I just want to have something that I know works before I start trudging off to create something in Global Mapper and then not know what it isn't working.
Thanks,
Mike
Global Mapper Support
support@globalmapper.com -
I have completed adding support for exporting data for use in Google Maps. I have placed a new build at http://www.globalmapper.com/global_mapper9.zip with the Google Maps export under the File->Export Raster and Elevation Data menu for you to try. Simply download that file and extract the contents into your existing v9.xx installation folder to give it a try.
Let me know if I can be of further assistance.
Thanks,
Mike
Global Mapper Support
support@globalmapper.com -
Hi,
I came across two odd things. First, I loaded a 7 1/2 degree USGS DRG with the added info (prj, tfw files) then did a Tools-config-projection to Plate-Curree (Google Earth projection). What I am doing may sound odd but it seems like it should operate differently than it does now. I want a single JPG file containing the reprojected image. When I go File-Export Raster-KML/KMZ, specify JPG, then Gridding-No Grid, and export bounds of All Loaded Data, the results are a 100 or so jpg "tiles". If I go back and specify Gridding-Specify Rows and Columns boxes set to 1, then I get a single JPG.
A second odd thing. When I did project the USGS DRG using Plate Curree the image in the windows gets compressed downward a bit. It looks more square than rectangle in the original.
Here's the odd thing. When I export using Export JPG and no gridding, the resulting image has the flattened aspect ratio. When I Export KML using the 1 row, 1 column method, I get a single JPG file which has the rectangle aspect ratio and pixels of the original.
Thanks -
By default, there is a "Automatically Grid Export" option on the KML Export options dialog that automatically will break the export into a grid to make it less likely that the data will overwhelm Google Earth. If that is checked, the data will be gridded in an automatic manner unless you explicitly select a different gridding method on the Gridding tab. If you uncheck that and choose the 'No Grid' option, then you should get a single file.
The flattening that you are seeing is a result of the projection being used. If you are exporting in the Plate-Caree (Geographic/Lat-Lon), then USGS DRGs will appear square as they are the same number of degrees across as they are up and down. As Google Earth requires Lat/Lon coordinates, all exports to KML files should have this look. Normal exports are done in whatever projection is currently selected on the Projection tab of the Configuration dialog. Usually something like UTM is a good choice there.
Let me know if I can be of further assistance.
Thanks,
Mike
Global Mapper Support
support@globalmapper.com -
Turning this off worked fine. I looked at that panel but it did not click that was my problem. Thanks."Automatically Grid Export"
The output JPG was a single image but the image size is 7964 x 10671, retaining the original Albers projection aspect ratio. Before doing this export KMZ I had applied the configure|projection to Plate_Carree and it displayed as square yet the output image is rectangle. Also, I brought in a fresh copy of the DRG and did an export KMZ straightaway and got the same (rectangle) results. Is it that Google doesn't care what the image looks like, just that the pixel locations in the image iis synched with Geo/Lat/Long coordinates that go into the KML file? Thanks again.The flattening that you are seeing is a result of the projection being used. If you are exporting in the Plate-Caree (Geographic/Lat-Lon), then USGS DRGs will appear square as they are the same number of degrees across as they are up and down. As Google Earth requires Lat/Lon coordinates, all exports to KML files should have this look. Normal exports are done in whatever projection is currently selected on the Projection tab of the Configuration dialog. Usually something like UTM is a good choice there. -
Great job, Mike !
Checked the new feature, works great. The georeference seems good/perfect, tested it with a 1:25.000 map and the original Google Maps road overlay, both fit perfectly.
Maybe you cover the new feature in a special tutorial - it is a "unique selling point" for Global Mapper ! Especially cause it is so easy: Get an API key, press a button and publish a map on the web .... (more or less ;-)
Greetings
Hans-Jochen Schmitt -
There seems to be ways to make data go from Global Mapper to Google. Is are several ways listed to load images int Global Mapper but Google maps/images seems to be absent. Is this a restriction to their terms of use, otherwise it seems like a desirable feature?
thx -
It would be a violation of Google's terms of use for us to provide built-in direct access to the Google Maps or Google Earth data in Global Mapper.
Thanks,
Mike
Global Mapper Support
support@globalmapper.com -
I plan on adding a tutorial detailing this function to this site very soon. I just moved and I am waiting on high speed and my "main" computer to be up and running soon.
Categories
- 13K All Categories
- 5.8K Features Discussion
- 350 Downloading Imagery
- 1.3K Elevation Data
- 385 Georeferencing Imagery Discussion
- 652 GM Script Language
- 56 User Scripts
- 115 GPS Features
- 421 Projection Questions
- 835 Raster Data
- 1.4K Vector Data
- 6.7K Support
- 181 Announcement and News
- 939 Bug Report
- 562 SDK
- 1.2K Suggestion Box
- 3.7K Technical Support
- 579 Other Discussion
- 132 GIS Data Sources
- 27 Global Mapper Showcase
- 244 How I use Global Mapper
- 110 Global Mapper Forum Website
