Created
October 24, 2018 08:26
-
-
Save kentyeh/87c4d16e77858320042959cfbb5f7d55 to your computer and use it in GitHub Desktop.
TWD97座標轉經緯度
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.osgeo.proj4j.CRSFactory; | |
import org.osgeo.proj4j.CoordinateReferenceSystem; | |
import org.osgeo.proj4j.CoordinateTransform; | |
import org.osgeo.proj4j.CoordinateTransformFactory; | |
import org.osgeo.proj4j.ProjCoordinate; | |
public class Proj4j { | |
/** | |
* https://search.maven.org/search?q=a:proj4j 找出proj4j轉案 | |
* http://www.sunriver.com.tw/taiwanmap/grid_tm2_convert.php#a03 線上轉換(參考範本) | |
* https://proj4.org/usage/projections.html 參數說明 lon_0: 中央經線 +lat_0: 中央緯線 | |
* +x_0: X 軸座標原點,向西平移 250000 units(公尺,meters) +y_0: Y 軸座標原點位在赤道 | |
* | |
*/ | |
public static void main(String[] args) { | |
CoordinateTransformFactory ctFactory = new CoordinateTransformFactory(); | |
CRSFactory csFactory = new CRSFactory(); | |
//台灣基準 | |
CoordinateReferenceSystem crsTaiwan = csFactory.createFromParameters("EPSG:3826", "+title=TWD97 +proj=tmerc +lat_0=0 +lon_0=121 +k=0.9999 +x_0=250000 +y_0=0 +ellps=GRS80 +units=meters +no_defs"); | |
//澎湖,金門與馬祖基準 | |
CoordinateReferenceSystem crsPenghu = csFactory.createFromParameters("EPSG:3825", "+title=TWD97 +proj=tmerc +lat_0=0 +lon_0=119 +k=0.9999 +x_0=250000 +y_0=0 +ellps=GRS80 +units=公尺 +no_defs"); | |
//WGS84 | |
CoordinateReferenceSystem WGS84 = csFactory.createFromParameters("WGS84", "+proj=longlat +datum=WGS84 +no_defs"); | |
//台灣基準轉換為WGS84 | |
CoordinateTransform trans = ctFactory.createTransform(crsTaiwan, WGS84); | |
ProjCoordinate p = new ProjCoordinate(306976.247, 2769609.563); //TGOS全國門牌地址定位服務找出台北101的TWD97座標 | |
ProjCoordinate p2 = new ProjCoordinate(); | |
ProjCoordinate p3 = trans.transform(p, p2); | |
System.out.printf("Taipei 101:%.7f,%.7f\n",p2.x, p3.y); | |
System.out.printf("Taipei 101:%.7f,%.7f\n",p3.x, p3.y);//其實p2的座標與p3一樣 | |
//澎湖,金門與馬祖基準轉換為WGS84 | |
trans = ctFactory.createTransform(crsPenghu, WGS84); | |
p = new ProjCoordinate(308217.440, 2607766.233);//澎湖縣馬公市文光路48巷4號,也是由TGOS全國門牌地址定位服務找出後再轉成澎湖基準 | |
p2 = new ProjCoordinate(); | |
trans.transform(p, p2); | |
System.out.printf("馬公市:%.7f,%.7f\n",p2.x, p3.y); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment