|
@@ -10,7 +10,7 @@ public class GisCoordinateTransform {
|
|
|
//WGS84坐标系参数
|
|
|
private static double WGS84_a=6378137.0;
|
|
|
private static double WGS84_f=1/298.2572236;
|
|
|
-
|
|
|
+ private static double earthRadius= 6378137;//地球半径
|
|
|
/**
|
|
|
* 求三度分带的中央经线
|
|
|
* @param longitude
|
|
@@ -19,23 +19,95 @@ public class GisCoordinateTransform {
|
|
|
public static double getZone3CenterLon(double longitude){
|
|
|
return Math.round(longitude/3)*3;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 2000坐标系 经纬度转平面坐标算法 也就是经纬度转米
|
|
|
+ * @param longitude 经度
|
|
|
+ * @param latitude 纬度
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static double[] convertWGS_84BLToGauss(double longitude, double latitude)
|
|
|
+ {
|
|
|
+ return convertGaussToBL(longitude, latitude, WGS84_a,WGS84_f);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 2000坐标系 平面转经纬度坐标算法 也就是米转经纬度
|
|
|
+ * @param x x坐标,对应经度
|
|
|
+ * @param y y坐标,对应纬度
|
|
|
+ * @param centerlon 所处带的中央经线
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static double[] convertWGS_84GaussToBL(double x, double y,double centerlon)
|
|
|
+ {
|
|
|
+ return convertGaussToBL(x, y, centerlon, WGS84_a,WGS84_f);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 2000坐标系 经纬度转平面坐标算法 也就是经纬度转米
|
|
|
* @param longitude 经度
|
|
|
* @param latitude 纬度
|
|
|
* @return
|
|
|
*/
|
|
|
- public static double[] Convert2000BLToGauss(double longitude, double latitude)
|
|
|
+ public static double[] convert2000BLToGauss(double longitude, double latitude)
|
|
|
+ {
|
|
|
+ return convertGaussToBL(longitude, latitude, CGCS2000_a,CGCS2000_f);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 2000坐标系 平面转经纬度坐标算法 也就是米转经纬度
|
|
|
+ * @param x x坐标,对应经度
|
|
|
+ * @param y y坐标,对应纬度
|
|
|
+ * @param centerlon 所处带的中央经线
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static double[] convert2000GaussToBL(double x, double y,double centerlon)
|
|
|
{
|
|
|
+ return convertGaussToBL(x, y, centerlon, CGCS2000_a,CGCS2000_f);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 4326转33857
|
|
|
+ * @param longitude
|
|
|
+ * @param latitude
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static double[] WGS84_4326To3857(double longitude, double latitude) {
|
|
|
+ double a=longitude,b=latitude;
|
|
|
+ double[] output = new double[2];
|
|
|
+ if(89.99999 > b&&-89.99999 < b){
|
|
|
+ b *= .017453292519943;
|
|
|
+ }
|
|
|
+ output[0] = 0.017453292519943 * a * earthRadius;
|
|
|
+ output[1] = earthRadius/2 * Math.log((1 + Math.sin(b)) / (1 - Math.sin(b)));
|
|
|
+ return output;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 3857平面坐标转4326地理坐标,单位转换是米转经纬度
|
|
|
+ * @param x
|
|
|
+ * @param y
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static double[] WGS84_3857To4326(double x, double y) {
|
|
|
+ double a=x,b=y;
|
|
|
+ double[] output = new double[2];
|
|
|
+ a = a / earthRadius * 57.29577951308232;
|
|
|
+ output[0] = a - 360 * Math.floor((a + 180) / 360);
|
|
|
+ output[1] = 57.29577951308232 * (Math.PI / 2 - 2 * Math.atan(Math.exp(-1 * b / earthRadius)));
|
|
|
+ return output;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static double[] convertGaussToBL(double longitude, double latitude,double a,double f){
|
|
|
double[] output = new double[2];
|
|
|
double longitude1,latitude1,longitude0, X0,Y0, xval,yval;
|
|
|
//NN曲率半径,测量学里面用N表示
|
|
|
//M为子午线弧长,测量学里用大X表示
|
|
|
//fai为底点纬度,由子午弧长反算公式得到,测量学里用Bf表示
|
|
|
//R为底点所对的曲率半径,测量学里用Nf表示
|
|
|
- double a,f, e2,ee, NN, T,C,A, M, iPI;
|
|
|
+ double e2,ee, NN, T,C,A, M, iPI;
|
|
|
iPI = 0.0174532925199433; //3.1415926535898/180.0;
|
|
|
- a= CGCS2000_a; f=CGCS2000_f; //CGCS2000坐标系参数
|
|
|
+ // a= CGCS2000_a; f=CGCS2000_f; //CGCS2000坐标系参数
|
|
|
longitude0=Math.round(longitude/3)*3;//中央子午线计算
|
|
|
longitude0 = longitude0 * iPI ;//中央子午线转换为弧度
|
|
|
longitude1 = longitude * iPI ; //经度转换为弧度
|
|
@@ -62,25 +134,17 @@ public class GisCoordinateTransform {
|
|
|
return output;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 2000坐标系 平面转经纬度坐标算法 也就是米转经纬度
|
|
|
- * @param x x坐标,对应经度
|
|
|
- * @param y y坐标,对应纬度
|
|
|
- * @param centerlon 所处带的中央经线
|
|
|
- * @return
|
|
|
- */
|
|
|
- public static double[] Convert2000GaussToBL(double x, double y,double centerlon)
|
|
|
- {
|
|
|
+ private static double[] convertGaussToBL(double x, double y,double centerlon,double a,double f){
|
|
|
double[] output = new double[2];
|
|
|
int ProjNo; int ZoneWide; ////带宽
|
|
|
double longitude1,latitude1, longitude0,latitude0, X0,Y0, xval,yval;
|
|
|
- double e1,e2,f,a, ee, NN, T,C, M, D,R,u,fai, iPI;
|
|
|
+ double e1,e2, ee, NN, T,C, M, D,R,u,fai, iPI;
|
|
|
iPI = 0.0174532925199433; ////3.1415926535898/180.0;
|
|
|
- a=CGCS2000_a; f=CGCS2000_f; //CGCS2000坐标系参数
|
|
|
+ // a=CGCS2000_a; f=CGCS2000_f; //CGCS2000坐标系参数
|
|
|
ZoneWide = 3; ////3度带宽
|
|
|
ProjNo = (int)(x/1000000L) ; //查找带号
|
|
|
longitude0 = (ProjNo-1) * ZoneWide + ZoneWide / 2;
|
|
|
- // System.out.println(longitude0);
|
|
|
+ // System.out.println(longitude0);
|
|
|
longitude0=centerlon;
|
|
|
longitude0 = longitude0 * iPI ; //中央经线
|
|
|
X0 = ProjNo*1000000L+500000L;
|