|
@@ -74,37 +74,47 @@ public class ConvertXY {
|
|
|
public static MyPoint ConvertXYToXian80(String x, String y,String moveXY) {
|
|
|
MyPoint pPoint = new MyPoint();
|
|
|
double dblLon = Double.parseDouble(x), dblLat = Double.parseDouble(y);
|
|
|
- StringBuilder dblX80 = new StringBuilder();
|
|
|
- StringBuilder dblY80 = new StringBuilder();
|
|
|
- ICoordinate pCoordinate = CoordinateFactory.CreateCoordinate(Spheroid.Xian80);
|
|
|
- pCoordinate.GaussPrjCalculate(dblLon, dblLat, dblX80, dblY80);
|
|
|
- double X80 = Double.parseDouble(String.format("%.4f", Double.parseDouble(dblX80.toString())));
|
|
|
- double Y80 = Double.parseDouble(String.format("%.4f", Double.parseDouble(dblY80.toString())));
|
|
|
- X80 += -196600;
|
|
|
- Y80 += 270;
|
|
|
- int moveX=0,moveY=0;
|
|
|
- if(!StringUtils.isEmpty(moveXY)){
|
|
|
- moveX=Integer.parseInt(moveXY.split(",")[0]);
|
|
|
- moveY=Integer.parseInt(moveXY.split(",")[1]);
|
|
|
+ if(dblLon <= 0 && dblLat <= 0){
|
|
|
+ pPoint.X = 0;
|
|
|
+ pPoint.Y = 0;
|
|
|
+ }else{
|
|
|
+ StringBuilder dblX80 = new StringBuilder();
|
|
|
+ StringBuilder dblY80 = new StringBuilder();
|
|
|
+ ICoordinate pCoordinate = CoordinateFactory.CreateCoordinate(Spheroid.Xian80);
|
|
|
+ pCoordinate.GaussPrjCalculate(dblLon, dblLat, dblX80, dblY80);
|
|
|
+ double X80 = Double.parseDouble(String.format("%.4f", Double.parseDouble(dblX80.toString())));
|
|
|
+ double Y80 = Double.parseDouble(String.format("%.4f", Double.parseDouble(dblY80.toString())));
|
|
|
+ X80 += -196600;
|
|
|
+ Y80 += 270;
|
|
|
+ int moveX=0,moveY=0;
|
|
|
+ if(!StringUtils.isEmpty(moveXY)){
|
|
|
+ moveX=Integer.parseInt(moveXY.split(",")[0]);
|
|
|
+ moveY=Integer.parseInt(moveXY.split(",")[1]);
|
|
|
+ }
|
|
|
+ pPoint.X = X80+moveX;
|
|
|
+ pPoint.Y = Y80+moveY;
|
|
|
}
|
|
|
- pPoint.X = X80+moveX;
|
|
|
- pPoint.Y = Y80+moveY;
|
|
|
return pPoint;
|
|
|
}
|
|
|
|
|
|
/* 经纬度转墨卡托投影坐标 */
|
|
|
public static MyPoint ConvertXYToMercato(String x, String y,String moveXY) {
|
|
|
MyPoint mercator = new MyPoint();
|
|
|
- double dblLon = Double.parseDouble(x) * 20037508.34 / 180;
|
|
|
- double dblLat = Math.log(Math.tan((90 + Double.parseDouble(y)) * Math.PI / 360)) / (Math.PI / 180);
|
|
|
- dblLat = dblLat * 20037508.34 / 180;
|
|
|
- int moveX=0,moveY=0;
|
|
|
- if(!StringUtils.isEmpty(moveXY)){
|
|
|
- moveX=Integer.parseInt(moveXY.split(",")[0]);
|
|
|
- moveY=Integer.parseInt(moveXY.split(",")[1]);
|
|
|
+ if(Double.parseDouble(x) <= 0 && Double.parseDouble(y) <= 0){
|
|
|
+ mercator.X = 0;
|
|
|
+ mercator.Y = 0;
|
|
|
+ }else{
|
|
|
+ double dblLon = Double.parseDouble(x) * 20037508.34 / 180;
|
|
|
+ double dblLat = Math.log(Math.tan((90 + Double.parseDouble(y)) * Math.PI / 360)) / (Math.PI / 180);
|
|
|
+ dblLat = dblLat * 20037508.34 / 180;
|
|
|
+ int moveX=0,moveY=0;
|
|
|
+ if(!StringUtils.isEmpty(moveXY)){
|
|
|
+ moveX=Integer.parseInt(moveXY.split(",")[0]);
|
|
|
+ moveY=Integer.parseInt(moveXY.split(",")[1]);
|
|
|
+ }
|
|
|
+ mercator.X = dblLon+moveX;
|
|
|
+ mercator.Y = dblLat+moveY;
|
|
|
}
|
|
|
- mercator.X = dblLon+moveX;
|
|
|
- mercator.Y = dblLat+moveY;
|
|
|
return mercator;
|
|
|
}
|
|
|
|
|
@@ -118,23 +128,28 @@ public class ConvertXY {
|
|
|
*/
|
|
|
public static MyPoint ConvertXian80ToXY(String x, String y,String moveXY) {
|
|
|
MyPoint pPoint = new MyPoint();
|
|
|
- double dx = Double.parseDouble(x)+196600, dy = Double.parseDouble(y)-270;
|
|
|
- int moveX=0,moveY=0;
|
|
|
- if(!StringUtils.isEmpty(moveXY)){
|
|
|
- moveX=Integer.parseInt(moveXY.split(",")[0]);
|
|
|
- moveY=Integer.parseInt(moveXY.split(",")[1]);
|
|
|
+ if(Double.parseDouble(x) <= 0 && Double.parseDouble(y) <= 0){
|
|
|
+ pPoint.X =0;
|
|
|
+ pPoint.Y =0;
|
|
|
+ }else{
|
|
|
+ double dx = Double.parseDouble(x)+196600, dy = Double.parseDouble(y)-270;
|
|
|
+ int moveX=0,moveY=0;
|
|
|
+ if(!StringUtils.isEmpty(moveXY)){
|
|
|
+ moveX=Integer.parseInt(moveXY.split(",")[0]);
|
|
|
+ moveY=Integer.parseInt(moveXY.split(",")[1]);
|
|
|
+ }
|
|
|
+ dx -= moveX;
|
|
|
+ dy -= moveY;
|
|
|
+ StringBuilder dblLon = new StringBuilder();
|
|
|
+ StringBuilder dblLat = new StringBuilder();
|
|
|
+ ICoordinate pCoordinate = CoordinateFactory.CreateCoordinate(Spheroid.WGS84);
|
|
|
+ pCoordinate.GaussPrjInvCalculate(dx, dy, dblLon, dblLat);
|
|
|
+ double X84 = Double.parseDouble(String.format("%.6f", Double.parseDouble(dblLon.toString())));
|
|
|
+ double Y84 = Double.parseDouble(String.format("%.6f", Double.parseDouble(dblLat.toString())));
|
|
|
+
|
|
|
+ pPoint.X =X84;
|
|
|
+ pPoint.Y =Y84;
|
|
|
}
|
|
|
- dx -= moveX;
|
|
|
- dy -= moveY;
|
|
|
- StringBuilder dblLon = new StringBuilder();
|
|
|
- StringBuilder dblLat = new StringBuilder();
|
|
|
- ICoordinate pCoordinate = CoordinateFactory.CreateCoordinate(Spheroid.WGS84);
|
|
|
- pCoordinate.GaussPrjInvCalculate(dx, dy, dblLon, dblLat);
|
|
|
- double X84 = Double.parseDouble(String.format("%.6f", Double.parseDouble(dblLon.toString())));
|
|
|
- double Y84 = Double.parseDouble(String.format("%.6f", Double.parseDouble(dblLat.toString())));
|
|
|
-
|
|
|
- pPoint.X =X84;
|
|
|
- pPoint.Y =Y84;
|
|
|
return pPoint;
|
|
|
}
|
|
|
|
|
@@ -143,16 +158,21 @@ public class ConvertXY {
|
|
|
MyPoint lngLat = new MyPoint();
|
|
|
double lng = Double.parseDouble(x);
|
|
|
double lat = Double.parseDouble(y);
|
|
|
- int moveX=0,moveY=0;
|
|
|
- if(!StringUtils.isEmpty(moveXY)){
|
|
|
- moveX=Integer.parseInt(moveXY.split(",")[0]);
|
|
|
- moveY=Integer.parseInt(moveXY.split(",")[1]);
|
|
|
+ if(lng<=0 && lat<=0){
|
|
|
+ lngLat.X=0;
|
|
|
+ lngLat.Y=0;
|
|
|
+ }else{
|
|
|
+ int moveX=0,moveY=0;
|
|
|
+ if(!StringUtils.isEmpty(moveXY)){
|
|
|
+ moveX=Integer.parseInt(moveXY.split(",")[0]);
|
|
|
+ moveY=Integer.parseInt(moveXY.split(",")[1]);
|
|
|
+ }
|
|
|
+ lng -= moveX;
|
|
|
+ lat -= moveY;
|
|
|
+ lngLat.X = lng / 20037508.34 * 180;
|
|
|
+ double mmy = lat / 20037508.34 * 180;
|
|
|
+ lngLat.Y = 180 / Math.PI * (2 * Math.atan(Math.exp(mmy * Math.PI / 180)) - Math.PI / 2);
|
|
|
}
|
|
|
- lng -= moveX;
|
|
|
- lat -= moveY;
|
|
|
- lngLat.X = lng / 20037508.34 * 180;
|
|
|
- double mmy = lat / 20037508.34 * 180;
|
|
|
- lngLat.Y = 180 / Math.PI * (2 * Math.atan(Math.exp(mmy * Math.PI / 180)) - Math.PI / 2);
|
|
|
return lngLat;
|
|
|
}
|
|
|
|