Created
June 18, 2020 00:59
-
-
Save IngIeoAndSpare/9106180c6b3d67f04de19ba54e109cb4 to your computer and use it in GitHub Desktop.
Tile coordinate convert code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private (double, double) convertWsg84Coordinate(double x, double y, double z) | |
{ | |
double lat = Math.Asin(z / Math.Sqrt(x * x + y * y + z * z)) * (180 / Math.PI); | |
double lot = -Math.Atan2(y, x) * (180 / Math.PI); | |
return (lat, lot); | |
} | |
//wsg84 coordinate | |
public (string, string) calculateTileIdLatLot(double lat, double lot, int level) | |
{ | |
double xId = Math.Truncate(((lot + 180) / 36) * Math.Pow(2, level)); | |
double yId = Math.Truncate(((lat + 90) / 36) * Math.Pow(2, level)); | |
var formatCoordinate = getTileName(xId, yId); | |
return formatCoordinate; | |
} | |
private (string, string) getCoordinateFormat(double x, double y) | |
{ | |
string formatYCoordinateName = (Math.Log10(x) + 1 > 5 ? "00000000.##" : "0000.##"); | |
string formatXCoordinateName = (Math.Log10(y) + 1 > 5 ? "00000000.##" : "0000.##"); | |
return (formatXCoordinateName, formatYCoordinateName); | |
} | |
public (string, string) getTileName(double xCoordinate, double yCoordinate) | |
{ | |
var formatCoordinate = getCoordinateFormat(xCoordinate, yCoordinate); | |
return (xCoordinate.ToString(formatCoordinate.Item2), yCoordinate.ToString(formatCoordinate.Item1)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment