public class OsmMercator extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static int |
DEFAUL_TILE_SIZE
default tile size
|
static double |
EARTH_RADIUS
equatorial earth radius for EPSG:3857 (Mercator)
|
static double |
MAX_LAT
maximum latitude (north) for mercator display
|
static OsmMercator |
MERCATOR_256
instance with tile size of 256 for easy conversions
|
static double |
MIN_LAT
minimum latitude (south) for mercator display
|
private long |
tileSize
tile size of the displayed tiles.
|
Constructor and Description |
---|
OsmMercator()
Creates instance with default tile size of 256
|
OsmMercator(int tileSize)
Creates instance with provided tile size.
|
Modifier and Type | Method and Description |
---|---|
long |
falseEasting(int aZoomlevel) |
long |
falseNorthing(int aZoomlevel) |
double |
getDistance(double la1,
double lo1,
double la2,
double lo2)
Gets the distance using Spherical law of cosines.
|
double |
getDistance(long x1,
long y1,
long x2,
long y2,
int zoomLevel)
Transform pixelspace to coordinates and get the distance.
|
long |
getMaxPixels(int aZoomlevel)
Returns the absolut number of pixels in y or x, defined as: 2^Zoomlevel *
tileSize where tileSize is the width of a tile in pixels
|
double |
latToY(double aLat,
int aZoomlevel)
Transforms latitude to pixelspace
|
double |
lonToX(double aLongitude,
int aZoomlevel)
Transform longitude to pixelspace
|
double |
radius(int aZoomlevel) |
double |
xToLon(long aX,
int aZoomlevel)
Transforms pixel coordinate X to longitude
|
double |
yToLat(long aY,
int aZoomlevel)
Transforms pixel coordinate Y to latitude
|
public static final int DEFAUL_TILE_SIZE
public static final double MAX_LAT
public static final double MIN_LAT
public static final double EARTH_RADIUS
public static final OsmMercator MERCATOR_256
private long tileSize
public OsmMercator()
public OsmMercator(int tileSize)
tileSize
- tile size in pixelspublic double radius(int aZoomlevel)
public long getMaxPixels(int aZoomlevel)
aZoomlevel
- zoom level to request pixel datapublic long falseEasting(int aZoomlevel)
public long falseNorthing(int aZoomlevel)
public double getDistance(long x1, long y1, long x2, long y2, int zoomLevel)
x1
- the first x coordinatey1
- the first y coordinatex2
- the second x coordinatey2
- the second y coordinatezoomLevel
- the zoom levelpublic double getDistance(double la1, double lo1, double la2, double lo2)
la1
- the Latitude in degreeslo1
- the Longitude in degreesla2
- the Latitude from 2nd coordinate in degreeslo2
- the Longitude from 2nd coordinate in degreespublic double lonToX(double aLongitude, int aZoomlevel)
Mathematical optimization
x = radius(aZoomlevel) * toRadians(aLongitude) + falseEasting(aZoomLevel)
x = getMaxPixels(aZoomlevel) / (2 * PI) * (aLongitude * PI) / 180 + getMaxPixels(aZoomlevel) / 2
x = getMaxPixels(aZoomlevel) * aLongitude / 360 + 180 * getMaxPixels(aZoomlevel) / 360
x = getMaxPixels(aZoomlevel) * (aLongitude + 180) / 360
aLongitude
- [-180..180]aZoomlevel
- zoom levelpublic double latToY(double aLat, int aZoomlevel)
Mathematical optimization
log(u) := log((1.0 + sin(toRadians(aLat))) / (1.0 - sin(toRadians(aLat))
y = -1 * (radius(aZoomlevel) / 2 * log(u)))) - falseNorthing(aZoomlevel))
y = -1 * (getMaxPixel(aZoomlevel) / 2 * PI / 2 * log(u)) - -1 * getMaxPixel(aZoomLevel) / 2
y = getMaxPixel(aZoomlevel) / (-4 * PI) * log(u)) + getMaxPixel(aZoomLevel) / 2
y = getMaxPixel(aZoomlevel) * ((log(u) / (-4 * PI)) + 1/2)
aLat
- [-90...90]aZoomlevel
- zoom levelpublic double xToLon(long aX, int aZoomlevel)
Mathematical optimization
lon = toDegree((aX - falseEasting(aZoomlevel)) / radius(aZoomlevel))
lon = 180 / PI * ((aX - getMaxPixels(aZoomlevel) / 2) / getMaxPixels(aZoomlevel) / (2 * PI)
lon = 180 * ((aX - getMaxPixels(aZoomlevel) / 2) / getMaxPixels(aZoomlevel))
lon = 360 / getMaxPixels(aZoomlevel) * (aX - getMaxPixels(aZoomlevel) / 2)
lon = 360 * aX / getMaxPixels(aZoomlevel) - 180
aX
- [0..2^Zoomlevel*TILE_WIDTH[aZoomlevel
- zoom levelpublic double yToLat(long aY, int aZoomlevel)
aY
- [0..2^Zoomlevel*TILE_WIDTH[aZoomlevel
- zoom level