geotrellis.raster

TileUtils

object TileUtils extends AnyRef

Utility functions for working with web mercator tile systems.

Some code and documentation adapted from gdal2tiles.

See this site for a great little intro: http://www.maptiler.org/google-maps-coordinates-tile-bounds-projection

It contains classes implementing coordinate conversions for:

More info at:

http://wiki.osgeo.org/wiki/Tile_Map_Service_Specification http://wiki.osgeo.org/wiki/WMS_Tiling_Client_Recommendation http://msdn.microsoft.com/en-us/library/bb259689.aspx http://code.google.com/apis/maps/documentation/overlays.html#Google_Maps_Coordinates

TMS Global Mercator Profile ---------------------------

Functions necessary for generation of tiles in Spherical Mercator projection, EPSG:900913 (EPSG:gOOglE, Google Maps Global Mercator), EPSG:3785, OSGEO:41001.

Such tiles are compatible with Google Maps, Microsoft Virtual Earth, Yahoo Maps, UK Ordnance Survey OpenSpace API, ... and you can overlay them on top of base maps of those web mapping applications.

Pixel and tile coordinates are in TMS notation (origin [0,0] in bottom-left).

What coordinate conversions do we need for TMS Global Mercator tiles::

LatLon <-> Meters <-> Pixels <-> Tile

WGS84 coordinates Spherical Mercator Pixels in pyramid Tiles in pyramid lat/lon XY in metres XY pixels Z zoom XYZ from TMS EPSG:4326 EPSG:900913 .----. --------- -- TMS / \ <-> | | <-> /----/ <-> Google \ / | | /--------/ QuadTree ----- --------- /------------/ KML, public WebMapService Web Clients TileMapService

What is the coordinate extent of Earth in EPSG:900913?

[-20037508.342789244, -20037508.342789244, 20037508.342789244, 20037508.342789244] Constant 20037508.342789244 comes from the circumference of the Earth in meters, which is 40 thousand kilometers, the coordinate origin is in the middle of extent. In fact you can calculate the constant as: 2 * math.pi * 6378137 / 2.0 $ echo 180 85 | gdaltransform -s_srs EPSG:4326 -t_srs EPSG:900913 Polar areas with abs(latitude) bigger then 85.05112878 are clipped off.

What are zoom level constants (pixels/meter) for pyramid with EPSG:900913?

whole region is on top of pyramid (zoom=0) covered by 256x256 pixels tile, every lower zoom level resolution is always divided by two initialResolution = 20037508.342789244 * 2 / 256 = 156543.03392804062

What is the difference between TMS and Google Maps/QuadTree tile name convention?

The tile raster itself is the same (equal extent, projection, pixel size), there is just different identification of the same raster tile. Tiles in TMS are counted from [0,0] in the bottom-left corner, id is XYZ. Google placed the origin [0,0] to the top-left corner, reference is XYZ. Microsoft is referencing tiles by a QuadTree name, defined on the website: http://msdn2.microsoft.com/en-us/library/bb259689.aspx

The lat/lon coordinates are using WGS84 datum, yeh?

Yes, all lat/lon we are mentioning should use WGS84 Geodetic Datum. Well, the web clients like Google Maps are projecting those coordinates by Spherical Mercator, so in fact lat/lon coordinates on sphere are treated as if the were on the WGS84 ellipsoid.

From MSDN documentation: To simplify the calculations, we use the spherical form of projection, not the ellipsoidal form. Since the projection is used only for map display, and not for displaying numeric coordinates, we don't need the extra precision of an ellipsoidal projection. The spherical projection causes approximately 0.33 percent scale distortion in the Y direction, which is not visually noticable.

How do I create a raster in EPSG:900913 and convert coordinates with PROJ.4?

You can use standard GIS tools like gdalwarp, cs2cs or gdaltransform. All of the tools supports -t_srs 'epsg:900913'.

For other GIS programs check the exact definition of the projection: More info at http://spatialreference.org/ref/user/google-projection/ The same projection is degined as EPSG:3785. WKT definition is in the official EPSG database.

Proj4 Text: +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs

Human readable WKT format of EPGS:900913: PROJCS["Google Maps Global Mercator", GEOGCS["WGS 84", DATUM["WGS_1984", SPHEROID["WGS 84",6378137,298.2572235630016, AUTHORITY["EPSG","7030"]], AUTHORITY["EPSG","6326"]], PRIMEM["Greenwich",0], UNIT["degree",0.0174532925199433], AUTHORITY["EPSG","4326"]], PROJECTION["Mercator_1SP"], PARAMETER["central_meridian",0], PARAMETER["scale_factor",1], PARAMETER["false_easting",0], PARAMETER["false_northing",0], UNIT["metre",1, AUTHORITY["EPSG","9001"]]]

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Hide All
  2. Show all
  1. TileUtils
  2. AnyRef
  3. Any
Visibility
  1. Public
  2. All

Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  5. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  6. def GoogleTile(tx: Int, ty: Int, zoom: Int): (Int, Double)

    Converts TMS tile coordinates to Google Tile coordinates (again, see http://www.

    Converts TMS tile coordinates to Google Tile coordinates (again, see http://www.maptiler.org/google-maps-coordinates-tile-bounds-projection/)

  7. def LatLonToMeters(lat: Double, lon: Double): (Double, Double)

    Converts given lat/lon in WGS84 Datum to XY in Spherical Mercator EPSG:900913

  8. def MetersToLatLon(mx: Double, my: Double): (Double, Double)

    Converts XY point from Spherical Mercator EPSG:900913 to lat/lon in WGS84 Datum

  9. def MetersToPixels(mx: Double, my: Double, zoom: Int): (Int, Int)

    Converts EPSG:900913 to pyramid pixel coordinates in given zoom level

  10. def MetersToTile(mx: Double, my: Double, zoom: Int): (Int, Int)

    "Returns tile for given mercator coordinates"

  11. def PixelsToMeters(px: Int, py: Int, zoom: Int): (Double, Double)

    Converts pixel coordinates in given zoom level of pyramid to EPSG:900913

  12. def PixelsToRaster(px: Int, py: Int, zoom: Int): (Int, Int)

    Move the origin of pixel coordinates to top-left corner

  13. def PixelsToTile(px: Int, py: Int): (Int, Int)

    Returns a tile covering region in given pixel coordinates

  14. def QuadTree(tx: Int, ty: Int, zoom: Int): String

    Converts TMS tile coordinates to Microsoft QuadTree

  15. def Resolution(zoom: Int): Double

    Resolution (meters/pixel) for given zoom level (measured at Equator)

  16. def TileBounds(tx: Int, ty: Int, zoom: Int): (Double, Double, Double, Double)

    Returns bounds of the given tile in EPSG:900913 coordinates

  17. def TileLatLonBounds(tx: Int, ty: Int, zoom: Int): (Double, Double, Double, Double)

    Returns bounds of the given tile in latutude/longitude using WGS84 datum

  18. def ZoomForPixelSize(pixelSize: Double): Unit

    Maximal scaledown zoom of the pyramid closest to the pixelSize.

  19. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  20. def clone(): AnyRef

    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  21. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  22. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  23. def finalize(): Unit

    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  24. final def getClass(): java.lang.Class[_]

    Definition Classes
    AnyRef → Any
  25. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  26. val initialResolution: Double

  27. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  28. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  29. final def notify(): Unit

    Definition Classes
    AnyRef
  30. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  31. val originShift: Double

  32. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  33. val tileSize: Int

  34. def toString(): String

    Definition Classes
    AnyRef → Any
  35. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()
  36. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()
  37. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()

Inherited from AnyRef

Inherited from Any