Package org.oscim.core
Class MercatorProjection
java.lang.Object
org.oscim.core.MercatorProjection
An implementation of the spherical Mercator projection.
There are generally two methods for each operation: one taking a byte zoom level and
a parallel one taking a double scale. The scale is Math.pow(2, zoomLevel)
for a given zoom level, but the operations take intermediate values as well.
The zoom level operation is a little faster as it can make use of shift operations,
the scale operation offers greater flexibility in computing the values for
intermediate zoom levels.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final doubleThe circumference of the earth at the equator in meters.static final doubleMaximum possible latitude coordinate of the map.static final doubleMinimum possible latitude coordinate of the map.static final doubleMaximum possible longitude coordinate of the map.static final doubleMinimum possible longitude coordinate of the map. -
Method Summary
Modifier and TypeMethodDescriptionstatic GeoPointfromPixels(double pixelX, double pixelY, long mapSize) Get GeoPoint from Pixels.static GeoPointfromPixelsWithScale(double pixelX, double pixelY, double scale) Get GeoPoint from Pixels.static longgetMapSize(byte zoomLevel) static longgetMapSizeWithScale(double scale) static Pointstatic PointgetPixelAbsolute(GeoPoint geoPoint, long mapSize) Calculates the absolute pixel position for a map size and tile sizestatic PointgetPixelRelative(GeoPoint geoPoint, long mapSize, double x, double y) Calculates the absolute pixel position for a map size and tile size relative to originstatic PointgetPixelRelative(GeoPoint geoPoint, long mapSize, Point origin) Calculates the absolute pixel position for a map size and tile size relative to originstatic PointgetPixelRelativeToTile(GeoPoint geoPoint, Tile tile) Calculates the absolute pixel position for a tile and tile size relative to originstatic PointgetPixelWithScale(GeoPoint geoPoint, double scale) static doublegroundResolution(double latitude, long mapSize) Calculates the distance on the ground that is represented by a single pixel on the map.static doublestatic doublegroundResolutionWithScale(double latitude, double scale) Calculates the distance on the ground that is represented by a single pixel on the map.static doublelatitudeToPixelY(double latitude, byte zoomLevel) Converts a latitude coordinate (in degrees) to a pixel Y coordinate at a certain zoom level.static doublelatitudeToPixelY(double latitude, long mapSize) Converts a latitude coordinate (in degrees) to a pixel Y coordinate at a certain map size.static doublelatitudeToPixelYWithScale(double latitude, double scale) Converts a latitude coordinate (in degrees) to a pixel Y coordinate at a certain scale.static intlatitudeToTileY(double latitude, byte zoomLevel) Converts a latitude coordinate (in degrees) to a tile Y number at a certain zoom level.static intlatitudeToTileYWithScale(double latitude, double scale) Converts a latitude coordinate (in degrees) to a tile Y number at a certain scale.static doublelatitudeToY(double latitude) Projects a latitude coordinate (in degrees) to the range [0.0,1.0]static doublelimitLatitude(double latitude) static doublelimitLongitude(double longitude) static doublelongitudeToPixelX(double longitude, byte zoomLevel) Converts a longitude coordinate (in degrees) to a pixel X coordinate at a certain zoom level.static doublelongitudeToPixelX(double longitude, long mapSize) Converts a longitude coordinate (in degrees) to a pixel X coordinate at a certain map size.static doublelongitudeToPixelXWithScale(double longitude, double scale) Converts a longitude coordinate (in degrees) to a pixel X coordinate at a certain scale factor.static intlongitudeToTileX(double longitude, byte zoomLevel) Converts a longitude coordinate (in degrees) to the tile X number at a certain zoom level.static intlongitudeToTileXWithScale(double longitude, double scale) Converts a longitude coordinate (in degrees) to the tile X number at a certain scale factor.static doublelongitudeToX(double longitude) Projects a longitude coordinate (in degrees) to the range [0.0,1.0]static doublemetersToPixels(float meters, double latitude, long mapSize) Converts meters to pixels at latitude for zoom-level.static doublemetersToPixelsWithScale(float meters, double latitude, double scale) Converts meters to pixels at latitude for zoom-level.static doublepixelXToLongitude(double pixelX, long mapSize) Converts a pixel X coordinate at a certain map size to a longitude coordinate.static doublepixelXToLongitudeWithScale(double pixelX, double scale) Converts a pixel X coordinate at a certain scale to a longitude coordinate.static intpixelXToTileX(double pixelX, byte zoomLevel) Converts a pixel X coordinate to the tile X number.static intpixelXToTileXWithScale(double pixelX, double scale) Converts a pixel X coordinate to the tile X number.static doublepixelYToLatitude(double pixelY, long mapSize) Converts a pixel Y coordinate at a certain map size to a latitude coordinate.static doublepixelYToLatitudeWithScale(double pixelY, double scale) Converts a pixel Y coordinate at a certain scale to a latitude coordinate.static intpixelYToTileY(double pixelY, byte zoomLevel) Converts a pixel Y coordinate to the tile Y number.static intpixelYToTileYWithScale(double pixelY, double scale) Converts a pixel Y coordinate to the tile Y number.static voidproject(double latitude, double longitude, double[] out, int pos) static voidstatic Pointstatic doublescaleToZoomLevel(double scale) Converts a scale factor to a zoomLevel.static longtileToPixel(long tileNumber) static doubletileXToLongitude(long tileX, byte zoomLevel) Converts a tile X number at a certain zoom level to a longitude coordinate.static doubletileXToLongitudeWithScale(long tileX, double scale) Converts a tile X number at a certain scale to a longitude coordinate.static doubletileYToLatitude(long tileY, byte zoomLevel) Converts a tile Y number at a certain zoom level to a latitude coordinate.static doubletileYToLatitudeWithScale(long tileY, double scale) Converts a tile Y number at a certain scale to a latitude coordinate.static longtileYToTMS(long tileY, byte zoomLevel) Converts a tile Y number at a certain zoom level to TMS notation.static doubletoLatitude(double y) Converts y map position to latitude in degrees.static doubletoLongitude(double x) Converts x map position to longitude in degrees.static doublewrapLongitude(double longitude) static doublezoomLevelToScale(byte zoomLevel) Converts a zoom level to a scale factor.
-
Field Details
-
EARTH_CIRCUMFERENCE
public static final double EARTH_CIRCUMFERENCEThe circumference of the earth at the equator in meters.- See Also:
-
LATITUDE_MAX
public static final double LATITUDE_MAXMaximum possible latitude coordinate of the map.- See Also:
-
LATITUDE_MIN
public static final double LATITUDE_MINMinimum possible latitude coordinate of the map.- See Also:
-
LONGITUDE_MAX
public static final double LONGITUDE_MAXMaximum possible longitude coordinate of the map.- See Also:
-
LONGITUDE_MIN
public static final double LONGITUDE_MINMinimum possible longitude coordinate of the map.- See Also:
-
-
Method Details
-
fromPixelsWithScale
Get GeoPoint from Pixels. -
fromPixels
Get GeoPoint from Pixels. -
getMapSizeWithScale
public static long getMapSizeWithScale(double scale) - Parameters:
scale- the scale factor for which the size of the world map should be returned.- Returns:
- the horizontal and vertical size of the map in pixel at the given scale.
- Throws:
IllegalArgumentException- if the given scale factor is < 1
-
getMapSize
public static long getMapSize(byte zoomLevel) - Parameters:
zoomLevel- the zoom level for which the size of the world map should be returned.- Returns:
- the horizontal and vertical size of the map in pixel at the given zoom level.
- Throws:
IllegalArgumentException- if the given zoom level is negative.
-
getPixelWithScale
-
getPixel
-
getPixelAbsolute
Calculates the absolute pixel position for a map size and tile size- Parameters:
geoPoint- the geographic position.mapSize- precomputed size of map.- Returns:
- the absolute pixel coordinates (for world)
-
getPixelRelative
Calculates the absolute pixel position for a map size and tile size relative to origin- Parameters:
geoPoint- the geographic position.mapSize- precomputed size of map.- Returns:
- the relative pixel position to the origin values (e.g. for a tile)
-
getPixelRelative
Calculates the absolute pixel position for a map size and tile size relative to origin- Parameters:
geoPoint- the geographic position.mapSize- precomputed size of map.- Returns:
- the relative pixel position to the origin values (e.g. for a tile)
-
getPixelRelativeToTile
Calculates the absolute pixel position for a tile and tile size relative to origin- Parameters:
geoPoint- the geographic position.tile- tile- Returns:
- the relative pixel position to the origin values (e.g. for a tile)
-
groundResolutionWithScale
public static double groundResolutionWithScale(double latitude, double scale) Calculates the distance on the ground that is represented by a single pixel on the map.- Parameters:
latitude- the latitude coordinate at which the resolution should be calculated.scale- the map scale at which the resolution should be calculated.- Returns:
- the ground resolution at the given latitude and scale.
-
groundResolution
-
groundResolution
public static double groundResolution(double latitude, long mapSize) Calculates the distance on the ground that is represented by a single pixel on the map.- Parameters:
latitude- the latitude coordinate at which the resolution should be calculated.mapSize- precomputed size of map.- Returns:
- the ground resolution at the given latitude and map size.
-
latitudeToPixelYWithScale
public static double latitudeToPixelYWithScale(double latitude, double scale) Converts a latitude coordinate (in degrees) to a pixel Y coordinate at a certain scale.- Parameters:
latitude- the latitude coordinate that should be converted.scale- the scale factor at which the coordinate should be converted.- Returns:
- the pixel Y coordinate of the latitude value.
-
latitudeToPixelY
public static double latitudeToPixelY(double latitude, byte zoomLevel) Converts a latitude coordinate (in degrees) to a pixel Y coordinate at a certain zoom level.- Parameters:
latitude- the latitude coordinate that should be converted.zoomLevel- the zoom level at which the coordinate should be converted.- Returns:
- the pixel Y coordinate of the latitude value.
-
latitudeToPixelY
public static double latitudeToPixelY(double latitude, long mapSize) Converts a latitude coordinate (in degrees) to a pixel Y coordinate at a certain map size.- Parameters:
latitude- the latitude coordinate that should be converted.mapSize- precomputed size of map.- Returns:
- the pixel Y coordinate of the latitude value.
-
latitudeToTileYWithScale
public static int latitudeToTileYWithScale(double latitude, double scale) Converts a latitude coordinate (in degrees) to a tile Y number at a certain scale.- Parameters:
latitude- the latitude coordinate that should be converted.scale- the scale factor at which the coordinate should be converted.- Returns:
- the tile Y number of the latitude value.
-
latitudeToTileY
public static int latitudeToTileY(double latitude, byte zoomLevel) Converts a latitude coordinate (in degrees) to a tile Y number at a certain zoom level.- Parameters:
latitude- the latitude coordinate that should be converted.zoomLevel- the zoom level at which the coordinate should be converted.- Returns:
- the tile Y number of the latitude value.
-
latitudeToY
public static double latitudeToY(double latitude) Projects a latitude coordinate (in degrees) to the range [0.0,1.0]- Parameters:
latitude- the latitude coordinate that should be converted.- Returns:
- the position.
-
limitLatitude
public static double limitLatitude(double latitude) - Parameters:
latitude- the latitude value which should be checked.- Returns:
- the given latitude value, limited to the possible latitude range.
-
limitLongitude
public static double limitLongitude(double longitude) - Parameters:
longitude- the longitude value which should be checked.- Returns:
- the given longitude value, limited to the possible longitude range.
-
longitudeToPixelXWithScale
public static double longitudeToPixelXWithScale(double longitude, double scale) Converts a longitude coordinate (in degrees) to a pixel X coordinate at a certain scale factor.- Parameters:
longitude- the longitude coordinate that should be converted.scale- the scale factor at which the coordinate should be converted.- Returns:
- the pixel X coordinate of the longitude value.
-
longitudeToPixelX
public static double longitudeToPixelX(double longitude, byte zoomLevel) Converts a longitude coordinate (in degrees) to a pixel X coordinate at a certain zoom level.- Parameters:
longitude- the longitude coordinate that should be converted.zoomLevel- the zoom level at which the coordinate should be converted.- Returns:
- the pixel X coordinate of the longitude value.
-
longitudeToPixelX
public static double longitudeToPixelX(double longitude, long mapSize) Converts a longitude coordinate (in degrees) to a pixel X coordinate at a certain map size.- Parameters:
longitude- the longitude coordinate that should be converted.mapSize- precomputed size of map.- Returns:
- the pixel X coordinate of the longitude value.
-
longitudeToTileXWithScale
public static int longitudeToTileXWithScale(double longitude, double scale) Converts a longitude coordinate (in degrees) to the tile X number at a certain scale factor.- Parameters:
longitude- the longitude coordinate that should be converted.scale- the scale factor at which the coordinate should be converted.- Returns:
- the tile X number of the longitude value.
-
longitudeToTileX
public static int longitudeToTileX(double longitude, byte zoomLevel) Converts a longitude coordinate (in degrees) to the tile X number at a certain zoom level.- Parameters:
longitude- the longitude coordinate that should be converted.zoomLevel- the zoom level at which the coordinate should be converted.- Returns:
- the tile X number of the longitude value.
-
longitudeToX
public static double longitudeToX(double longitude) Projects a longitude coordinate (in degrees) to the range [0.0,1.0]- Parameters:
longitude- the longitude coordinate that should be converted.- Returns:
- the position.
-
metersToPixelsWithScale
public static double metersToPixelsWithScale(float meters, double latitude, double scale) Converts meters to pixels at latitude for zoom-level.- Parameters:
meters- the meters to convertlatitude- the latitude for the conversion.scale- the scale factor for the conversion.- Returns:
- pixels that represent the meters at the given zoom-level and latitude.
-
metersToPixels
public static double metersToPixels(float meters, double latitude, long mapSize) Converts meters to pixels at latitude for zoom-level.- Parameters:
meters- the meters to convertlatitude- the latitude for the conversion.mapSize- precomputed size of map.- Returns:
- pixels that represent the meters at the given zoom-level and latitude.
-
pixelXToLongitudeWithScale
public static double pixelXToLongitudeWithScale(double pixelX, double scale) Converts a pixel X coordinate at a certain scale to a longitude coordinate.- Parameters:
pixelX- the pixel X coordinate that should be converted.scale- the scale factor at which the coordinate should be converted.- Returns:
- the longitude value of the pixel X coordinate.
- Throws:
IllegalArgumentException- if the given pixelX coordinate is invalid.
-
pixelXToLongitude
public static double pixelXToLongitude(double pixelX, long mapSize) Converts a pixel X coordinate at a certain map size to a longitude coordinate.- Parameters:
pixelX- the pixel X coordinate that should be converted.mapSize- precomputed size of map.- Returns:
- the longitude value of the pixel X coordinate.
- Throws:
IllegalArgumentException- if the given pixelX coordinate is invalid.
-
pixelXToTileXWithScale
public static int pixelXToTileXWithScale(double pixelX, double scale) Converts a pixel X coordinate to the tile X number.- Parameters:
pixelX- the pixel X coordinate that should be converted.scale- the scale factor at which the coordinate should be converted.- Returns:
- the tile X number.
-
pixelXToTileX
public static int pixelXToTileX(double pixelX, byte zoomLevel) Converts a pixel X coordinate to the tile X number.- Parameters:
pixelX- the pixel X coordinate that should be converted.zoomLevel- the zoom level at which the coordinate should be converted.- Returns:
- the tile X number.
-
pixelYToLatitudeWithScale
public static double pixelYToLatitudeWithScale(double pixelY, double scale) Converts a pixel Y coordinate at a certain scale to a latitude coordinate.- Parameters:
pixelY- the pixel Y coordinate that should be converted.scale- the scale factor at which the coordinate should be converted.- Returns:
- the latitude value of the pixel Y coordinate.
- Throws:
IllegalArgumentException- if the given pixelY coordinate is invalid.
-
pixelYToLatitude
public static double pixelYToLatitude(double pixelY, long mapSize) Converts a pixel Y coordinate at a certain map size to a latitude coordinate.- Parameters:
pixelY- the pixel Y coordinate that should be converted.mapSize- precomputed size of map.- Returns:
- the latitude value of the pixel Y coordinate.
- Throws:
IllegalArgumentException- if the given pixelY coordinate is invalid.
-
pixelYToTileYWithScale
public static int pixelYToTileYWithScale(double pixelY, double scale) Converts a pixel Y coordinate to the tile Y number.- Parameters:
pixelY- the pixel Y coordinate that should be converted.scale- the scale factor at which the coordinate should be converted.- Returns:
- the tile Y number.
-
pixelYToTileY
public static int pixelYToTileY(double pixelY, byte zoomLevel) Converts a pixel Y coordinate to the tile Y number.- Parameters:
pixelY- the pixel Y coordinate that should be converted.zoomLevel- the zoom level at which the coordinate should be converted.- Returns:
- the tile Y number.
-
project
-
project
-
project
public static void project(double latitude, double longitude, double[] out, int pos) -
scaleToZoomLevel
public static double scaleToZoomLevel(double scale) Converts a scale factor to a zoomLevel. Note that this will return a double, as the scale factors cover the intermediate zoom levels as well.- Parameters:
scale- the scale factor to convert to a zoom level.- Returns:
- the zoom level.
-
tileToPixel
public static long tileToPixel(long tileNumber) - Parameters:
tileNumber- the tile number that should be converted.- Returns:
- the pixel coordinate for the given tile number.
-
tileXToLongitudeWithScale
public static double tileXToLongitudeWithScale(long tileX, double scale) Converts a tile X number at a certain scale to a longitude coordinate.- Parameters:
tileX- the tile X number that should be converted.scale- the scale factor at which the number should be converted.- Returns:
- the longitude value of the tile X number.
-
tileXToLongitude
public static double tileXToLongitude(long tileX, byte zoomLevel) Converts a tile X number at a certain zoom level to a longitude coordinate.- Parameters:
tileX- the tile X number that should be converted.zoomLevel- the zoom level at which the number should be converted.- Returns:
- the longitude value of the tile X number.
-
tileYToLatitudeWithScale
public static double tileYToLatitudeWithScale(long tileY, double scale) Converts a tile Y number at a certain scale to a latitude coordinate.- Parameters:
tileY- the tile Y number that should be converted.scale- the scale factor at which the number should be converted.- Returns:
- the latitude value of the tile Y number.
-
tileYToLatitude
public static double tileYToLatitude(long tileY, byte zoomLevel) Converts a tile Y number at a certain zoom level to a latitude coordinate.- Parameters:
tileY- the tile Y number that should be converted.zoomLevel- the zoom level at which the number should be converted.- Returns:
- the latitude value of the tile Y number.
-
tileYToTMS
public static long tileYToTMS(long tileY, byte zoomLevel) Converts a tile Y number at a certain zoom level to TMS notation.- Parameters:
tileY- the tile Y number that should be converted.zoomLevel- the zoom level at which the number should be converted.- Returns:
- the TMS value of the tile Y number.
-
toLatitude
public static double toLatitude(double y) Converts y map position to latitude in degrees.- Parameters:
y- the map positiony.- Returns:
- the latitude in degrees.
-
toLongitude
public static double toLongitude(double x) Converts x map position to longitude in degrees.- Parameters:
x- the map positionx.- Returns:
- the longitude in degrees.
-
wrapLongitude
public static double wrapLongitude(double longitude) -
zoomLevelToScale
public static double zoomLevelToScale(byte zoomLevel) Converts a zoom level to a scale factor.- Parameters:
zoomLevel- the zoom level to convert.- Returns:
- the corresponding scale factor.
-