将lat / long转换为像素X& Y坐标 [英] Convert lat/long to pixel X&Y co-ordinates
问题描述
这类问题似乎已被多次询问,但没有一个解决方案让我接近我需要的答案。
This type of question seems to have been asked numerous times but none of the solutions posted get me anywhere near the answer I need.
我有这张Northland地图,新西兰和我想将Lat / Long值映射到此图像上的x / y(像素)值(http://i.stack.imgur.com/3ok4O.gif - 这是400px square)
I have this map of Northland, New Zealand and I'd like to map Lat/Long values to x/y (pixel) values on this image (http://i.stack.imgur.com/3ok4O.gif - which is 400px square)
现在我不知道这个图像的精确纬度/长度边界,但我确实有一些示例数据对于知道他们正在做什么的人有用。
Right now I do not know the precise lat/long boundaries of this image, but I do have some example data which should be useful to someone who knows what they are doing.
LAT LONG X Y
-35.3989854471 173.504676819 192.92777494 196.760481649
-35.2647882735 174.121499062 271.426291418 176.82865668
-35.3131641432 173.89125824 242.099305271 183.945780963
我现在收到的数据只有Lat / long,所以我需要能够在应用程序中生成x和y值。
The data I'm receiving now is only Lat/long, so I need to be able to produce x and y values within the application.
任何人都可以帮助m e写下创建这些x / y值所需的方法/逻辑。
Can anybody help me write the required method/logic for creating these x/y values.
谢谢!
推荐答案
在Javascript ....
in Javascript....
var lat=-35.3989854471;
var long=173.504676819;
var imageNorthLat=???;
var imageSouthLat=???;
var imageWestLong=???;
var imageEastLong=???;
var imageLongPixels=400;
var imageLatPixels=400;
var pixelsPerLat=imageLatPixels/(imageNorthLat-imageSouthLat);
var pixelsPerLong=imageLongPixels/(imageEastLong-imageWestLong);
var xPixelPosition=(long-imageWestLong)*pixelsPerLong;
var yPixelPosition=Math.abs(lat-imageNorthLat)*pixelsPerLat;
我没有尝试运行它,所以可能需要一些调试,而x和y像素位置必须添加左上角或地图的x和y位置。但你可以看到这个想法。当然,我可能还不明白你真正要问的是什么。
I didn't try to run this, so there's probably a bit of debugging necessary, and the x and y pixel positions would have to have added to them the x and y positions of the top left or your map. But you can see the idea. And, of course, I may not have understood what you're really asking.
这篇关于将lat / long转换为像素X& Y坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!