Saturday, April 19, 2008

Gmaps to DSmaps converter

I've been playing around with the fantastic DS homebrew app DSmaps and found it pretty useful. One great feature is that it caches areas you've already viewed and you can go through them later (i.e. when you're out and about and get lost)

But what if you're lost and you haven't looked at that area already, and there's no free wifi around to grab those missing tiles? Well if you know you are going to be somewhere unfamiliar you could just pan around that area at various zoom levels before you leave hoping you've viewed everywhere you will be going and hope you don't miss anywhere, but ideally you'd be able to select a certain geographical area, downloads all the tiles for that space at all the zoom levels you want and have them ready to go. A bit of googling around led me to gMapMaker which lets you do just that, however it grabs the tiles in Google's QRST quadtree naming scheme, whereas DSmaps stores the tiles as a directory for the X coordinate, containing a subdirectory for the Y coordinate, which then contains the actual tile named as the zoom level. (once you get down past the 256 x 256 level X and Y data starts going into the filename as well, as DSmaps only uses a max 2 characters per directory)

So I thought as I'm wanting to learn how to write perl scripts I'd have a go at one to convert from the Gmaps naming to the DSmaps naming. I based it off a code snippet found here to figure out the X, Y and zoom values, then converted them to hex and used that to generate the DSmaps paths and files. You can grab the Perl script here. The script was written and tested on a Windows XP machine, no idea if it'll work on other platforms.

Before we get to using the script, a few notes. This is the 2nd script I've ever written, so it is probably not the best way of doing things, any pointers on how I could have done it better are welcome. BACK UP YOUR CARD FIRST. Sorry about the caps, but you never know when something might go wrong and I'm not responsible if your card gets corrupted, your dog catches fire and aliens enslave humanity due to this script. You can feel free to redistribute or modify the script as you see fit, however a credit or at least a link back to this post would be appreciated. If you do give it a go, please post a comment and let me know what you think.

Shutup already, how do you use the thing!

To use the script, you'll need to install Perl, which you can get for Windows from ActiveState. Once you've got that set up, put the script in a directory (doesn't matter where) and create a subdirectory under that called 'gtiles'. Fire up gMapMaker and enter the coordinates bounding the area you want to grab, the zoom level you are after and select 'driving maps only' and set the operating mode to 'Download tiles'. Click Go and once it grabs all the tiles you will find you have a directory called 'mt' in the cache folder which has a directory for each zoom level you have grabbed. Copy the files from these directories to the 'gtiles' directory you created (just the files, don't copy the directories themselves) and run the script ( go to a command prompt, change to the directory you dropped the script in and type 'perl qrst2xyz.pl'. If all goes well, you should see that you now have a directory structure suitable for DSmaps all ready to go, copy this over to the DSMAPS folder on the card you use in your DS and fire up DSmaps. You should now be able to pan and zoom around offline as long as you stay within the area and zoom levels that you have grabbed.

And because I know some of you will be thinking it, yes you could theoretically download all the tiles at all the zoom levels and have the entire planet (que evil genius laugh), however we are talking in excess of 270 million files here, weighing in at around 2.7 terabytes, so good luck finding a card to get that onto your DS :P.

17 Comments:

At 7:05 PM, Anonymous Anonymous said...

Hi there,
Thanks for your great invention. I really appreciate.
I tried to follow your steps, but didn't work. If you could please check if I did it correctly?
1. installed
ActivePerl 5.10.0.1002 Windows (x86): MSI - 14.9MB ...right?
2. is your pearl script size 0kb?

I followed all your steps, but when I ran your script, nothing happenned to those image tiles I put under "gtiles" folder??

Thank you again,
Nat

 
At 7:58 AM, Blogger Dave said...

The script should be about 2KB, looks like the download link is broken, I've added a new one at http://www.filecrunch.com/fileDownload.php?sub=84401e3c3909878662f18080a0332372&fileId=142882 , just remove the 'renamethis' extension. (looks like they don't like file extensions that could be executed by your browser, probably why the other link died)

 
At 2:25 PM, Anonymous Anonymous said...

Dave,
I have been trying to make my DsMap useable in real life.
Now, my dream came true!

You rock!
Nat

 
At 1:13 AM, Anonymous Anonymous said...

Hi, could you please upload your file once more? :)
Your download link does not seem to work anymore...

Thanks,
Markus

 
At 2:12 AM, Blogger Muhmops said...

That's right, it can't be downloaded. :(

 
At 1:43 PM, Blogger Unknown said...

Your download link is broken again. Any chance of a re upload?

 
At 7:14 PM, Blogger Dave said...

Sorry guys, didn't realise the link was dead again, I've changed it to one that shouldn't go away any time soon.

 
At 7:46 PM, Blogger Unknown said...

Hmmm. see, heres the thing. Either gMaps doesn't work properly or Google got wise to it, because it only fetches a small portion of the map data from google. E.g. building a merged map only shows the outer portions of where you have asked for. Did you have similar problems?

 
At 4:20 PM, Blogger Dave said...

Hmmm, reading over some other forums it seems google may be stopping a lot of these tools working. The latest version of gmapmaker supports microsoft's maps as well as yahoo maps, so you could try grabbing the images from there, I haven't tried it with the script though so you'll just have to see if they come down in the same format. New version of gMapMaker is here:
http://www.mgmaps.com/cache/gMapMaker-setup.exe

 
At 6:14 PM, Blogger Dave said...

Just tried it with MSMaps, works fine, so I guess now it's a MSMaps to DSmaps converter :P

 
At 10:54 AM, Anonymous Anonymous said...

Your script rocks ! I followed all your instructions and everything is perfect. I'm working on the road so I often need to consult maps and I will not buy a GPS because I found your woderfull script. Thanks a lot !

 
At 6:20 PM, Anonymous Anonymous said...

I'd love to use this, I dloaded and installed everything but, sorry, I don't have the slightest idea where to get the coordinates to put into gmapmaker and what i have to put in "hash size". I'm in msn maps looking at the area I want to dload and I can't see anything anymore...

can anyone help this dumb girl?

 
At 8:24 PM, Anonymous Anonymous said...

ok I did everything, got the tiles from gmapmaker, but when i use the script it converts all tiles to the same file, so in the end there's only one folder with one file (just one little portion of the map)

what am i doing wrong?

 
At 8:27 AM, Anonymous Anonymous said...

I have the same problem. Only one or two files are created with the same name. The naming don't seem to work. The file names created begin with "000000" and then a number or a letter and finally ".GMT". If you could fix the script or tell us what we do wrong I would be very grateful.

 
At 8:50 AM, Anonymous Anonymous said...

could anyone upload the full files in a winrar or something with the map of santiago of chile?

 
At 4:50 PM, Blogger WarRock said...

This comment has been removed by the author.

 
At 4:51 PM, Anonymous Devyll said...

Hello,
I Was using your script and got it working to all the files I downloaded.
The problem is, when I put it into DSMaps folder, I can't see anything.

Here's what I did:
I copied all Files and Dirs generated by the script to the "DSMaps" folder. The tiles are in the 17th Zoom Level.
Is that correct? Or do I have to make a folder named "17" on the DSMaps folder and put inside all the files generated by the script? Thanks!

 

Post a Comment

<< Home