Browse Source

[feat]提交:修改部门区域解析逻辑②

pull/7/head
杨威 2 weeks ago
parent
commit
7d9bf35f45
  1. 2
      dk-modules/system/src/main/java/org/dromara/system/service/impl/SysDepartBoundaryServiceImpl.java
  2. 33
      dk-modules/system/src/main/java/org/dromara/system/utils/KmzParserUtil.java

2
dk-modules/system/src/main/java/org/dromara/system/service/impl/SysDepartBoundaryServiceImpl.java

@ -116,7 +116,7 @@ public class SysDepartBoundaryServiceImpl extends ServiceImpl<SysDepartBoundaryM
map.putAll(attributes);
}
map.put("XZQMC", kmzResult.getName());
map.put("the_geom", kmzResult.getName());
map.put("the_geom", kmzResult.getWkt());
kmzList.add(map);
});
mapList = kmzList;

33
dk-modules/system/src/main/java/org/dromara/system/utils/KmzParserUtil.java

@ -109,6 +109,25 @@ public class KmzParserUtil {
});
}
/**
* 处理当前Placemark的所有坐标为每个坐标创建新的Placemark对象
*
* @param currentPlacemark 当前Placemark对象
* @param currentCoordinates 当前Placemark的所有坐标
* @param placemarks 存储所有Placemark的列表
*/
private static void processCurrentPlacemarkCoordinates(Placemark currentPlacemark, List<String> currentCoordinates, List<Placemark> placemarks) {
if (currentPlacemark != null && !currentCoordinates.isEmpty()) {
for (String coords : currentCoordinates) {
Placemark newPlacemark = new Placemark();
newPlacemark.setName(currentPlacemark.getName());
newPlacemark.setAttributes(new HashMap<>(currentPlacemark.getAttributes()));
newPlacemark.setCoordinates(coords);
placemarks.add(newPlacemark);
}
}
}
/**
* 解析KML文件内容
*
@ -120,6 +139,7 @@ public class KmzParserUtil {
Placemark currentPlacemark = null;
boolean inDescription = false;
StringBuilder descriptionContent = new StringBuilder();
List<String> currentCoordinates = new ArrayList<>();
// 添加调试日志
System.out.println("开始解析KML内容,总行数: " + lines.length);
@ -128,10 +148,10 @@ public class KmzParserUtil {
line = line.trim();
if (line.startsWith("<Placemark>")) {
if (currentPlacemark != null) {
placemarks.add(currentPlacemark);
}
// 处理当前Placemark的所有坐标
processCurrentPlacemarkCoordinates(currentPlacemark, currentCoordinates, placemarks);
currentPlacemark = new Placemark();
currentCoordinates = new ArrayList<>();
System.out.println("发现新的Placemark");
} else if (line.startsWith("<name>")) {
if (currentPlacemark != null) {
@ -155,15 +175,14 @@ public class KmzParserUtil {
} else if (line.startsWith("<coordinates>")) {
if (currentPlacemark != null) {
String coords = line.replace("<coordinates>", "").replace("</coordinates>", "").trim();
currentPlacemark.setCoordinates(coords);
currentCoordinates.add(coords);
System.out.println("解析到坐标: " + coords);
}
}
}
if (currentPlacemark != null) {
placemarks.add(currentPlacemark);
}
// 处理最后一个Placemark
processCurrentPlacemarkCoordinates(currentPlacemark, currentCoordinates, placemarks);
// 打印解析结果
System.out.println("解析完成,共找到 " + placemarks.size() + " 个地标");

Loading…
Cancel
Save