我正在創建一個Android應用程序(使用Java),它將從文件讀取SWEREF99 TM座標,並將它們轉換爲WGS84(long-lat)座標,並在相反方向。爲此,我要使用JMapProjLib,Proj4j或Proj4js(我將使用Java的ScriptEngine
訪問JavaScript庫)。如何使用JMapProjLib,Proj4j或Proj4js在不同座標系之間轉換座標?
的問題是,我無法弄清楚如何使用圖書館,由於檸小文件...
我已經試過JMapProjLib -JavaLibrary,但它不給我正確的結果和我也使用Proj4js 2.3.3試過,但我甚至不能在後面提到的工作...
的JavaScript(和一些HTML)的代碼,我目前使用的,與Proj4js 2.3.3 (目前我只在HTML文件中嘗試這個腳本,所以瀏覽器應該顯示一條彈出消息「完成!」 當轉換完成後):
<!DOCTYPE html>
<html>
<head>
<title>Proj4js Testing</title>
</head>
<body onload="convertCoordinates()">
<script type"text/javascript" src="proj4js.js"></script>
<script type="text/javascript">
// Convert coordinates
function convertCoordinates()
// Define the target projection (SWEREF99 TM)
var targetProjection = "+proj=utm +zone=33 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs";
// Convert the WGS84 coordinates Lon: 15 and Lat: 55 to SWEREF99 TM coordinates
proj4(targetProjection, [15, 55]);
// Just show an alert message telling that the code has executed properly
alert("Done!");
}
</script>
</body>
</html>
我想要(與
JMapProjLib)
Java代碼:
/**
* Convert a long-lat coordinate to a SWEREF99 TM coordinate.
*
* @param longLatCoordinate The long-lat coordinate to convert.
*
* @return The converted SWEREF99 TM coordinate.
*/
public static SWEREF99TMCoordinate longLatToSWEREF99TM(LongLatCoordinate longLatCoordinate) {
// Create a new SWEREF99 TM projection
Projection projection = ProjectionFactory.fromPROJ4Specification(new String[] {
"+proj=tmerc",
"+zone=33",
"+ellps=GRS80",
"+towgs84=0,0,0,0,0,0,0",
"+units=m",
"+no_defs"
});
// Convert the LongLatCoordinate to a Point2D.Double
Point2D.Double longLatPoint = new Point2D.Double(longLatCoordinate.getLongitude(), longLatCoordinate.getLatitude());
// Get the location as a SWEREF99 TM Point2D.Double
Point2D.Double sweref99TMPoint = projection.transform(longLatPoint, new Point2D.Double());
// COnvert the location to a SWEREF99TMCoordinate
SWEREF99TMCoordinate sweref99TMCoordinate = new SWEREF99TMCoordinate(sweref99TMPoint.x, sweref99TMPoint.y);
// Return the projected coordinate
return sweref99TMCoordinate;
}
的JMapProjLib -library其被引用到我的Java項目由git-repository中的文件夾src/com/jhlabs/map
和src/coordsys/
中的內容組成,使用Eclipse編譯爲.jar
文件,由我自己編寫。
由於的JavaScript -library Proj4js看起來更「做得好」對我來說,我寧願用它與Java ScriptEngine
結合起來,所以我現在真的需要的只是某種文檔,或者有人誰可以向我解釋這一點。
看起來不錯!我會看看它! – 2015-02-05 17:10:19