从X和Y坐标获取纬度和经度 [英] Get latitude and longitude from X and Y coordinates
问题描述
似乎有很多关于从经度和纬度转换为X和Y坐标的知识,但不是相反的。
It seems that there is a wealth of knowledge on converting from Longitude and Latitude to X and Y coordinates, but not the reverse.
这是我的一个函数,基于Kavrayskiy的数学
Here is a function of mine based on Kavrayskiy's math
float xp = kavraX(radians(pv.x), radians(pv.y))*FACTOR;
float yp = kavraY(radians(pv.x), radians(pv.y))*FACTOR;
// mapping -- this gives you screen X and Y coords from LAT and LONG
float kavraX (float latitude, float longitude) // Kavra for Kavrayskiy
// formula from http://en.wikipedia.org/wiki/Kavrayskiy_VII_projection
{
return ((3 * longitude) / TWO_PI)*sqrt(pow(PI, 2)/3 - pow(latitude, 2));
}
float kavraY (float latitude, float longitude)
{
return latitude*-1;
}
pv.x在这种情况下可能只是34(对于LA)ad pv在这种情况下,.y将是-118。不过,我很难绕过这个方程式。任何想法?
pv.x in this case could simply be 34 (for LA) ad pv.y would be -118 in that case. I'm having a hard time turning the equation around, though. Any ideas?
推荐答案
基于math @ Wikipedia,我设法扭转了等式
Ok based on the math @ Wikipedia, I managed to reverse the equation
// find latitude from Y coord
// height / 2 to make middle of map ZERO, *-1 to flip it, so south of equator is negative.
// divide by FACTOR to make it fit within bounds of larger map
float reMapY = ((mouseY - (height/2))*-1)/FACTOR;
println(degrees(reMapY));
// I have no idea what I'm doing
float temp = sqrt((pow(PI,2)/3 - pow(reMapY,2)));
float reMapX = (mouseX - (width/2))/FACTOR;
float temp2 = ((reMapX / temp) * TWO_PI) / 3;
println(degrees(temp2));
请记住,因为地图的大小,因此FACTOR是我设计中固有的东西。我认为它应该是width = 5.47 * FACTOR。
Just remember that FACTOR is something inherent in my design, because of the size of my map. I believe it should be width = 5.47 * FACTOR.
这篇关于从X和Y坐标获取纬度和经度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!