Wednesday, May 16, 2012

Manage (Google) maps tiles

Google and other maps come as a collection of many files, each of them representing a precisely defined piece of Earth, often called tiles. Some software tools can store them on your mobile device or computer for later, off-line, usage. One of them is, for example, Android application Maverick (even though, the latest Maverick, because of licensing terms, does not store Google maps but it does the same off-line storing with other maps, such as OpenStreet maps).

The files with tiles have numeric names and they are located in the directories named also numerically, including directories indicating the zoom level of the stored tiles.

For example, in the picture, there is a map of type "Google Hybrid" (this name, by the way, differs depending what platform the map was created at - but the rest is reasonably same); it has several zoom levels - numbers 10, 11 and 12 on the picture; each zoom level has tiles in directories 622, 623, etc.

In almost all cases, you do not need to know this structure. You just copy it to your mobile device (or, even better, it was already created on your mobile device so you even do not need to see this structure. Except one case: when you want to delete some tiles. You may have maps from many different places and you do not need any more some of them. How do you know which tiles to remove and which to keep? That's why I wrote a small script (in Perl) that can help with it.

The core of the script is a Perl module USNaviguide_Google_Tiles written in 2008 by John D. Coryat (who made it available under Apache 2.0 license). This module is able to convert the numerical names of tiles into their geographical coordinates. I wrote a little wrapper, clusterize.pl, around this script that does the following:
  • It creates a KML file with clusters of the tiles (for all or only for a given map type). You can open this file in Google Earth and easily see where are your map tiles from.
  • It generates another Perl script, tiles-remover.pl, that can be used to delete some tile clusters. You can choose to delete all tiles for a particular map type, or just tiles from some clusters.
The script wrapper, including the original John's script is available here. After unpacking, you can invoke it to get all options:
clusterize.pl -help
For example, this invocation:
clusterize -input /home/blah/maps -kml my-tiles.kml
 will read all map tiles from your directory /home/blah/maps and creates a file my-tiles.kml and a file tiles-removal.pl. It was written for Linux.

Friday, July 8, 2011

How to convert Google Maps to GPX file

The best tool to do that is the bookmarklet GMapToGPX. But after recent (June 2011) changes in Google Maps,  it stopped to work with maps created as "My Places" (aka "My Maps"). Until the author updates the bookmarklet (I hope it will be possible with the new Google Maps), there is a simple workaround (I found it here):

  • Take a link of your map from the Google Maps web site. This link is either directly available under a small "chain" image (works in Google Chrome browser but not in my Firefox), or in the text of email created by the "send" image (works in all browser I have tried)...
  • ...and add to it: "&output=kml". Then convert, as with GMapToGPX before, the resulting KML file to a GPX file using an excellent GPSVisualizer.
The created KML file may have (usually has) some (formatting) HTML tags in its waypoint description fields. The GPSVisualizer converts correctly these tags into formally correct GPX file. For example, changing all "<" characters to sequences of "&lt;". But very often these HTML formatting tags are not recognized by the software using such GPX file (e.g. Maverick map software on Android), and are displayed as normal text which does not look correct. Therefore, I am using a small Perl script that first removes these tags from the KML file and only after that I fill the updated KML file into GPSVisualizer. The script "update-kml.pl"can be downloaded from here and one can use it this way:
perl update-kml.pl < input.kml > output.kml

Upravena sablona pro exportovani z GeoGetu

GeoGet je databaze vybranych geokesi, pripadne s pridanymi souradnicemi dalsich waypointu, nejcasteji se jedna o finalni souradnice vylustenych mysterek. Aby se tyto souradnice dostaly do vaseho GPS, je nutno je exportovat do GPX souboru a ten pak nahrat do GPS (nechme ted stranou trochu slozitejsi moznost s tzv. POI soubory).

GeoGet nabizi nekolik moznosti, jak ma vysledny GPX soubor vypadat a co v nem vsechno ma byt. Kazda z moznosti je trochu jina, ale dokumentace je (aspon v dobe psani tohoto prispevku) miziva. Nejlepe je tedy si to vyzkouset nebo se podivat primo do sablon (scriptu) GeoGetu, Sablony pro export jsou textove soubory v adresari "...kde-je-instalovan-vas-GeoGet\data\script\export\". Sablony jsou prehledne, dobre napsane, ale je treba trochu rozumnet programovani, aby se lepe chapaly.

Patrne nejbeznejsi volba je export "PocketQuery GPX". Ta vytvori GPX soubor se vsemi geokesemi a jejich waypointy ve stejnem formatu jako jsou PocketQuery primo z geocaching.com. Tento soubor je plne kompatibilni a vas GPS (pouzivam Oregon) s nim nema problemy. Az na to, ze ty waypointy nemaji vsechny informace, ktere by mohly mit. Tedy lepe receno, vytvoreny GPX soubor tyto informace ma, ale jsou na miste, kde je vas Oregon bude ignorovat. Proto jsem si vytvoril mirne upravenou sablonu.

Sablona je k dispozici zde; jmenuje se mygpxpq.gge.pas. Stahnete-li si ji, ulozte ji do vyse zmineneho adresare "...\data\script\export\". Kdyz pak v GeoGetu zacnete exportovat (nejrychleji pomoci Ctrl-E), objevi se vam ve volbach i ta nova:


A ted to hlavni - v cem se tato sablona lisi od te puvodni:

  • V exportu samotnych geokesi nejsou zadne zmeny. Menit neco tam by znamenalo menit format predepsany Groundspeakem.
  • Hlavni zmena je v popisu waypointu. V puvodni sablone se tento popis uklada do vystupniho policka "cmt", ktere ale Oregon ignoruje. Proto nova sablona popis waypointu dava do policka "desc" (kam puvodni sablona dava jen jmeno waypointu).
  • Popis se jeste lisi podle toho, jaky waypoint to je. Pokud jde o finalni waypoint (napr. finalni souradnice vylustene mysterky), nova sablona dava do popisu puvodni hint z geocache. Pro ostatni waypointy tam dava text, ktery byl zapsan do kolonky "Cmt":

 

  • Pouzivani hintu do popisu je diskutabilni, protoze ve vystupu natvrdo prepise to, co jste mozna sami zapsali v GeoGetu do "Cmt" kolonky. V obrazku nahore je text "u stromu" totozny s hintem, takze se nic nestane, kdybyste ale sem byli byvali zapsali neco vic nebo neco jineho, do vystupniho GPX by to neprislo. Jak rikaji Anglicane, take it or leave it (nebo pripadneji: zmente si sablonku; nejlepe by asi bylo porovnavat v ni hint s "Cmt" textem a podle toho tam dat to ci ono; mozna to nekdy napravim).
  • Pozor take na to, ze Oregon pouzije z pole "desc" jen prvnich 49 znaku, zbytek ignoruje. Na hinty to obvykle staci, ale nemusi. Jine reseni, ktere toto omezeni ma daleko volnejsi (dovolujici vice nez 100 znaku pro popis), je vytvaret waypointy jako body POI (ale o tom snad jindy).
  • Nova sablona take finalnim waypointum prirazuje specificky symbol, zeleny spendlik:
  •  A konecne jsem z waypointu odstranil vystupni pole "url" a "urlname", aby soubor byl kratsi - nikde jsem nevidel, ze by je Oregon pouzival. Rad to ale vratim zpatky, najdu-li pro tato pole vyuziti (v sablone tato cast zustala, jen je ted pouhou poznamkou).

Friday, March 4, 2011

Filtrovani v programu GeoGet


Program GeoGet (vase osobni databaze geokesi na vasem pocitaci) je dobry, ma mnoho funkci - ale zaroven je, podle meho nazoru, uzivatelsky nestandardni, nekdy az zavadejici. Je to samozrejme otazka zvyku. Hodila by se lepsi dokumentace - pak by mozna uzivatelska privetivost byla dostatecna.

Chvili mi trvalo, nez jsem se naucil pouzivat filtrovani tak, jak jsem potreboval. Mozna to porad nedelam tim nejlepsim zpusobem, ale aspon to funguje, jak chci :-)

Nejdrive trochu terminologie: GeoGet rika "seznam" (anglicky "list") tomu, co je prave zobrazeno na obrazovce. Pokud v takovem seznamu nejake polozky ubirate nebo pridavate, tak se to deje jen na obrazovce, nikoliv v databazi geokesi (pro vymazani z databaze jsou v GeoGetu jine funkce). Nejcastejsi zpusob (krome rucniho ubirani nebo pridavani radek), jak seznam vytvorit, je uzit nejaky "filter". Pozor ovsem na to, ze prostym vyberem filtru, se seznam na obrazovce nezmeni. To musite udelat rucne (bud stisknout "load" - je na nekolika mistech) nebo, casteji, stisknout klavesu F5. Tak se na obrazovce zobrazi jen ty kese, ktere odpovidaji prave vybranemu filtru.

Pak jeste GeoGet pouziva termin "tag", coz je libovolna poznamka, kterou muzete priradit k jedne nebo vice kesim. Nektere poznamky si vytvorite sami (treba poznamku "tohle je kes, kterou jsem navstivil s manzelkou"), nektere poznamky (tagy) jsou v GeoGetu uz predpripravene (takze je staci jen vybrat). Na priklad: vytvorim nejdrive novou kategorii tagu "Navstiveno spolu" a pak vytvorim dve hodnoty (dva tagy) v teto kategorii: "s manzelkou" a "s milenkou". Tagy jsou vhodne kriterium pro filtrovani - budu moci, napriklad, vybrat jen ty kese, ktere jsem jeste nenavstivil ani s manzelkou ani s milenkou.

"So far so good..." Komplikace nastanou, kdyz chceme kombinovat vice filtru, a navic, kdyz nektere filtry jsou zavisle na nekolika "tagach". Chceme treba rici "Zobraz vsechno, co odpovida filtru A, ale co zaroven neodpovida filtru B ani C". To neni teoreticka kombinace, to je ta, kterou pravidelne potrebuji. Zde je, co mam a co bych rad:

  • Jde mi o kese v Praze.
  • Chci vsechny typy krome eventu.
  • Ale u mysterek chci jen ty, co mam vyresene anebo ty, ktere jsem oznacil tagem v kategorii "Stage" s hodnotu "PreFinal". Jinymi slovy, vyresim-li mysterku se vsim vsudy a mam jeji finalni souradnice, nepotrebuji k ni pridavat zadny muj osobni tag, protoze staci, kdyz k ni pridam finalni waypoint (volba "add waypoint"). GeoGet mi uz vetsinou sam spravne nabidne waypoint typu "Final location" se jmenem "Final" a prefixem "FI". Kdyz ale jeste potrebuji nekam zajit a neco k mysterce jeste zjistit, pridam ("edit tags") k takove mysterce muj osobni tag "PreFinal" me kategorie "Stage".
  • A u multi-kesi chci jen ty, ktere mam take otagovany kategorii "Stage" s hodnotou "PreFinal" - tak oznacuji ty multinky, ktere mam v umyslu navstivit (zrejme proto, ze jsem jich uz cast nasbiral drive).

Vytvorim si nekolik filtru - ktere pak budu "skladat" dohromady, abych dostal seznam podle mych predstav. Filtry se vytvareji jednou provzdy - nemusim je delat znovu a znovu pokazde, co importuji nove kese do GeoGetu. Prvi pojmenuji "Prague - to load to GPS". Vyberu tam vsechno z Prahy:




Pak si vytvorim filter "Prague - remove unresolved". Tam definuji jen mysterky - a to pouze ty, ktere nemaji "Your final waypoint" a ktere nemaji tag "Stage" s hodnotou "PreFinal":





Konecne si vytvorim filter "Prague - remove rest of multi", kde budou multi-cache, u kterych nemam tag "PreFinal" (a tedy mne jeste nezajimaji):





Mam-li vsechny filtry, zbyva mi je nez zkombinovat do vysledneho seznamu. Toto kombinovani musim delat pokazde, kdyz chci takovy seznam. Nenasel jsem zpusob, jak si kombinaci uchovat do nejakeho "kombinovaneho filtru" (mozna tady je to misto, ktere jsem z GeoGetu jeste uplne nepochopil). Takze udelam tohle:


  • Nastavim filter "Prague - to load to GPS" a stisku F5. Tim mam na obrazovce seznam vsech (mnou dosud nenalezenych) kesi v Praze (na obrazku dole je cislo 986, ktere rika, kolik ma tento seznam polozek):


  • Nyni nastavim filter "Prague - remove unresolved" a nestisknu klavesu F5, ale naopak kliknu na ikonku filtru (trychtyre) s cervenym minusem, coz znamena "odeber ze zobrazeneho seznamu polozky, ktere definuje prave zvoleny filter". Vsimnete si, ze se delka listu zmensila, list ma ted jen 660 polozek:


  • Nakonec odstranim jeste multi-kese, ktere nemam ve stavu "PreFinal". Vyberu filter "Prague - remove rest of multi" a opet stiknu jen trychtyrek s cervenym minusem. Dostavam seznam s 489 polozkami:


Ten seznam obsahuje presne to, co chci - a mohu jit exportovat do formatu GPX. Tech je take vice - a nenasel jsem je nikde zdokumentovany. Takze o nich snad priste. Ted si jen pamatuji, ze exportuji do formatu "Pocket Query GPX", ktery muj Oregon rozezna.

Friday, November 5, 2010

Mobile Atlas Creator and Garmin Custom Maps

The MOBAC is a very good program for downloading maps from various on-line sources (Google, Yahoo, Microsoft, OpenStreetMap, but also, for example, UK OS Maps, etc.) and putting their "tiles" together into atlases that can be used in many different mobile devices. I was using the maps in my Android-based mobile phone with two different mobile applications: Maverick and OruxMaps (the Maverick links has more details about MOBAC).

The Mobile Atlas Creator can also create an atlas as Garmin's Custom Maps. But in my case, the result was disappointing (bad image resolution, maps were not really readable). But perhaps I was using wrong input parameters. I have found a good tutorial that may help to get better results: http://gpsteam.eu/guide/MOBAC_KMZ/MOBAC_GarminKMZ.htm.

Just to remind you how good the MOBAC is, here is a screenshot of a CykloAtlas from the Czech Republic (no, this is not the Garmin Custom map; this is a screenshot from the Mobile Atlas on the PC):

How to use OpenStreet maps in Garmin GPS

Garmin GPS (at least in Oregon and similar devices) can be enhanced by so called "Custom maps". Their usage, at least from my experiences, is limited to small maps (like park or campus plans). However, there are many open, large-scale maps around, notably in the OpenStreetMap project, that would be great to have in your GPS device (some of them are even routable, navigable). I was very pleased when a friend of mine told me that it was, indeed, possible.

The main site where are all the gory details is this: http://wiki.openstreetmap.org/wiki/OSM_Map_On_Garmin. Here is just a quick start how to do it:
  • Find a map you are interested in and download it to your computer. A good place to start with is here: http://garmin.na1400.info/routable.php. The downloaded file has a file extension ".img" (e.g. 632490265.img). The mentioned site allows to download one tile as an ".img" file, or you can combine more tiles into one ".img" file (using the option "Build your map").
  • On the SD card of your Garmin GPS, create a directory "Garmin" and copy there your downloaded ".img" file but rename it to "gmapsupp2.img" - if it is not the first file there, increase the number (e.g your files may be "gmapsupp2.img", "gmapsupp3.img",...).
That's is.

Once you have a map in your Garmin device, however, you may start looking for how to see the same map also on your PC in the Garmin's MapSource program. That would give you a better chance for planning and evaluating the trips. And, indeed, it is also possible. The detailed instructions are here: http://freegeographytools.com/2007/adding-garmin-img-files-to-mapsource. You have to install first two programs on your PC: MapSetToolkit and cGPSmapper, and than follow the instructions. Here is an example of a map from the West Australie (town Geraldton):

Friday, October 8, 2010

Android map applications

There is an incredible application Maverick that shows several different maps, including the Google Maps, and - what is the punch line - it caches them for the offline usage. Once you browse them on your phone (e.g. using the free WiFi connection), you can go out, stay offline and you still see and use the maps! Only in the zoom levels that you browsed them at home, of course. There is a free version of Maverick and then there is a Maverick Pro version. These versions differ in number of custom waypoints, and perhaps in few other details, but the main feature, the map caching, is in both of them.

Maverick can also be used for recording your tracks.