Ver código fonte

调整读取坐标

chenendian 1 dia atrás
pai
commit
724682b2c0

+ 7 - 0
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/mapper/CadastreFileMapper.java

@@ -114,4 +114,11 @@ public interface CadastreFileMapper {
 
     String checkQueryWhere(@Param("tableName") String tableName, @Param("queryWhere") String queryWhere);
 
+    String transformTo4326(@Param("ewkt") String ewkt);
+
+
+
+
+
+
 }

+ 58 - 47
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/service/cadastre/impl/CadastreManageServiceImpl.java

@@ -626,6 +626,22 @@ public class CadastreManageServiceImpl implements CadastreManageService {
      */
     private List<Map<String, Object>> getValueList(Layer layer, Map<String, String> fieldNameAndTypeMap, Boolean haveGeom) {
         List<Map<String, Object>> list = new ArrayList<>();
+        Integer sourceSRID = 4326;
+
+        // ========== 1. 获取源数据坐标系 EPSG:4527 ==========
+        try {
+            SpatialReference srcSR = layer.GetSpatialRef();
+            if (srcSR != null) {
+                srcSR.AutoIdentifyEPSG();
+                String code = srcSR.GetAuthorityCode(null);
+                if (code != null) {
+                    sourceSRID = Integer.parseInt(code);
+                }
+            }
+        } catch (Exception e) {
+            log.warn("获取图层坐标系SRID失败,使用默认4326", e);
+        }
+
         layer.ResetReading();
         Feature feature;
         while ((feature = layer.GetNextFeature()) != null) {
@@ -652,24 +668,13 @@ public class CadastreManageServiceImpl implements CadastreManageService {
                     log.warn("当前图层-{},多出字段-{}",layer.GetName(),fieldName);
                 }
             }
-
             if (haveGeom.equals(true)) {
                 String ewkt = null;
                 Geometry geom = feature.GetGeometryRef();
                 if (geom != null) {
-                    // 创建空间参考对象(例如 WGS84,SRID 4326)
-//                    SpatialReference spatialRef = new SpatialReference();
-//                    spatialRef.SetWellKnownGeogCS("WGS84");
-//                    // 为几何体设置空间参考(SRID 4326)
-//                    geom.AssignSpatialReference(spatialRef);
-                    // 将几何对象转换为 WKT 格式
-                    geom = geom.MakeValid();
-                    int type = geom.GetGeometryType() & 0xFF;
-                    if (type != ogr.wkbPolygon && type != ogr.wkbMultiPolygon) {
-                        continue; // 直接跳过
-                    }
-                    ewkt = "SRID=" + 4326 + ";" + geom.ExportToWkt();
-                    ;
+                    String wkt = geom.ExportToWkt();
+                    ewkt = "SRID=" + sourceSRID + ";" + wkt;
+                    ewkt = this.transforGeomTo4326(ewkt);
                 }
                 map.put("geom", ewkt);
             }
@@ -679,6 +684,7 @@ public class CadastreManageServiceImpl implements CadastreManageService {
     }
 
 
+
     /**
      *
      * 调整坐标系导入系统展示不准问题
@@ -752,48 +758,30 @@ public class CadastreManageServiceImpl implements CadastreManageService {
                 }
             }
 
-
             // ========== 3. 处理几何体:转换坐标 + 输出4326 ==========
             if (haveGeom.equals(true)) {
-                String ewkt = null;
+                String ewkt = "";
                 Geometry geom = feature.GetGeometryRef();
                 if (geom != null) {
-                    try {
-                        geom = geom.MakeValid();
-                        int type = geom.GetGeometryType() & 0xFF;
-                        // 只保留面/多面
-                        if (type != ogr.wkbPolygon && type != ogr.wkbMultiPolygon) {
-                            continue;
-                        }
-
-                        // ========== 坐标转换核心代码 ==========
-                        if (transform != null) {
-                            geom.Transform(transform); // 4527 → 4326
-                        }
-
-                        // 固定输出 4326 的 EWKT
-                        ewkt = "SRID=" + TARGET_SRID + ";" + geom.ExportToWkt();
-                    } catch (Exception e) {
-                        log.error("要素几何体转换失败", e);
-                    }
+                    String wkt = geom.ExportToWkt();
+                    ewkt = "SRID=" + sourceSRID + ";" + wkt;
+                    ewkt = this.transforGeomTo4326(ewkt);
                 }
                 map.put("geom", ewkt);
             }
-
             list.add(map);
         }
 
+
         // 关闭释放资源
         if (transform != null) {
             transform.delete();
         }
-
         return list;
     }
 
 
 
-
     /**
      * 校验当前图层坐标系是否为:CGCS2000
      *
@@ -848,22 +836,31 @@ public class CadastreManageServiceImpl implements CadastreManageService {
      * @param layer
      * @return
      */
-    private static List<String> getLayerGeom(Layer layer) {
+    private List<String> getLayerGeom(Layer layer) {
         List<String> list = new ArrayList<>();
+        SpatialReference srcSrs = layer.GetSpatialRef();
+        Integer srid = null;
+        if (srcSrs != null) {
+            String authCode = srcSrs.GetAuthorityCode(null);
+            if (authCode != null) {
+                srid = Integer.parseInt(authCode);
+            }
+        }
+        if (srid == null) {
+            srid = 4527;
+        }
+
         layer.ResetReading();
         Feature feature;
         while ((feature = layer.GetNextFeature()) != null) {
             Geometry geom = feature.GetGeometryRef();
-            String ewkt = "";
-            if (geom != null) {
-                geom = geom.MakeValid();
-                int type = geom.GetGeometryType() & 0xFF;
-                if (type != ogr.wkbPolygon && type != ogr.wkbMultiPolygon) {
-                    continue; // 直接跳过
-                }
-                // 将几何对象转换为 WKT 格式
-                ewkt = "SRID=" + 4326 + ";" + geom.ExportToWkt();
+            if (geom == null) {
+                list.add("");
+                continue;
             }
+            String wkt = geom.ExportToWkt();
+            String ewkt = "SRID=" + srid + ";" + wkt;
+            ewkt = this.transforGeomTo4326(ewkt);
             list.add(ewkt);
         }
         return list;
@@ -1532,6 +1529,20 @@ public class CadastreManageServiceImpl implements CadastreManageService {
     }
 
 
+    /**
+     * 4527坐标系转换为4326坐标系
+     * @param ewkt
+     * @return
+     */
+    private String  transforGeomTo4326(String ewkt) {
+        if(StringUtils.isBlank(ewkt)){
+            return "";
+        }
+        return cadastreFileMapper.transformTo4326(ewkt);
+    }
+
+
+
 
 
 

+ 13 - 0
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/service/third/impl/DealExcelServiceImpl.java

@@ -688,6 +688,7 @@ public class DealExcelServiceImpl {
                 Map<String, String> jdMap = jdList.get(i);
                 String projectFileName = jdMap.get("数据治理文件名");
                 String nodeFileName = "03土地供应阶段";
+                writeToLog("project_file_name_err2.log", "excel行(" + i + ")-> "+projectFileName);
 
                 String currentGdType =  gdType.equalsIgnoreCase("出让") ? "1" : (gdType.equalsIgnoreCase("划拨")? "2" : "1");
                 dealCurrentNodeAttachment(projectId, id, projectFileName, nodeFileName, currentGdType);
@@ -955,6 +956,18 @@ public class DealExcelServiceImpl {
             return;
         }
 
+        List<String> aa = List.of(
+                "2020-3 赣江新区直管区国药南大道以东、规划路以南、国药支路以西、慈菇东路以北(SHD02-07)",
+                "2020-4 赣江新区直管区欧阳修支路以东、欧阳修路以南、储备用地以西、慈菇东路以北(SHD04-05-01)",
+                "2020-12 赣江新区直管区济生南路以东、欧阳修路以南、储备用地以西、慈菇东路以北SHD06-03"
+        );
+
+        if(aa.contains(projectFileName)){
+            int a1=100;
+            int b2=a1+100;
+            log.info("附件材料处理逻辑:{},{}", projectFileName,b2);
+        }
+
         //这里先初始化项目
         nodeAttachmentService.addDefaultAttachment(projectId, nodeId,gdType);
 

+ 9 - 0
siwei-modules/siwei-apply/src/main/resources/mapper/cadastre/CadastreFileMapper.xml

@@ -406,4 +406,13 @@
         SELECT 1 FROM vector.${tableName} WHERE ${queryWhere} LIMIT 1
     </select>
 
+
+    <select id="transformTo4326"   resultType="String">
+        SELECT public.st_asewkt(wktField) from
+        (SELECT   public.st_transform(public.st_geomfromewkt(#{ewkt}), 4326) as wktField)
+    </select>
+
+
+
+
 </mapper>