Mercator Projection에서 위도에서 위도에서 Y 위치를 계산합니다.
-
20-09-2019 - |
문제
나는 위도가 각도에 주어진 Mercator projection이있는지도에서 Y 위치를 계산하려고합니다. 내가 필요한 것은 다음과 같습니다.
//mapHeight might be 600 (pixels), for example
//latitudeInDegrees ranges from -90 to 90
public double CalculateY(double mapHeight, double latitudeInDegrees)
{
//what on earth do I do here to calculate the Y offset on the map?
return ???;
}
온라인에서 찾은 모든 것을 시도했지만 (Wikipedia와 StackoverFlow 포함), 그 중 어느 것도 저에게 도움이되지 않았습니다. 나는 아마 어리석은 일을하고 있지만 무엇을 알 수 없습니다. 누구든지 내 정신을 구할 수 있습니까?
해결책
public double CalculateY(double mapHeight, double latitudeInDegrees)
{
return Math.Log(Math.Tan(latitudeInDegrees / 360d * Math.PI + Math.PI / 4));
}
mapheight가있는 스케일 y를 기억하지 못합니다 (taht에 대한 위도의 최소값과 최소값을 알아야합니다)
Wikipedia의 인용 :
북쪽 또는 남쪽으로 70 °보다 높은 위도에서는 Mercator 프로젝션을 실제로 사용할 수 없습니다.
다음과 같은 코드를 작성해야합니다.
private double CalculateYRelative(double latitudeInDegrees)
{
return Math.Log(Math.Tan(latitudeInDegrees / 360d * Math.PI + Math.PI / 4));
}
...
minY = CalculateYRelative(MinLatitudeInDegrees);
maxY = CalculateYRelative(MaxLatitudeInDegrees);
...
public double CalculateY(double mapHeight, double latitudeInDegrees)
{
return mapHeight*
(CalculateYRelative(latitudeInDegrees) - minY) / (maxY - minY);
}
자세한 내용은:
제휴하지 않습니다 StackOverflow