فهرست منبع

第三方导入增加源坐标系处理

欧阳劲驰 2 هفته پیش
والد
کامیت
4a7b23cd91

+ 4 - 0
src/main/java/com/shkpr/service/alambizplugin/apiparam/GisSurveyThirdImportParams.java

@@ -36,6 +36,10 @@ public class GisSurveyThirdImportParams {
      */
     private String nature;
     /**
+     * 源坐标系code
+     */
+    private String sourceCRSCode;
+    /**
      * 是否重置点号
      */
     private Boolean resetNo;

+ 30 - 4
src/main/java/com/shkpr/service/alambizplugin/components/GisSurveyThirdImporter.java

@@ -3,6 +3,7 @@ package com.shkpr.service.alambizplugin.components;
 import com.global.base.log.LogLevelFlag;
 import com.global.base.log.LogPrintMgr;
 import com.shkpr.service.alambizplugin.apiparam.GisSurveyThirdImportParams;
+import com.shkpr.service.alambizplugin.commtools.CRSUtil;
 import com.shkpr.service.alambizplugin.commtools.ExcelUtils;
 import com.shkpr.service.alambizplugin.commtools.PointCodeUtil;
 import com.shkpr.service.alambizplugin.commtools.ThirdImportTemplateUtils;
@@ -13,6 +14,7 @@ import com.shkpr.service.alambizplugin.components.checker.DuplicatePointsFinder;
 import com.shkpr.service.alambizplugin.components.checker.InvalidLinesFinder;
 import com.shkpr.service.alambizplugin.components.checker.InvalidPropertiesFinder;
 import com.shkpr.service.alambizplugin.constants.CommAsyncStatusEnum;
+import com.shkpr.service.alambizplugin.constants.CommCRSDefine;
 import com.shkpr.service.alambizplugin.constants.ExcelEnum;
 import com.shkpr.service.alambizplugin.constants.GisMetadataDefine;
 import com.shkpr.service.alambizplugin.constants.GisSurveyExcelDefine;
@@ -35,8 +37,8 @@ import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.math.NumberUtils;
 import org.locationtech.jts.geom.Coordinate;
+import org.locationtech.jts.geom.Geometry;
 import org.locationtech.jts.geom.GeometryFactory;
-import org.locationtech.jts.geom.Point;
 import org.locationtech.jts.geom.PrecisionModel;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.scheduling.annotation.AsyncResult;
@@ -451,14 +453,38 @@ public class GisSurveyThirdImporter {
                     layerApply.setDepth(Double.valueOf(propertyValue.getValue()));
             }
         }
-        layerApply.setPropertyValues(propertyValueList);
 
-        //填入经纬度
+        //处理经纬度
         if (lng != null && lat != null) {
-            Point geometry = geometryFactory.createPoint(new Coordinate(lng, lat));
+            //构建geom
+            Geometry geometry = geometryFactory.createPoint(new Coordinate(lng, lat));
+            //如源不为大地2000
+            if (!Objects.equals(params.getSourceCRSCode(), CommCRSDefine.CGCS2000)) {
+                //转换坐标系
+                Geometry transform = CRSUtil.transform(geometry, params.getSourceCRSCode(), CommCRSDefine.CGCS2000);
+                if (transform != null) {
+                    //回填geom
+                    geometry = transform;
+                    //获取解析后的经纬度
+                    Coordinate coordinate = geometry.getCoordinate();
+                    String lngStr = BigDecimal.valueOf(coordinate.getX()).toPlainString();
+                    String latStr = BigDecimal.valueOf(coordinate.getY()).toPlainString();
+                    //回填经纬度属性
+                    propertyValueList.stream()
+                            .filter(it -> Objects.equals(it.getProperty(), GisSurveyExcelDefine.TEMPLATE.LAT))
+                            .forEach(it -> it.setValue(latStr));
+                    propertyValueList.stream()
+                            .filter(it -> Objects.equals(it.getProperty(), GisSurveyExcelDefine.TEMPLATE.LNG))
+                            .forEach(it -> it.setValue(lngStr));
+                }
+            }
+            //设置geom
             layerApply.setGis(geometry);
         }
 
+        //设置属性
+        layerApply.setPropertyValues(propertyValueList);
+
         return layerApply;
     }
 

+ 14 - 0
src/main/java/com/shkpr/service/alambizplugin/constants/CommCRSDefine.java

@@ -0,0 +1,14 @@
+package com.shkpr.service.alambizplugin.constants;
+
+/**
+ * 通用crs定义
+ *
+ * @author 欧阳劲驰
+ * @since 1.0.0
+ */
+public interface CommCRSDefine {
+    /**
+     * 大地2000
+     */
+    String CGCS2000 = "4490";
+}

+ 5 - 2
src/main/java/com/shkpr/service/alambizplugin/controller/ApiGisSurveyController.java

@@ -276,6 +276,7 @@ public class ApiGisSurveyController {
      * @param operator      操作人
      * @param jobId         任务id
      * @param nature        用水性质,supply/drain
+     * @param sourceCRSCode 源坐标系code
      * @param resetNo       是否重置点号
      * @param ignoreFail    是否忽略失败
      * @return 第三方导入结果
@@ -288,6 +289,7 @@ public class ApiGisSurveyController {
             , @RequestParam(value = "operator", required = false) String operator
             , @RequestParam(value = "jobId", required = false) String jobId
             , @RequestParam(value = "nature", required = false) String nature
+            , @RequestParam(value = "sourceCRSCode", required = false, defaultValue = "4490") String sourceCRSCode
             , @RequestParam(value = "resetNo", required = false) Boolean resetNo
             , @RequestParam(value = "checkConstraint", required = false, defaultValue = "false") Boolean checkConstraint
             , @RequestParam(value = "ignoreFail", required = false, defaultValue = "false") String ignoreFail) throws SelfException {
@@ -304,7 +306,8 @@ public class ApiGisSurveyController {
                     , ResponseCode.STATUS_ERROR_PARAM_FORMAT.toStrMsg()));
         }
         //构建入参数
-        GisSurveyThirdImportParams params = new GisSurveyThirdImportParams(files, operator, jobId, nature, resetNo, checkConstraint, Boolean.parseBoolean(ignoreFail));
+        GisSurveyThirdImportParams params = new GisSurveyThirdImportParams(files, operator, jobId, nature, sourceCRSCode,
+                resetNo, checkConstraint, Boolean.parseBoolean(ignoreFail));
         //begin
         long llReqBefore = System.currentTimeMillis();
         String strRunSeq = String.format("%d-%d", llReqBefore, mSeqThirdImportReq.incrementAndGet());
@@ -1141,7 +1144,7 @@ public class ApiGisSurveyController {
         final String strPlatform = CommTool.getPlatformByAgent(strClientType, strUserAgent);
         final String strUserId = (String) request.getAttribute(TokenAuthenticationService.HEADER_USERID);
 
-        if (oJsonParam == null || bindRes.hasErrors() || oJsonParam.getGeometry()==null) {
+        if (oJsonParam == null || bindRes.hasErrors() || oJsonParam.getGeometry() == null) {
             throw new SelfException(ResponseCode.STATUS_ERROR_JSON_FORMAT.toStrCode()
                     , String.format(ApiURI.EXCEPTION_FORMAT
                     , strPlatform

+ 7 - 1
src/main/java/com/shkpr/service/alambizplugin/dbdao/pgtype/GeomLineStringTypeHandlePg.java

@@ -11,6 +11,7 @@ import org.locationtech.jts.geom.LineString;
 import org.locationtech.jts.geom.PrecisionModel;
 
 import java.io.IOException;
+import java.math.BigDecimal;
 import java.sql.CallableStatement;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
@@ -67,7 +68,12 @@ public class GeomLineStringTypeHandlePg extends BaseTypeHandler<LineString> {
         if (lineString != null && lineString.getCoordinates() != null && lineString.getCoordinates().length == 2) {
             Coordinate p0 = lineString.getCoordinateN(0);
             Coordinate p1 = lineString.getCoordinateN(1);
-            String value = String.format("[[%s,%s],[%s,%s]]", p0.x, p0.y, p1.x, p1.y);
+            String value = String.format("[[%s,%s],[%s,%s]]",
+                    BigDecimal.valueOf(p0.x).toPlainString(),
+                    BigDecimal.valueOf(p0.y).toPlainString(),
+                    BigDecimal.valueOf(p1.x).toPlainString(),
+                    BigDecimal.valueOf(p1.y).toPlainString()
+            );
             ps.setString(i, value);
         } else {
             //处理空值

+ 5 - 1
src/main/java/com/shkpr/service/alambizplugin/dbdao/pgtype/GeomPointTypeHandlePg.java

@@ -11,6 +11,7 @@ import org.locationtech.jts.geom.Point;
 import org.locationtech.jts.geom.PrecisionModel;
 
 import java.io.IOException;
+import java.math.BigDecimal;
 import java.sql.CallableStatement;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
@@ -63,7 +64,10 @@ public class GeomPointTypeHandlePg extends BaseTypeHandler<Point> {
     public void setNonNullParameter(PreparedStatement ps, int i, Point point, JdbcType jdbcType) throws SQLException {
         if (point != null && point.getCoordinate() != null) {
             //将 Point 序列化化为 [x,y] 字符串
-            String pointStr = String.format("[%f,%f]", point.getX(), point.getY());
+            String pointStr = String.format("[%s,%s]",
+                    BigDecimal.valueOf(point.getX()).toPlainString(),
+                    BigDecimal.valueOf(point.getY()).toPlainString()
+            );
             ps.setString(i, pointStr);
         } else {
             //处理空值

+ 11 - 2
src/main/java/com/shkpr/service/alambizplugin/dbdao/pgtype/GeomTypeHandlePg.java

@@ -12,6 +12,7 @@ import org.locationtech.jts.geom.LineString;
 import org.locationtech.jts.geom.Point;
 
 import java.io.IOException;
+import java.math.BigDecimal;
 import java.sql.CallableStatement;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
@@ -34,7 +35,10 @@ public class GeomTypeHandlePg extends BaseTypeHandler<Geometry> {
             //将 Point 序列化化为 [x,y] 字符串
             Point point = (Point) geometry;
             if (point.getCoordinate() != null) {
-                String pointStr = String.format("[%s,%s]", point.getX(), point.getY());
+                String pointStr = String.format("[%s,%s]",
+                        BigDecimal.valueOf(point.getX()).toPlainString(),
+                        BigDecimal.valueOf(point.getY()).toPlainString()
+                );
                 ps.setString(i, pointStr);
                 return;
             }
@@ -44,7 +48,12 @@ public class GeomTypeHandlePg extends BaseTypeHandler<Geometry> {
             if (lineString.getCoordinates() != null && lineString.getCoordinates().length == 2) {
                 Coordinate p0 = lineString.getCoordinateN(0);
                 Coordinate p1 = lineString.getCoordinateN(1);
-                String value = String.format("[[%s,%s],[%s,%s]]", p0.x, p0.y, p1.x, p1.y);
+                String value = String.format("[[%s,%s],[%s,%s]]",
+                        BigDecimal.valueOf(p0.x).toPlainString(),
+                        BigDecimal.valueOf(p0.y).toPlainString(),
+                        BigDecimal.valueOf(p1.x).toPlainString(),
+                        BigDecimal.valueOf(p1.y).toPlainString()
+                );
                 ps.setString(i, value);
                 return;
             }