|
@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.fdkankan.indoor.base.convert.GisCoordinateTransform;
|
|
|
import com.fdkankan.indoor.base.exception.BaseRuntimeException;
|
|
|
+import com.fdkankan.indoor.core.entity.ControlPointCalculateEntity;
|
|
|
import com.fdkankan.indoor.core.entity.ControlPointEntity;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.junit.Test;
|
|
@@ -22,6 +23,90 @@ public class GisCoordinateUtil {
|
|
|
private final static String coordCode4326 = "EPSG:4326";
|
|
|
private final static String coordCode3857 = "EPSG:3857";
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ private static double dx1;//x方向增量
|
|
|
+ private static double dy1;//y方向增量
|
|
|
+ private static double rotation1;//旋转角度
|
|
|
+ private static double scale1;//缩放比例
|
|
|
+
|
|
|
+ private static double dx2;//x方向增量
|
|
|
+ private static double dy2;//y方向增量
|
|
|
+ private static double rotation2;//旋转角度
|
|
|
+ private static double scale2;//缩放比例
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 本地坐标转经纬度
|
|
|
+ * 这里可以获取平面坐标, 结果是很大的
|
|
|
+ * @param loctionX
|
|
|
+ * @param loctionY
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+// public static double[] transformLocationToBL(double loctionX,double loctionY){
|
|
|
+// Point point = new Point(loctionX,loctionY);
|
|
|
+// log.warn("本地转经纬度 平面 start ====");
|
|
|
+// log.info("参数 rotation:{}", rotation2);
|
|
|
+// log.info("参数 scale:{}", scale2);
|
|
|
+// log.info("参数 tx:{}", dx2);
|
|
|
+// log.info("参数 ty:{}", dy2);
|
|
|
+// Point resultPoint = AffineTransform.transformBoePoint(new Point(point.getX(), point.getY()), rotation2, scale2, dx2, dy2);
|
|
|
+// log.info("本地坐标转平面坐标输出结果:{}, {}", resultPoint.getX(),resultPoint.getY());
|
|
|
+// log.warn("本地转经纬度 平面 end ====");
|
|
|
+// return GisCoordinateTransform.convertByProj4(resultPoint.getX(),resultPoint.getY(),"EPSG:4547","EPSG:4490");
|
|
|
+// }
|
|
|
+
|
|
|
+ public static double[] transformLocationToBL(double loctionX,double loctionY, ControlPointCalculateEntity dto){
|
|
|
+ Point point = new Point(loctionX,loctionY);
|
|
|
+ log.warn("本地转经纬度 平面 start ====");
|
|
|
+ log.info("参数 rotation:{}", dto.getRotation2());
|
|
|
+ log.info("参数 scale:{}", dto.getScale2());
|
|
|
+ log.info("参数 tx:{}", dto.getDx2());
|
|
|
+ log.info("参数 ty:{}", dto.getDy2());
|
|
|
+ Point resultPoint = AffineTransform.transformBoePoint(new Point(point.getX(), point.getY()), dto.getRotation2(), dto.getScale2(), dto.getDx2(), dto.getDy2());
|
|
|
+ log.info("本地坐标转平面坐标输出结果:{}, {}", resultPoint.getX(),resultPoint.getY());
|
|
|
+ log.warn("本地转经纬度 平面 end ====");
|
|
|
+ return GisCoordinateTransform.convertByProj4(resultPoint.getX(),resultPoint.getY(),"EPSG:4547","EPSG:4490");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 经纬度转本地坐标
|
|
|
+ * @param lon 经度 十进制度
|
|
|
+ * @param lat 纬度 十进制度
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+// public static double[] transformBLToLocation(double lon,double lat){
|
|
|
+// double[] gauss= GisCoordinateTransform.convertByProj4(lon, lat,"EPSG:4490","EPSG:4547");
|
|
|
+// log.info("经纬度转本地坐标,大地坐标:{}, {}", gauss[0],gauss[1]);
|
|
|
+// Point point = new Point(gauss[0],gauss[1]);
|
|
|
+// Point resultPoint = AffineTransform.transformBoePoint(new Point(point.getX(), point.getY()), rotation1, scale1, dx1, dy1);
|
|
|
+//
|
|
|
+// double[] location=new double[2];
|
|
|
+// location[0]=resultPoint.getX();
|
|
|
+// location[1]=resultPoint.getY();
|
|
|
+// return location;
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+ public static double[] transformBLToLocation(double lon,double lat, ControlPointCalculateEntity dto){
|
|
|
+ double[] gauss= GisCoordinateTransform.convertByProj4(lon, lat,"EPSG:4490","EPSG:4547");
|
|
|
+ log.info("经纬度转本地坐标,大地坐标:{}, {}", gauss[0],gauss[1]);
|
|
|
+ Point point = new Point(gauss[0],gauss[1]);
|
|
|
+ Point resultPoint = AffineTransform.transformBoePoint(new Point(point.getX(), point.getY()), dto.getRotation1(), dto.getScale1(), dto.getDx1(), dto.getDy1());
|
|
|
+
|
|
|
+ double[] location=new double[2];
|
|
|
+ location[0]=resultPoint.getX();
|
|
|
+ location[1]=resultPoint.getY();
|
|
|
+ return location;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+
|
|
|
/**
|
|
|
* 解析控制点文件
|
|
|
*
|
|
@@ -70,103 +155,13 @@ public class GisCoordinateUtil {
|
|
|
double blat = bPointCoordinate.getDouble("latitude");
|
|
|
double bX = bPointLocation.getDouble("x");
|
|
|
double bY = bPointLocation.getDouble("y");
|
|
|
- calculateVariable(alon, alat, aX, aY, blon, blat, bX, bY);
|
|
|
+// calculateVariable(alon, alat, aX, aY, blon, blat, bX, bY);
|
|
|
// System.out.println(alon+" "+alat+" "+aX+" "+aY+" "+blon+" "+blat+" "+bX+" "+bY);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 控制点
|
|
|
- * 根据两个控制点计算增量及用于计算角度的两个向量
|
|
|
- *
|
|
|
- * @param alon
|
|
|
- * @param alat
|
|
|
- * @param aX
|
|
|
- * @param aY
|
|
|
- * @param blon
|
|
|
- * @param blat
|
|
|
- * @param bX
|
|
|
- * @param bY
|
|
|
- */
|
|
|
- public static void calculateVariable(double alon, double alat, double aX, double aY, double blon, double blat, double bX, double bY) {
|
|
|
-
|
|
|
- double[] a = GisCoordinateTransform.convert2000BLToGauss(alon, alat);
|
|
|
- double[] b = GisCoordinateTransform.convert2000BLToGauss(blon, blat);
|
|
|
-
|
|
|
- dx = a[0] - aX;
|
|
|
- dy = a[1] - aY;
|
|
|
- locationplaneVector = new double[2];
|
|
|
- locationplaneVector[0] = a[0] - b[0];
|
|
|
- locationplaneVector[1] = a[1] - b[1];
|
|
|
- geographicplaneVector = new double[2];
|
|
|
- geographicplaneVector[0] = aX - bX;
|
|
|
- geographicplaneVector[1] = aY - bY;
|
|
|
- centerLon = GisCoordinateTransform.getZone3CenterLon(alon);
|
|
|
- }
|
|
|
|
|
|
|
|
|
- /**
|
|
|
- * 本地坐标转经纬度
|
|
|
- *
|
|
|
- * @param loctionX
|
|
|
- * @param loctionY
|
|
|
- * @return
|
|
|
- */
|
|
|
- public static double[] transformLocationToBL(double loctionX, double loctionY) {
|
|
|
- double x1 = locationplaneVector[0];
|
|
|
- double y1 = locationplaneVector[1];
|
|
|
- double x2 = geographicplaneVector[0];
|
|
|
- double y2 = geographicplaneVector[1];
|
|
|
-// double tana1=y1/x1;
|
|
|
-// double tana2=y2/x2;
|
|
|
- double a1 = Math.atan2(y1, x1);
|
|
|
- double a2 = Math.atan2(y2, x2);
|
|
|
- double a = a2 - a1;
|
|
|
- double sinazimuth, cosazimuth;
|
|
|
- cosazimuth = Math.cos(a);
|
|
|
- sinazimuth = Math.sin(a);
|
|
|
- double resultX = loctionY * sinazimuth + loctionX * cosazimuth;
|
|
|
- double resultY = loctionY * cosazimuth - loctionX * sinazimuth;
|
|
|
- double x = resultX + dx;
|
|
|
- double y = resultY + dy;
|
|
|
-
|
|
|
-
|
|
|
-// return GisCoordinateTransform.Convert2000GaussToBL(x,y,centerLon);
|
|
|
-// return GisCoordinateTransform.convertByProj4(x,y, coordCode3857, coordCode4326);
|
|
|
- return GisCoordinateTransform.convert2000GaussToBL(x, y, centerLon);
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
- /**
|
|
|
- * 经纬度转本地坐标
|
|
|
- *
|
|
|
- * @param lon 经度 十进制度
|
|
|
- * @param lat 纬度 十进制度
|
|
|
- * @return
|
|
|
- */
|
|
|
- public static double[] transformBLToLocation(double lon, double lat) {
|
|
|
-
|
|
|
-
|
|
|
- double[] gauss = GisCoordinateTransform.convert2000BLToGauss(lon, lat);
|
|
|
- double x1 = locationplaneVector[0];
|
|
|
- double y1 = locationplaneVector[1];
|
|
|
- double x2 = geographicplaneVector[0];
|
|
|
- double y2 = geographicplaneVector[1];
|
|
|
- double a1 = Math.atan2(y1, x1);
|
|
|
- double a2 = Math.atan2(y2, x2);
|
|
|
-// double a=a1-a2;
|
|
|
- double a = 0;
|
|
|
- double sinazimuth, cosazimuth;
|
|
|
- cosazimuth = Math.cos(a);
|
|
|
- sinazimuth = Math.sin(a);
|
|
|
- double resultX = gauss[1] * sinazimuth + gauss[0] * cosazimuth;
|
|
|
- double resultY = gauss[1] * cosazimuth - gauss[0] * sinazimuth;
|
|
|
- double x = resultX - dx;
|
|
|
- double y = resultY - dy;
|
|
|
- double[] location = new double[2];
|
|
|
- location[0] = x;
|
|
|
- location[1] = y;
|
|
|
- return location;
|
|
|
- }
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -176,195 +171,31 @@ public class GisCoordinateUtil {
|
|
|
* @param dto 控制点
|
|
|
* @return
|
|
|
*/
|
|
|
- public static double[] convertGpsToLocation(double[] position, ControlPointEntity dto) {
|
|
|
- double[] controlLocation1 = dto.getAgeControlLocation1();
|
|
|
- double[] controlLocation2 = dto.getAgeControlLocation2();
|
|
|
-
|
|
|
- double[] controlCoordinate1 = dto.getGpsControlCoordinate1();
|
|
|
- double[] controlCoordinate2 = dto.getGpsControlCoordinate2();
|
|
|
- try {
|
|
|
- GisCoordinateUtil.calculateVariable(controlCoordinate1[0], controlCoordinate1[1], controlLocation1[0], controlLocation1[1], controlCoordinate2[0], controlCoordinate2[1], controlLocation2[0], controlLocation2[1]);
|
|
|
- double[] d = GisCoordinateUtil.transformBLToLocation(position[0], position[1]);
|
|
|
- return d;
|
|
|
- } catch (RuntimeException e) {
|
|
|
- log.error("坐标转换输入参数有误,请检查");
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
-// /**
|
|
|
-// * 本地坐标转经纬度
|
|
|
-// *
|
|
|
-// * @param position 经纬度
|
|
|
-// * @param dto 控制点
|
|
|
-// * @return
|
|
|
-// */
|
|
|
-// public static double[] convertLocationToGps(double[] position, ControlPointEntity dto) {
|
|
|
+// public static double[] convertGpsToLocation(double[] position, ControlPointEntity dto) {
|
|
|
// double[] controlLocation1 = dto.getAgeControlLocation1();
|
|
|
// double[] controlLocation2 = dto.getAgeControlLocation2();
|
|
|
//
|
|
|
// double[] controlCoordinate1 = dto.getGpsControlCoordinate1();
|
|
|
// double[] controlCoordinate2 = dto.getGpsControlCoordinate2();
|
|
|
-// GisCoordinateUtil.calculateVariable(controlCoordinate1[0], controlCoordinate1[1], controlLocation1[0], controlLocation1[1], controlCoordinate2[0], controlCoordinate2[1], controlLocation2[0], controlLocation2[1]);
|
|
|
-// double[] d = GisCoordinateUtil.transformLocationToBL(position[0], position[1]);
|
|
|
-// return d;
|
|
|
-// }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 两个控制点的纠偏,已知两个控制点的未纠偏前的经纬度和控制点的真实经纬度,求真实位置相对于未纠偏之前的旋转 角度
|
|
|
- * @param relativePoint1 【经度,纬度】 [113,22] ,页面输入的相对坐标转gis坐标
|
|
|
- * @param absolutelyPoint1 【经度,纬度】 [113,22] 绝对坐标:用页面输入的坐标
|
|
|
- * @param relativePoint2 【经度,纬度】 [113,22] ,页面输入的相对坐标转gis坐标
|
|
|
- * @param absolutelyPoint2 【经度,纬度】 [113,22] 绝对坐标:用页面输入的坐标
|
|
|
- * @return 弧度 设置到dataSet.orientation
|
|
|
- */
|
|
|
-// private static double getAngle(double[] relativePoint1,double[] absolutelyPoint1,double[] relativePoint2,double[] absolutelyPoint2){
|
|
|
-// double[] relativeVector=new double[2];
|
|
|
-// double[] absolutelyVector=new double[2];
|
|
|
-// relativeVector[0]=relativePoint2[0]-relativePoint1[0];
|
|
|
-// relativeVector[1]=relativePoint2[1]-relativePoint1[1];
|
|
|
-// absolutelyVector[0]=absolutelyPoint2[0]-absolutelyPoint1[0];
|
|
|
-// absolutelyVector[1]=absolutelyPoint2[1]-absolutelyPoint1[1];
|
|
|
-// double a1=Math.atan2(relativeVector[1], relativeVector[0]);
|
|
|
-// double a2=Math.atan2(absolutelyVector[1], absolutelyVector[0]);
|
|
|
-// return a1-a2;
|
|
|
-// }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取弧度
|
|
|
- *
|
|
|
- * @param dto
|
|
|
- * @return
|
|
|
- */
|
|
|
-// public static double getAngle(ControlPointEntity dto){
|
|
|
-//
|
|
|
-// double[] relativePoint1 = dto.getRelativePoint1();
|
|
|
-// double[] absolutelyPoint1 = dto.getGpsControlCoordinate1();
|
|
|
-// double[] relativePoint2 = dto.getRelativePoint2();
|
|
|
-// double[] absolutelyPoint2 = dto.getGpsControlCoordinate2();
|
|
|
-// return getAngle(relativePoint1, absolutelyPoint1, relativePoint2, absolutelyPoint2);
|
|
|
-//
|
|
|
-// }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取弧度, 采用本地坐标
|
|
|
- *
|
|
|
- * @param dto
|
|
|
- * @return
|
|
|
- */
|
|
|
-// public static double getAngleOrientation(ControlPointEntity dto) {
|
|
|
-//
|
|
|
-// //gps转本地坐标
|
|
|
-// double[] defaultP1 = convertGpsToLocation(dto.getGpsControlCoordinate1(), dto);
|
|
|
-// double[] defaultP2 = convertGpsToLocation(dto.getGpsControlCoordinate2(), dto);
|
|
|
-//
|
|
|
-// double[] ageControlLocation1 = dto.getAgeControlLocation1();
|
|
|
-// double[] ageControlLocation2 = dto.getAgeControlLocation2();
|
|
|
-//
|
|
|
-// return getAngle(defaultP1, defaultP2, ageControlLocation1, ageControlLocation2);
|
|
|
-//
|
|
|
-// }
|
|
|
-
|
|
|
- //采用本地坐标
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取弧度, 采用本地坐标
|
|
|
- * P1,P2是传过来的本地坐标
|
|
|
- * defaultP1和defaultP2是传过来的gis坐标通过当前的控制点转换成新的本地坐标
|
|
|
- *
|
|
|
- * @param defaultP1
|
|
|
- * @param defaultP2
|
|
|
- * @param P1 P1,P2是传过来的本地坐标
|
|
|
- * @param P2
|
|
|
- * @return
|
|
|
- */
|
|
|
-// private static double getAngle(double[] defaultP1, double[] defaultP2, double[] P1, double[] P2) {
|
|
|
-// double dx = P1[0] - defaultP1[0];
|
|
|
-// double dy = P1[1] - defaultP1[1];
|
|
|
-//
|
|
|
-// P2[0] = P2[0] - dx;
|
|
|
-// P2[1] = P2[1] - dy;
|
|
|
-//
|
|
|
-// //p1,p2,defaultP2
|
|
|
-// double angle = Angle(P1, P2, defaultP2);
|
|
|
-// return angle;
|
|
|
-// }
|
|
|
-//
|
|
|
-// private static double Angle(double[] p, double[] p1, double[] p2) {
|
|
|
-// double cosfi = 0, fi = 0, norm = 0;
|
|
|
-// double dsx = p1[0] - p[0];
|
|
|
-// double dsy = p1[1] - p[1];
|
|
|
-// double dex = p2[0] - p[0];
|
|
|
-// double dey = p2[1] - p[1];
|
|
|
-//
|
|
|
-// cosfi = dsx * dex + dsy * dey;
|
|
|
-// norm = (dsx * dsx + dsy * dsy) * (dex * dex + dey * dey);
|
|
|
-// cosfi /= Math.sqrt(norm);
|
|
|
-//
|
|
|
-// if (cosfi >= 1.0) return 0;
|
|
|
-// //if (cosfi <= -1.0) return Math.PI;
|
|
|
-// if (cosfi <= -1.0) return 180;
|
|
|
-// fi = Math.acos(cosfi);
|
|
|
-//
|
|
|
-// if (180 * fi / Math.PI < 180) {
|
|
|
-// return fi;
|
|
|
-// } else {
|
|
|
-// return 2 * Math.PI - fi;
|
|
|
+// try {
|
|
|
+//// log.info("输入控制点3: {}, {}, {}, {}, {}, {}, {}, {}", controlCoordinate1[0], controlCoordinate1[1], controlLocation1[0], controlLocation1[1], controlCoordinate2[0], controlCoordinate2[1], controlLocation2[0], controlLocation2[1]);
|
|
|
+//// GisCoordinateUtil.calculateVariable(controlCoordinate1[0], controlCoordinate1[1], controlLocation1[0], controlLocation1[1], controlCoordinate2[0], controlCoordinate2[1], controlLocation2[0], controlLocation2[1]);
|
|
|
+// double[] d = GisCoordinateUtil.transformBLToLocation(position[0], position[1]);
|
|
|
+// return d;
|
|
|
+// } catch (RuntimeException e) {
|
|
|
+// log.error("坐标转换输入参数有误,请检查");
|
|
|
+// e.printStackTrace();
|
|
|
// }
|
|
|
+// return null;
|
|
|
// }
|
|
|
|
|
|
|
|
|
- /**
|
|
|
- * 采用本地坐标
|
|
|
- * 获取dataSet.orientation:弧度
|
|
|
- * @param dto 控制点
|
|
|
- * @return
|
|
|
- */
|
|
|
- public static double getDataSetOrientation(ControlPointEntity dto) {
|
|
|
|
|
|
- //web输入控制点的gis坐标
|
|
|
- double[] webGisP1 = dto.getGpsControlCoordinate1();
|
|
|
- double[] webGisP2 = dto.getGpsControlCoordinate2();
|
|
|
-
|
|
|
-
|
|
|
- // 将算法部提供控制点赋值,用于计算
|
|
|
- double[] defaultGisP1 = dto.getDefaultGisP1();
|
|
|
- double[] defaultGisP2 = dto.getDefaultGisP2();
|
|
|
- double[] defaultLocation1 = dto.getDefaultLocation1();
|
|
|
- double[] defaultLocation2 = dto.getDefaultLocation2();
|
|
|
- if (defaultGisP1 == null || defaultGisP2 == null || defaultLocation1 == null || defaultLocation2 == null) {
|
|
|
- log.error("默认控制点数据有空值, 请检查默认控制点。尝试重算解决");
|
|
|
- throw new BaseRuntimeException("默认控制点数据有空值, 请检查默认控制点。尝试重算解决");
|
|
|
- }
|
|
|
|
|
|
- dto.setGpsControlCoordinate1(defaultGisP1);
|
|
|
- dto.setGpsControlCoordinate2(defaultGisP2);
|
|
|
- dto.setAgeControlLocation1(defaultLocation1);
|
|
|
- dto.setAgeControlLocation2(defaultLocation2);
|
|
|
- log.info("准备转换坐标");
|
|
|
- // defaultP1,defaultP2使用的是算法部提供的控制点得出结果, 人工输入gis坐标转 本地坐标
|
|
|
- double[] defaultP1 = convertGpsToLocation(webGisP1, dto);
|
|
|
- double[] defaultP2 = convertGpsToLocation(webGisP2, dto);
|
|
|
- log.info("转换本地坐标完成");
|
|
|
|
|
|
|
|
|
|
|
|
- // web输入控制点的本地坐标
|
|
|
- double[] ageControlLocation1 = dto.getAgeControlLocation1();
|
|
|
- double[] ageControlLocation2 = dto.getAgeControlLocation2();
|
|
|
|
|
|
- return getOrientation(defaultP1, defaultP2, ageControlLocation1, ageControlLocation2);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- @Test
|
|
|
- public void test11(){
|
|
|
- getDataSetOrientation(new ControlPointEntity());
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
|
@@ -415,6 +246,209 @@ public class GisCoordinateUtil {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * 求方位角度
|
|
|
+ * @param x
|
|
|
+ * @param y
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private static double azimyth(double x,double y){
|
|
|
+ double returnValue=0;
|
|
|
+ if(y>0&&x>0){
|
|
|
+ returnValue=Math.atan(y/x);
|
|
|
+ }else if(y>0&&x<0){
|
|
|
+ returnValue=Math.PI- Math.atan(y/Math.abs(x));
|
|
|
+ }else if(y<0&&x<0){
|
|
|
+ returnValue=Math.PI+Math.atan(y/x);
|
|
|
+ }else if(y<0&&x>0){
|
|
|
+ returnValue=2*Math.PI-Math.atan(Math.abs(y)/x);
|
|
|
+ }
|
|
|
+ return returnValue;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+// /**
|
|
|
+// * 控制点初始化作用, 只有控制点变化, 才会调用一次, 以后坐标转换都是基于这个值使用
|
|
|
+// * @param alon
|
|
|
+// * @param alat
|
|
|
+// * @param aX
|
|
|
+// * @param aY
|
|
|
+// * @param blon
|
|
|
+// * @param blat
|
|
|
+// * @param bX
|
|
|
+// * @param bY
|
|
|
+// */
|
|
|
+// public static void calculateVariable (double alon,double alat,double aX,double aY,double blon,double blat,double bX,double bY){
|
|
|
+//
|
|
|
+//
|
|
|
+// try {
|
|
|
+// double[] a= new double[0];
|
|
|
+// a = GisCoordinateTransform.convertByProj4(alon, alat,"EPSG:4490","EPSG:4547");
|
|
|
+// double[] b= GisCoordinateTransform.convertByProj4(blon, blat,"EPSG:4490","EPSG:4547");
|
|
|
+// log.info("经度2、纬度2: {}, {}", alon, alat );
|
|
|
+// log.info("经度4、纬度4: {}, {}", blon, blat );
|
|
|
+// log.info("大地2: {}, {}", a[0], a[1]);
|
|
|
+// log.info("大地4: {}, {}", b[0], b[1]);
|
|
|
+// Point point1 = new Point(a[0],a[1]);
|
|
|
+// Point point2 = new Point(b[0],b[1]);
|
|
|
+// Point newPoint1 = new Point(aX,aY);
|
|
|
+// Point newPoint2 = new Point(bX,bY);
|
|
|
+// log.info("========== start calculateVariable =================");
|
|
|
+// // 2021-09-13 修改:前后对调一下
|
|
|
+// rotation1 = Math.toRadians(AffineTransform.getAngle(point1 , point2 ) - AffineTransform.getAngle(newPoint1 , newPoint2 ));
|
|
|
+// scale1 = AffineTransform.getScale( point1 , newPoint1 , point2 , newPoint2);
|
|
|
+//// log.info("rotation1: {}", rotation1);
|
|
|
+// dx1 = AffineTransform.getXTranslation( point1 ,newPoint1, rotation1, scale1);
|
|
|
+// dy1 = AffineTransform.getYTranslation( point1 ,newPoint1, rotation1, scale1);
|
|
|
+// log.warn("rotation1: {}", rotation1);
|
|
|
+// log.warn("scale1: {}", scale1);
|
|
|
+// log.warn("tx1: {}", dx1);
|
|
|
+// log.warn("ty1: {}", dy1);
|
|
|
+// rotation2 = Math.toRadians(AffineTransform.getAngle(newPoint1 , newPoint2 ) - AffineTransform.getAngle(point1 , point2 ));
|
|
|
+//// log.info("rotation2: {}", rotation2);
|
|
|
+// scale2 = AffineTransform.getScale( newPoint1 , point1 , newPoint2 , point2);
|
|
|
+// dx2 = AffineTransform.getXTranslation( newPoint1 ,point1, rotation2, scale1);
|
|
|
+// dy2 = AffineTransform.getYTranslation( newPoint1 ,point1, rotation2, scale1);
|
|
|
+//
|
|
|
+// log.warn("rotation2: {}", rotation2);
|
|
|
+// log.warn("scale2: {}", scale2);
|
|
|
+// log.warn("tx2: {}", dx2);
|
|
|
+// log.warn("ty2: {}", dy2);
|
|
|
+//
|
|
|
+// log.info("========== end calculateVariable =================");
|
|
|
+// } catch (RuntimeException e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 控制点初始化作用, 只有控制点变化, 才会调用一次, 以后坐标转换都是基于这个值使用
|
|
|
+// * @param alon
|
|
|
+// * @param alat
|
|
|
+// * @param aX
|
|
|
+// * @param aY
|
|
|
+// * @param blon
|
|
|
+// * @param blat
|
|
|
+// * @param bX
|
|
|
+// * @param bY
|
|
|
+ */
|
|
|
+// public static void calculateVariable (double alon,double alat,double aX,double aY,double blon,double blat,double bX,double bY){
|
|
|
+ public static ControlPointCalculateEntity calculateVariable (ControlPointEntity dto){
|
|
|
+ double[] controlLocation1 = dto.getAgeControlLocation1();
|
|
|
+ double[] controlLocation2 = dto.getAgeControlLocation2();
|
|
|
+
|
|
|
+ double[] controlCoordinate1 = dto.getGpsControlCoordinate1();
|
|
|
+ double[] controlCoordinate2 = dto.getGpsControlCoordinate2();
|
|
|
+
|
|
|
+ double alon = controlCoordinate1[0];
|
|
|
+ double alat = controlCoordinate1[1];
|
|
|
+ double aX = controlLocation1[0];
|
|
|
+ double aY = controlLocation1[1];
|
|
|
+ double blon = controlCoordinate2[0];
|
|
|
+ double blat = controlCoordinate2[1];
|
|
|
+ double bX = controlLocation2[0];
|
|
|
+ double bY = controlLocation2[1];
|
|
|
+
|
|
|
+ try {
|
|
|
+ double[] a= new double[0];
|
|
|
+ a = GisCoordinateTransform.convertByProj4(alon, alat,"EPSG:4490","EPSG:4547");
|
|
|
+ double[] b= GisCoordinateTransform.convertByProj4(blon, blat,"EPSG:4490","EPSG:4547");
|
|
|
+ Point point1 = new Point(a[0],a[1]);
|
|
|
+ Point point2 = new Point(b[0],b[1]);
|
|
|
+ Point newPoint1 = new Point(aX,aY);
|
|
|
+ Point newPoint2 = new Point(bX,bY);
|
|
|
+ log.info("========== start calculateVariable =================");
|
|
|
+ double rotation1 = Math.toRadians(AffineTransform.getAngle(point1 , point2 ) - AffineTransform.getAngle(newPoint1 , newPoint2 ));
|
|
|
+ double scale1 = AffineTransform.getScale( point1 , newPoint1 , point2 , newPoint2);
|
|
|
+// log.info("rotation1: {}", rotation1);
|
|
|
+ double dx1 = AffineTransform.getXTranslation( point1 ,newPoint1, rotation1, scale1);
|
|
|
+ double dy1 = AffineTransform.getYTranslation( point1 ,newPoint1, rotation1, scale1);
|
|
|
+
|
|
|
+ double rotation2 = Math.toRadians(AffineTransform.getAngle(newPoint1 , newPoint2 ) - AffineTransform.getAngle(point1 , point2 ));
|
|
|
+ double scale2 = AffineTransform.getScale( newPoint1 , point1 , newPoint2 , point2);
|
|
|
+ log.info("输入参数1:{}, {}", newPoint1.getX(), newPoint1.getY());
|
|
|
+ log.info("输入参数2:{}, {}", point1.getX(), point1.getY());
|
|
|
+ log.info("输入参数 rotation2:{}, {}", rotation2);
|
|
|
+ log.info("输入参数 scale2:{}, {}", scale2);
|
|
|
+// double dx2 = AffineTransform.getXTranslation( newPoint1 ,point1, rotation2, scale1);
|
|
|
+// double dy2 = AffineTransform.getYTranslation( newPoint1 ,point1, rotation2, scale1);
|
|
|
+
|
|
|
+ // 2021-09-13 这里应该使用scale2
|
|
|
+ double dx2 = AffineTransform.getXTranslation( newPoint1 ,point1, rotation2, scale2);
|
|
|
+ log.info("输出结果 dx2:{}, {}", dx2);
|
|
|
+ double dy2 = AffineTransform.getYTranslation( newPoint1 ,point1, rotation2, scale2);
|
|
|
+ log.info("输出结果 dy2:{}, {}", dy2);
|
|
|
+
|
|
|
+
|
|
|
+ ControlPointCalculateEntity entity = new ControlPointCalculateEntity();
|
|
|
+ entity.setRotation1(rotation1);
|
|
|
+ entity.setScale1(scale1);
|
|
|
+ entity.setDx1(dx1);
|
|
|
+ entity.setDy1(dy1);
|
|
|
+
|
|
|
+
|
|
|
+ entity.setRotation2(rotation2);
|
|
|
+ entity.setScale2(scale2);
|
|
|
+ entity.setDx2(dx2);
|
|
|
+ entity.setDy2(dy2);
|
|
|
+ log.warn("平面坐标 start");
|
|
|
+ log.info("参数 rotation1:{}", rotation1);
|
|
|
+ log.info("参数 scale1:{}", scale1);
|
|
|
+ log.info("参数 dx1:{}", dx1);
|
|
|
+ log.info("参数 dy1:{}", dy1);
|
|
|
+ log.info("参数 rotation2:{}", rotation2);
|
|
|
+ log.info("参数 scale2:{}", scale2);
|
|
|
+ log.info("参数 dx2:{}", dx2);
|
|
|
+ log.info("参数 dy2:{}", dy2);
|
|
|
+ log.warn("平面坐标 end");
|
|
|
+
|
|
|
+ return entity;
|
|
|
+ } catch (RuntimeException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 控制点赋值,初始化
|
|
|
+ */
|
|
|
+// public void initAssign(ControlPointEntity dto){
|
|
|
+// double[] controlLocation1 = dto.getAgeControlLocation1();
|
|
|
+// double[] controlLocation2 = dto.getAgeControlLocation2();
|
|
|
+//
|
|
|
+// double[] controlCoordinate1 = dto.getGpsControlCoordinate1();
|
|
|
+// double[] controlCoordinate2 = dto.getGpsControlCoordinate2();
|
|
|
+//
|
|
|
+// log.info("输入控制点1: {}, {}, {}, {}, {}, {}, {}, {}", controlCoordinate1[0], controlCoordinate1[1], controlLocation1[0], controlLocation1[1], controlCoordinate2[0], controlCoordinate2[1], controlLocation2[0], controlLocation2[1]);
|
|
|
+// GisCoordinateUtil.calculateVariable (
|
|
|
+// controlCoordinate1[0],controlCoordinate1[1],
|
|
|
+// controlLocation1[0],controlLocation1[1],
|
|
|
+// controlCoordinate2[0],controlCoordinate2[1],
|
|
|
+// controlLocation2[0],controlLocation2[1]);
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testcp(){
|
|
|
+ double[] a1 = GisCoordinateTransform.convertByProj4(113.594635361111 , 22.367307611111 ,"EPSG:4490","EPSG:4547");
|
|
|
+ double[] a2 = GisCoordinateTransform.convertByProj4(113.594615305556 , 22.367325305556 ,"EPSG:4490","EPSG:4547");
|
|
|
+ double[] a3 = GisCoordinateTransform.convertByProj4(113.594646722222 , 22.367337138889 ,"EPSG:4490","EPSG:4547");
|
|
|
+ double[] a4 = GisCoordinateTransform.convertByProj4(113.594664777778 , 22.367347694444 ,"EPSG:4490","EPSG:4547");
|
|
|
+ log.info("a1: {}, {}", a1[0], a1[1]);
|
|
|
+ log.info("a2: {}, {}", a2[0], a2[1]);
|
|
|
+ log.info("a3: {}, {}", a3[0], a3[1]);
|
|
|
+ log.info("a4: {}, {}", a4[0], a4[1]);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
}
|