GeoTiff and Tiles for Custom Maps

This page will pass through some interesting image and shape georeferencing topics. First what is this image georeferencing business anyway? Well, I’m no expert myself but superficially its adding a referenced coordinate system to a image, so that each pixel has a location associated with it. Let’s say I have a satellite picture of your neighbourhood or house and I would like to use this image in google earth, mapbox or any other mapping system. In this case you could get some known reference points and mark then on the image, such as a tree, signs, roof tops. After that you could go to google-earth (or similar) get the true/approximate coordinates just by placing those spots under your mouse and writing down latitude and longitude values, which appear automatically on the screen footer. Well at this point you have your picture (in TIFF format), you’ve marked some pixels and you have their true lat/lon values: you could now use a command line tool called GDAL (not very user friendly, but easy) and run a few operations and magically you have a GeoTIFF. This is slightly larger TIFF file (I hope you know what TIFF files are), which you can view (but not edit natively) on photoshop/gimp or even o OS image viewer. The GeoTIFF itself is not all that useful from an artistic/design point of view, what you really need is to create a tile multi resolution folder which you can use in google-earth (KMZ and/or KML) or mapbox (MBTiles).

Why else would want to georeference an image? Maybe you’d like to draw your own maps: such as a factory map, tourist map or any other info you would like to map in your own "non satellite photo" way. If you go over to MapBox home page you’ll find lots of custom sample maps: cities, pirate maps, illustrated maps. It’s how art/design meets real mapping. And the great part is that all these maps work with real coordinates, so by using gps location from, let’s say, a cell phone, you can pin point the users real location. Ok, I know… this is all overwhelming… your just dying to draw your own maps!

Just wait a moment.. don’t just go downloading GDAL… There other ways to making it happen using a nice cross-platform graphical interface.

During my web research I tried out quite a few apps, hoping to find a do-it-all designer friendly interface. But! sorry to disappoint you, that’s a definite NO GO (at least today (12/12/2012). Okay you can buy a professional toolkit like ARC GIS, although I believe that if your reading this that’s not what you’re looking for. Let’s go straight to the chase:

Good/Easy apps and their usefulness:

    • QlandkarteGT – The first app I stumbled upon, great app lets you load a TIFF image mark some pixels and give them coordinates. After that if you’ve concluded the "create new map steps" you’ll have a nice GeoTIFF.
    • Quantum GIS – A lot more complex than QlandkarteGT, does image referencing and lets you draw a georeference shapes (Vector graphics). In this case you get a nice SHP file to use in your projects.
    • TileMill – If you plan to get your GeoTIFFs and shapes in Mapbox, this is the tool. You can add shapes and geotiffs and build that mbtiles file which loads in mapbox SDK.
    • MapTiler – If going for the google solution, well maptiler is the tool. It transforms you geotiff in a nice folder system to use with google mapping. So if you have google-earth installed you can just open the KML file in the root folder, and like magic earth will load your custom map.

Even if you’re not going to use Mapbox, you can open your geotiff in TileMill and check if it’s correctly georeferenced (appearing in the right place on planet earth). If you’ve got the coordinate format wrong or lat/lon inverted (inverted signs as well) your wonderful house in Rio de Janeiro will probably be in the grassy plains of the Republic of Madagascar. So watch out for the "gotchas". Remember, even if your output is Mapbox you could run it through MapTiler and open google-earth to check the precision and correctness of the map, the earth app lets you overlay the map and make it transparent so you can cross compare with strategically placed marks.

Let’s get started: Simple Georeferencing and Tilling

Download QlandkartGT… (It has Windows, MAC and Linux builds..) and Open… you should see rougthly the screen below:

Now go to Map create new map…

Now select Tiff to GeoTiff…

Now select your source Tiff image… it should show in the background…

Now select your map projection type… I’ve been using WGS_1984…. This is important, because the tiler application will want to know the data format when opening the geotiff… or again "gotcha" you might find yourself on the wrong side of the blue marble.. or worst it might not even open your image.

Next choose your georeferencing procedure… more points probably more precision.. you can go from 2 to 6… maybe you can even use more… but no need… 3 works fine… 4 is great… 6 can give you strange results from time to time (don’t undertstand why)…

Ok so you choose WGS_1984… now you have to find some corresponding reference points between your custom map and the real world! Use place marks on google earth to extract the complete coordinate.

The properties from the placemark have detailed coordinates… you can always click on the placemark do a "copy" and then "paste" on any TextEditor… and you’ll get the original kml info…

Move on to step 2 menu tab… and click on Add Ref…. This will create a boubble shape pin on the custom map… use the mouse to move it around a place it on a corresponding reference point. After take a quick look at the point table and observer the <enter coord.> text… click on it and enter the coordinates using one of the formats available in the "?" icon above the Add Ref. button… (I’ll be using the one marked in red…)

OK… now you have a simple "gotcha", the coordinates on google earth are shown in latitude/longitude…. but Qlandkarte receives the data in longitude/latitude… so just type them in the reverse order… After you’ve finished this tedious stage… you can go and press "Start Process" on the bottom right corner… and it should show you a console on "stage 3 tab" and some feedback from a command line tool… After that you should have tiff file in the same folder as the original image (image.tiff -> image_ref.tiff). The _ref.tiff is the geotiff…. Just go over to the TileMill app and open your geotiff as a new layer and check if everything is well.

 

 

Ok! now you’ve seen a nice step-by-step "Make your own geoTiff" tutorial… and you need to do some fine editing on the GeoTiff before tilling, since geo referencing can take up some time depending on map size you might like the following info: Youre probably thinking… Oh! let’s go over to Photoshop or GIMP and edit the picture… it’s a TIFF file. Well, I won’t lie to you, the picture will open, and yes, you can edit it: When you save the file again it will lose all the geo information since all editors don’t work with the geo tags in the image. Again, you have nice, simple and well documented procedure to extract the geo tag to ASCII file before editing and then re-integrate it after you finished. So no need to geo reference it every time, just be carefull with transformations which might reshape the image. For this step I got this nice tutorial from fsdeveloper using fwTools (all the links on the text).

Touch up a geotiff image: (from www.fsdeveloper.com, you also need fwTools)

Copying tags

Most programs that you can use to edit your imagery do not understand the geo related tags in the GeoTIFF file, so they will probably save your image back as a normal TIFF image. In that case you will have to insert the geo information again yourself. Of course you could provide the boundaries again as explained above, but you could also save the previous tags and just apply them again. To do this use the listgeo and geotifcp tools.

First you will need to save the current geo tags to a file on your harddisk. To do that we will be using the listgeo tool:

 listgeo myfile_wgs84.tif > myfile_wgs84.gtf  

The GTF file is just plain ASCII, so you can open it with your text editor and view the information.

After you have edited your image in your painting program, all you have to do now is put the tags back into the TIFF file, so that it becomes a GeoTIFF again. We will use the geotiffcp tool for that:

 geotifcp -g myfile_wgs84.gtf myfile_geotiff.tif myfile_edited.tif  

This will give you a new GeoTIFF file that can again be used by the resample tool to place your imagery in FS. So all you have to do before you start editing in your painting program is make sure yo have save the geo information to a GTF file, then you can always put it back later on.

 

I hope this page helps you get started in making custom maps for apps the easy and correct way. As I said, I’m no expert on the subject so please correct me if I wrong…