java转换投影坐标_GeoTools坐标转换(投影转换和仿射变换)
GeoTools是在java下的gis開源軟件,以下介紹坐標(biāo)轉(zhuǎn)換的兩種方法:投影轉(zhuǎn)換和仿射變換
投影轉(zhuǎn)換
這里以xian80經(jīng)緯度坐標(biāo)轉(zhuǎn)xian80,3度分帶 111中央經(jīng)線平面坐標(biāo)為例
轉(zhuǎn)換函數(shù)如下:
1 Point pointXian80 = projectTransform(lon, lat, "EPSG:4610", "EPSG:2382");
1 /**
2 * 投影轉(zhuǎn)換, lon=經(jīng)度,lat=緯度,ESPG格式(例):EPSG:46103 */
4 public static Point projectTransform(double lon, doublelat,5 String epsgSource, String epsgTarget) throwsFactoryException,6 MismatchedDimensionException, TransformException {7 //原始坐標(biāo)點(diǎn)8 //PS:通常邏輯上理解經(jīng)度應(yīng)該是橫坐標(biāo)x,緯度是y,可是這里經(jīng)度要填到y(tǒng),緯度x,否則會報(bào)錯(cuò)
9 Point sourcePoint =JtsHelper.createPoint(lat, lon);10
11 //定義轉(zhuǎn)換前和轉(zhuǎn)換后的投影,可以用ESPG或者wkt12 //"PROJCS[\"Xian_1980_3_Degree_GK_CM_111E\",GEOGCS[\"GCS_Xian_1980\",DATUM[\"D_Xian_1980\",SPHEROID[\"Xian_1980\",6378140.0,298.257]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Gauss_Kruger\"],PARAMETER[\"False_Easting\",500000.0],PARAMETER[\"False_Northing\",0.0],PARAMETER[\"Central_Meridian\",111.0],PARAMETER[\"Scale_Factor\",1.0],PARAMETER[\"Latitude_Of_Origin\",0.0],UNIT[\"Meter\",1.0]]";13 //CoordinateReferenceSystem mercatroCRS = CRS.parseWKT(strWKTMercator);
14 CoordinateReferenceSystem crsSource =CRS.decode(epsgSource);15 CoordinateReferenceSystem crsTarget =CRS.decode(epsgTarget);16 //投影轉(zhuǎn)換
17 MathTransform transform =CRS.findMathTransform(crsSource, crsTarget);18 Point pointTarget =(Point) JTS.transform(sourcePoint, transform);19
20 returnpointTarget;21 }
關(guān)于定義坐標(biāo)系的說明,GeoTools中定義坐標(biāo)系有兩種方法,一是坐標(biāo)系的wkt,二是ESPG
坐標(biāo)系的wkt可以從arcgis的prj文件中過去,用記事本打開prj文件,里面的內(nèi)容就是該坐標(biāo)系的wkt格式內(nèi)容,例如:PROJCS[\"Xian_1980_3_Degree_GK_CM_111E\",GEOGCS[\"GCS_Xian_1980\",DATUM[\"D_Xian_1980\",SPHEROID[\"Xian_1980\",6378140.0,298.257]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Gauss_Kruger\"],PARAMETER[\"False_Easting\",500000.0],PARAMETER[\"False_Northing\",0.0],PARAMETER[\"Central_Meridian\",111.0],PARAMETER[\"Scale_Factor\",1.0],PARAMETER[\"Latitude_Of_Origin\",0.0],UNIT[\"Meter\",1.0]]
獲取到wkt后,可以通過 CoordinateReferenceSystem mercatroCRS = CRS.parseWKT(strWKTMercator); 獲取到坐標(biāo)系對象
另一種方法是ESPG,意思是每一個(gè)坐標(biāo)系都有一個(gè)ESPG標(biāo)準(zhǔn)的號碼,查詢坐標(biāo)系的ESPG可通過以下網(wǎng)站 外鏈網(wǎng)址已屏蔽
PS:當(dāng)轉(zhuǎn)換的兩種坐標(biāo)系的datum不同,會報(bào)錯(cuò)Bursa-Wolf parameters,暫時(shí)未解決
仿射變換
代碼如下:
首先是輸入三組參考點(diǎn),前三個(gè)是轉(zhuǎn)換前,后三個(gè)是轉(zhuǎn)換后
最后結(jié)果是pointReuslt
1 //參考點(diǎn)坐標(biāo)
2 Coordinate s1 = new Coordinate(429275.549, 2801455.153);3 Coordinate s2 = new Coordinate(428110.626, 2792148.620);4 Coordinate s3 = new Coordinate(428966.479, 2800016.622);5
6 Coordinate t1 = new Coordinate(4628.339, 801349.338);7 Coordinate t2 = new Coordinate(3515.906, 792036.308);8 Coordinate t3 = new Coordinate(4327.381, 799909.069);9 //建立仿射變換對象
10 AffineTransformationBuilder afb = newAffineTransformationBuilder(s1,11 s2, s3, t1, t2, t3);12 AffineTransformation atf =afb.getTransformation();13
14 Point pointReuslt =JtsHelper.createPoint(x,y);15
16 //坐標(biāo)轉(zhuǎn)換
17 pointReuslt.apply(atf);
總結(jié)
以上是生活随笔為你收集整理的java转换投影坐标_GeoTools坐标转换(投影转换和仿射变换)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java中资源获取
- 下一篇: Basler相机SDK相关问题收集与知识