Class GlobalMercator
- Author:
- zhangjianshe <zhangjianshe@gmail.com>
TMS Global Mercator Profile ---------------------------
Functions necessary for generation of tiles in Spherical Mercator projection, EPSG:3857.
Such tiles are compatible with Google Maps, Bing Maps, 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 meters XY pixels Z zoom XYZ from TMS EPSG:4326 EPSG:3875 .----. --------- -- TMS / \ <-> | | <-> /----/ <-> Google \ / | | /--------/ QuadTree ----- --------- /------------/ KML, public WebMapService Web Clients TileMapService
What is the coordinate extent of Earth in EPSG:3857?
[-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:3857 Polar areas with abs(latitude) bigger then 85.05112878 are clipped off.
What are zoom level constants (pixels/meter) for pyramid with EPSG:3857?
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, yes?
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 noticeable.
How do I create a raster in EPSG:3857 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:3857'.
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 designated as EPSG:3857. 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 EPSG:3857: PROJCS["Google Maps Global Mercator", GEOGCS["WGS 84", DATUM["WGS_1984", SPHEROID["WGS 84",6378137,298.257223563, 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"]]]
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncn.mapway.geo.shared.vector.PointgeoToTile(double lng, double lat, double tx, double ty, int zoom) 地理坐标 转化为 tile内像素坐标 (256*256) 坐标系为 左下角为坐标原点static GlobalMercatorget()全局获取墨卡托参数信息byte[]获取一个波段数据cn.mapway.geo.shared.vector.BoxlngLatBoxToTileBox(cn.mapway.geo.shared.vector.Box lngLat, int zoom) 给定一个经纬度坐标范围 返回一个 墨卡托坐标系下 zoom级别中对应的 瓦片范围cn.mapway.geo.shared.vector.PointlngLatToMeter(double lng, double lat) "Converts lon/lat to pixel coordinates in given zoom of the EPSG:4326 pyramid" 经纬度 转化为 以mi为单位的坐标cn.mapway.geo.shared.vector.PointlngLatToTile(double lng, double lat, int zoom) 经纬度所在的tile编号static voidcn.mapway.geo.shared.vector.BoxmeterToGeo(cn.mapway.geo.shared.vector.Box meter) 墨卡托坐标 转化为经纬度cn.mapway.geo.shared.vector.PointmeterTolngLat(double mx, double my) "Maximal scaledown zoom of the pyramid closest to the pixelSize." 墨卡托 以米为单位的坐标 转化为WGS84经纬度坐标cn.mapway.geo.shared.vector.PointmeterToPixels(double mx, double my, int zoom) Converts EPSG:3857 to pyramid pixel coordinates in given zoom level"cn.mapway.geo.shared.vector.PointmeterToTile(double mx, double my, long tileX, long tileY, int zoom) 墨卡托坐标 在 tile下的像素坐标cn.mapway.geo.shared.vector.PointpixelsToMeters(double px, double py, int zoom) "Converts pixel coordinates in given zoom level of pyramid to EPSG:3857" tile (tx,ty)对应的经纬度范围 墨卡托 tile编码规则 左上角 为(0,0) 向右向下生长 墨卡托坐标单位 为 mi 坐标原点为 将 中央子午线和赤道的交点 (0,0) 这个方法 将 像素坐标 转化为 以mi为单位的 墨卡托坐标cn.mapway.geo.shared.vector.PointpixelsToRaster(double px, double py, int zoom) "Move the origin of pixel coordinates to top-left corner"cn.mapway.geo.shared.vector.PointpixelToTile(double px, double py) "Returns a tile covering region in given pixel coordinates"doubleresolution(int zoom) "Resolution (meters/pixel) for given zoom level (measured at Equator)"cn.mapway.geo.shared.vector.BoxtileBounds(double tx, double ty, int zoom) "Returns bounds of the given tile in EPSG:3857 coordinates"cn.mapway.geo.shared.vector.BoxtileBoundsWebMercator(double tx, double ty, int zoom) 某一个级别下的瓦片编号 tx ty ,计算其WEB墨卡托的像素坐标 (tx ty) 左上角为 (0,0) 向右 向下 增加 WEB墨卡托 所坐标系定义 (地图中心点为坐标原点) (tx*512 , ty*512)是一个世界坐标系 第0级是一个 512*512图片 对应一个地球表面 赤道上 每个像素对应的地面距离为 RES= 2*PI*r/512 第n级赤道上每个像素对应的地面距离为 RES/2^ncn.mapway.geo.shared.vector.BoxtileBoundWgs84(double tx, double ty, int zoom) tile (tx,ty)对应的经纬度范围 墨卡托 tile编码规则 左上角 为(0,0) 向右向下生长 墨卡托坐标单位 为 mi 坐标原点为 将 中央子午线和赤道的交点 (0,0)cn.mapway.geo.shared.vector.BoxtileLngLatBounds(long tx, long ty, int zoom) 墨卡托坐标下 tile的编号规则 左下角的编号为 (0,0) 向右 向上增加 WGS坐标 统一称做 gps坐标cn.mapway.geo.shared.vector.BoxtileNoBoxToLngLatBox(cn.mapway.geo.shared.vector.Box tileNo, int zoom) 给定瓦片的范围 范围其经纬度信息范围static TileNotileNoFromWgs84(double lat, double lng, int zoom) 经纬度坐标 所在的tile索引 参考 https://wiki.openstreetmap.org/wiki/Slippy_map_tilenamesintzoomForPixelSize(double pixelSize) "Maximal scaledown zoom of the pyramid closest to the pixelSize."
-
Field Details
-
MAXZOOMLEVEL
public final int MAXZOOMLEVEL- See Also:
-
EARTH_RADIUS
public final long EARTH_RADIUS- See Also:
-
-
Constructor Details
-
GlobalMercator
public GlobalMercator(int tileSize)
-
-
Method Details
-
main
-
get
全局获取墨卡托参数信息- Returns:
-
getWhiteBand
public byte[] getWhiteBand()获取一个波段数据- Returns:
-
meterTolngLat
public cn.mapway.geo.shared.vector.Point meterTolngLat(double mx, double my) "Maximal scaledown zoom of the pyramid closest to the pixelSize." 墨卡托 以米为单位的坐标 转化为WGS84经纬度坐标- Parameters:
mx-my-- Returns:
-
lngLatToMeter
public cn.mapway.geo.shared.vector.Point lngLatToMeter(double lng, double lat) "Converts lon/lat to pixel coordinates in given zoom of the EPSG:4326 pyramid" 经纬度 转化为 以mi为单位的坐标- Parameters:
lng-lat-- Returns:
-
lngLatToTile
public cn.mapway.geo.shared.vector.Point lngLatToTile(double lng, double lat, int zoom) 经纬度所在的tile编号- Parameters:
lng-lat-- Returns:
-
pixelsToMeters
public cn.mapway.geo.shared.vector.Point pixelsToMeters(double px, double py, int zoom) "Converts pixel coordinates in given zoom level of pyramid to EPSG:3857" tile (tx,ty)对应的经纬度范围 墨卡托 tile编码规则 左上角 为(0,0) 向右向下生长 墨卡托坐标单位 为 mi 坐标原点为 将 中央子午线和赤道的交点 (0,0) 这个方法 将 像素坐标 转化为 以mi为单位的 墨卡托坐标(0,0) +------------------------------- | | | | | | |---------------|(0,0)--------------- py*res | | | |
- Parameters:
px-py-zoom-
-
meterToPixels
public cn.mapway.geo.shared.vector.Point meterToPixels(double mx, double my, int zoom) Converts EPSG:3857 to pyramid pixel coordinates in given zoom level"- Parameters:
mx-my-zoom-- Returns:
-
pixelToTile
public cn.mapway.geo.shared.vector.Point pixelToTile(double px, double py) "Returns a tile covering region in given pixel coordinates"- Parameters:
px-py-- Returns:
-
resolution
public double resolution(int zoom) "Resolution (meters/pixel) for given zoom level (measured at Equator)"- Parameters:
zoom-- Returns:
-
pixelsToRaster
public cn.mapway.geo.shared.vector.Point pixelsToRaster(double px, double py, int zoom) "Move the origin of pixel coordinates to top-left corner"- Parameters:
px-py-zoom-- Returns:
-
geoToTile
public cn.mapway.geo.shared.vector.Point geoToTile(double lng, double lat, double tx, double ty, int zoom) 地理坐标 转化为 tile内像素坐标 (256*256) 坐标系为 左下角为坐标原点- Parameters:
lng-lat-zoom-- Returns:
-
tileLngLatBounds
public cn.mapway.geo.shared.vector.Box tileLngLatBounds(long tx, long ty, int zoom) 墨卡托坐标下 tile的编号规则 左下角的编号为 (0,0) 向右 向上增加 WGS坐标 统一称做 gps坐标- Parameters:
tx- 墨卡托坐标下的X方向瓦片编号ty- 墨卡托坐标下的Y方向瓦片编号zoom- 图像LEVEL- Returns:
-
tileBounds
public cn.mapway.geo.shared.vector.Box tileBounds(double tx, double ty, int zoom) "Returns bounds of the given tile in EPSG:3857 coordinates"- Parameters:
tx-ty-zoom-- Returns:
-
tileNoFromWgs84
经纬度坐标 所在的tile索引 参考 https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames- Parameters:
lat-lng-zoom-- Returns:
-
tileBoundWgs84
public cn.mapway.geo.shared.vector.Box tileBoundWgs84(double tx, double ty, int zoom) tile (tx,ty)对应的经纬度范围 墨卡托 tile编码规则 左上角 为(0,0) 向右向下生长 墨卡托坐标单位 为 mi 坐标原点为 将 中央子午线和赤道的交点 (0,0)- Parameters:
tx-ty-zoom-- Returns:
-
tileBoundsWebMercator
public cn.mapway.geo.shared.vector.Box tileBoundsWebMercator(double tx, double ty, int zoom) 某一个级别下的瓦片编号 tx ty ,计算其WEB墨卡托的像素坐标 (tx ty) 左上角为 (0,0) 向右 向下 增加 WEB墨卡托 所坐标系定义 (地图中心点为坐标原点) (tx*512 , ty*512)是一个世界坐标系 第0级是一个 512*512图片 对应一个地球表面 赤道上 每个像素对应的地面距离为 RES= 2*PI*r/512 第n级赤道上每个像素对应的地面距离为 RES/2^n- Parameters:
tx-ty-zoom-- Returns:
-
zoomForPixelSize
public int zoomForPixelSize(double pixelSize) "Maximal scaledown zoom of the pyramid closest to the pixelSize."- Parameters:
pixelSize-- Returns:
-
meterToTile
public cn.mapway.geo.shared.vector.Point meterToTile(double mx, double my, long tileX, long tileY, int zoom) 墨卡托坐标 在 tile下的像素坐标- Parameters:
mx-my-tileX-tileY-zoom-- Returns:
-