|
|
@@ -16,6 +16,7 @@ import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.commons.collections4.MapUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.gdal.ogr.*;
|
|
|
+import org.gdal.osr.CoordinateTransformation;
|
|
|
import org.gdal.osr.SpatialReference;
|
|
|
import org.locationtech.jts.io.ParseException;
|
|
|
import org.locationtech.jts.io.WKBReader;
|
|
|
@@ -675,6 +676,122 @@ public class CadastreManageServiceImpl implements CadastreManageService {
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * 调整坐标系导入系统展示不准问题
|
|
|
+ *
|
|
|
+ * @param layer
|
|
|
+ * @param fieldNameAndTypeMap
|
|
|
+ * @param haveGeom
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<Map<String, Object>> getValueList2(Layer layer, Map<String, String> fieldNameAndTypeMap, Boolean haveGeom) {
|
|
|
+ // 目标坐标系固定为 4326(WGS84),写入数据库用
|
|
|
+ final int TARGET_SRID = 4326;
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ // ========== 2. 创建坐标转换对象(4527 → 4326) ==========
|
|
|
+ CoordinateTransformation transform = null;
|
|
|
+ try {
|
|
|
+ if (sourceSRID != TARGET_SRID) {
|
|
|
+ SpatialReference srcSR = new SpatialReference();
|
|
|
+ srcSR.ImportFromEPSG(sourceSRID);
|
|
|
+
|
|
|
+ SpatialReference targetSR = new SpatialReference();
|
|
|
+ targetSR.ImportFromEPSG(TARGET_SRID);
|
|
|
+
|
|
|
+ // 创建转换工具
|
|
|
+ transform = CoordinateTransformation.CreateCoordinateTransformation(srcSR, targetSR);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("创建坐标转换失败(源{}→目标{})", sourceSRID, TARGET_SRID, e);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Map<String, Object>> list = new ArrayList<>();
|
|
|
+ layer.ResetReading();
|
|
|
+ Feature feature;
|
|
|
+
|
|
|
+ while ((feature = layer.GetNextFeature()) != null) {
|
|
|
+ Map<String, Object> map = new LinkedHashMap<>();
|
|
|
+ // 读取属性字段(原逻辑不变)
|
|
|
+ for (int i = 0; i < feature.GetFieldCount(); i++) {
|
|
|
+ String fieldName = feature.GetFieldDefnRef(i).GetName();
|
|
|
+ if (fieldNameAndTypeMap.containsKey(fieldName.toLowerCase())) {
|
|
|
+ String fieldType = fieldNameAndTypeMap.get(fieldName.toLowerCase());
|
|
|
+ if (StringUtils.containsIgnoreCase(fieldType, "character")) {
|
|
|
+ map.put(fieldName, feature.GetFieldAsString(i));
|
|
|
+ } else if (StringUtils.containsIgnoreCase(fieldType, "integer")) {
|
|
|
+ map.put(fieldName, feature.GetFieldAsInteger(i));
|
|
|
+ } else if (StringUtils.containsIgnoreCase(fieldType, "date")) {
|
|
|
+ //todo 日期转化
|
|
|
+ map.put(fieldName, feature.GetFieldAsString(i));
|
|
|
+ } else if (StringUtils.containsIgnoreCase(fieldType, "numeric")) {
|
|
|
+ map.put(fieldName, feature.GetFieldAsDouble(i));
|
|
|
+ } else {
|
|
|
+ map.put(fieldName, feature.GetFieldAsString(i));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ map.put(fieldName, feature.GetFieldAsString(i));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // ========== 3. 处理几何体:转换坐标 + 输出4326 ==========
|
|
|
+ if (haveGeom.equals(true)) {
|
|
|
+ String ewkt = null;
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ map.put("geom", ewkt);
|
|
|
+ }
|
|
|
+
|
|
|
+ list.add(map);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 关闭释放资源
|
|
|
+ if (transform != null) {
|
|
|
+ transform.delete();
|
|
|
+ }
|
|
|
+
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 校验当前图层坐标系是否为:CGCS2000
|
|
|
*
|