|
|
@@ -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);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
|