I would install gdal2tiles.py and try it out and look at the code. You'll
have a working command line tile cutter out of the box, and it's written in
very readable Python code if you need to see how it's done. (The
GlobalMercator class has the calculations you're interested in.)

The best instructions for installing this are here:

http://help.maptiler.org/betatest/

Scroll to the section with the 8-step procedure (!) near the end. I followed
those steps to the letter, except that I also selected gdal17 and
gdal17-python along with gdal16 and gdal16-python, and where they have you
type gdal16 in step 7, I used gdal17. I figured it wouldn't hurt to try the
newer version, and it's working fine.

I already had Python installed; you'd need that first if you don't have it.

There are instructions for other OSes at the very end of the page; I only
tried it on Windows.

Once installed (on any platform), you'll find the gdal2tiles.py code in the
bin directory of your OSGeo installation. Run the special OSGeo shell and do
the gdal17 command inside it (or gdal16) and then you should have a
gdal2tiles command you can run directly from the command line (there's a
.bat file on Windows, and presumably a shell script on other platforms, that
runs the actual "python your-install-path/bin/gdal2tiles.py" command for
you).

As an example of what you can do with it, I was just given a directory of
GeoTiff files (.tif files with geocoding embedded in them) and needed to
generate tiles for them in a hurry, with a couple of colors (black and gray)
changed to transparent in the output tiles. I used this Python script:

# -*- coding: utf-8 -*-

import os, os.path, re, subprocess

def main():
    tileGeoTiffs()

def tileGeoTiffs():
    for tiff in os.listdir( '.' ):
        if os.path.isdir( tiff ): continue
        if tiff.find( '.tif' ) < 0: continue
        png = tiff.replace( '.tif', '.png' )
        tiffToPng( tiff, png )
        changePng( png )
        tilePng( png )

def tiffToPng( tiff, png ):
        print 'Converting %s to PNG' % tiff
        cmd( 'gdal_translate -of PNG %s %s' %( tiff, png ) )

def changePng( png ):
        print 'Converting pixels in %s' % png
        cmd( '''
            gm convert
                "%s"
                -type TrueColorMatte
                -transparent "rgb(0,0,0)"
                -transparent "rgb(128,128,128)"
                "%s"
        ''' %( png, png ) )

def tilePng( png ):
        print 'Tiling %s' % png
        cmd( 'gdal2tiles.bat -z 0-14 %s' % png )

def cmd( text ):
    subprocess.check_call( oneLine(text) )

def oneLine( text ):
    text = re.sub( r'\s*\n+\s*', ' ', text )
    text = re.sub( r'^\s+', '', text )
    return text

if __name__ == "__main__":
    main()

This was just a hack tested only on Windows (note the .bat command) but
could be easily adapted to other OSes - most of it other than that one line
should be portable.

It also requires GraphicksMagick which needs to be installed separately, or
could be adapted to use ImageMagick by changing "gm convert" to "convert" in
the changePng() function.

You can do all sorts of image transformations in that [gm] convert command -
for example I had some images that used grayscale values of 0 and 1 to
represent some pixel data - so I changed the 1's to be more visible using
this code added to the gm convert:

                -fill "#FFBF60" -opaque "rgb(1,1,1)"

It isn't significant that this uses both # and rgb() notation - that was
probably just sloppy coding on my part. :-)

It also isn't significant that this script (the code above) is written in
Python - you could do this part in any shell or scripting language, but
since Python is already a requirement for gdal2tiles.py I used it for this
script too.

-Mike

On Mon, Nov 22, 2010 at 5:48 PM, William Katsak <[email protected]> wrote:

> Hello,
>
> I realize that this may be the wrong place to ask, but I am hoping that
> someone can at least point me in the general direction that I need to go.
>
> I am designing an application that uses Google Maps. I am using GWT for the
> app, and the GWT classes mostly make sense. The issue I am having is that
> the data sets that I am trying to visualize are too big for markers at
> further zooms, so I am trying to figure out how to generate overlay tiles.
>
> I have a data source (list of addresses) that are already geocoded. I want
> to be able to generate sets of tiles, either server side or offline. I have
> no problem writing my own tileserver, but what is being elusive is me is how
> to figure out what pixel/tile coordinates a certain lat/long point
> corresponds to. I realize that Maps uses a Mercator projection, but I
> imagine that Google must have an "official" algorithm for doing the
> conversion.
>
> Any pointers would be much appreciated.
>
> Thanks,
> Bill
>
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Google Maps API V2" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<google-maps-api%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-maps-api?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Maps API V2" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-maps-api?hl=en.

Reply via email to