我拍攝了Google地球的圖像,它的所有4個角的經度/緯度都是已知的。我正在使用GPS傳感器捕捉緯度/經度。我必須使用java將這些捕獲的緯度/經度轉換爲圖像座標(像素座標)。我將使用圖像座標模擬汽車在靜態地圖上移動(從Google地球拍攝的圖像)。在簡單的圓柱投影上將緯度/經度轉換爲圖像座標(像素座標)
我發現了這個公式,並試圖實現它
- 確定在1653x1012的圖像最左邊的經度(X)
- 確定東最經度在1653x1012的圖像(Y)
- 確定經度差速器(Z = Y - X)
- 確定南北緯度大部分在1653x1012的圖像(A)
- 確定南緯度大部分在1653x1012的圖像(B)
- 確定緯度的Diff(C = A - B) 給定緯度和經度,以確定他們點擊哪個像素:
J =輸入的經度 K =輸入緯度
計算X-像素
XPixel = CInt(((Y - J)/CDbl(Z)) * 1653)
計算的Y像素
YPixel = CInt(((A - K)/CDbl(C)) * 1012)
這是我使用的代碼。
import java.awt.geom.Point2D;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;
public class LatLongService {
private static LatLongService latLangService;
private BufferedReader reader = null;
private String st;
private LatLongService() {
try {
reader = new BufferedReader(new FileReader(new File(
"resources/GPS_lat_long_2.txt")));
} catch (Exception e) {
e.printStackTrace();
}
}
public static LatLongService getInstance() {
if (latLangService == null)
latLangService = new LatLongService();
return latLangService;
}
public List<Point2D> readLatLongList() {
List<Point2D> pointList = new ArrayList<Point2D>();
StringBuffer xStr;
StringBuffer yStr = new StringBuffer();
try {
while ((st = reader.readLine()) != null) {
xStr = new StringBuffer(st.substring(0, st.indexOf(',')));
yStr = new StringBuffer(st.substring(st.indexOf(',') + 2,
st.length()));
Point2D pt = new Point2D.Double(
new Double(xStr.toString()).doubleValue(), new Double(
yStr.toString()).doubleValue());
pointList.add(pt);
}
} catch (Exception e) {
e.printStackTrace();
try {
reader.close();
} catch (Exception e2) {
e.printStackTrace();
}
}
return pointList;
}
public List<Point2D> convertLatLongToCoord(List<Point2D> coordinate) {
List<Point2D> latLong = new ArrayList<Point2D>();
double westMostLong = -79.974642;
double eastMostLong = -79.971244;
double longDiff = eastMostLong - westMostLong; // (rightmost_longitude -
// leftmost_longitude)
double northMostLat = 39.647556;
double southMostLat = 39.644675;
double latDiff = northMostLat - southMostLat; // (topmost_latitude -
// bottommost_latitude)
for (Point2D coord : coordinate) {
double j = coord.getY();
double k = coord.getX();
double XPixel = (((eastMostLong - j)/longDiff) * 1653);
double YPixel = (((northMostLat - k)/latDiff) * 1012);
Point2D actualCoord = new Point2D.Double(XPixel, YPixel);
latLong.add(actualCoord);
}
return latLong;
}
}
一些GPS的緯度/經度我從GPS傳感器得到
輸入緯度輸入的經度 (39.64581,-79.97168) (39.64651,-79.97275) (39.646915,-79.97342) ( 39.646538,-79.97279)
[IMG] http://i59.tinypic.com/nbqkk3.png[/IMG]
圖中的紅色線表示的路徑時,隨後取GPS座標通過傳感器。
但是,當我使用此公式將Lat/Long座標轉換爲像素座標時。像素座標轉換之後並不一致,你可以看到下面的輸出:
圖像X圖像Y (212.0977045,613.3120444) (732.6127134,367.4251996) (1058.542672,225.1620965) (752.0712184,357.5897258)
X,Y(像素)座標的變化太大。因此,當我嘗試根據像素座標移動車輛時,車輛不會沿着紅線或至少靠近該線。
車輛移動到紅線以上或線下,但不在線上。
對於基於像素的車輛的運動平穩協調,最好我期望從轉換緯度/經度對圖像座標是這樣的:
所需的圖像X必需圖像Y (1290,409) (1289,409) (1288,409) (1287,409)
但我得到這個
圖像X圖像Y (212.0977045,613.3120444) (732.6127134,367.4251996) (1058.542672,225.1620965) (752.0712184,357.5897258)
我希望我能夠傳達我的問題。
你有你的java源代碼和一些關於算法的例子嗎? –
「它跳」是什麼意思?你需要使用動畫框架嗎?或者你認爲座標是完全錯誤的?並且您確定輸入座標軟件車輛不會跳躍(這是當座標通過GPS測量並且車輛或人員靜止時的情況) – AlexWien
我編輯了我的問題,希望有所幫助。 – Nemesis