From f3104f14213028277c883e19301b820ae724bd70 Mon Sep 17 00:00:00 2001
From: linwei <872216696@qq.com>
Date: Fri, 05 Jun 2026 10:18:08 +0800
Subject: [PATCH] feat(utils): 添加几何数据处理和区域编码转换功能
---
drone-common/src/main/java/org/sxkj/common/utils/GeomUtils.java | 35 +++++++++++++++++++++++++++++++++++
1 files changed, 35 insertions(+), 0 deletions(-)
diff --git a/drone-common/src/main/java/org/sxkj/common/utils/GeomUtils.java b/drone-common/src/main/java/org/sxkj/common/utils/GeomUtils.java
index dd075ff..6cb200e 100644
--- a/drone-common/src/main/java/org/sxkj/common/utils/GeomUtils.java
+++ b/drone-common/src/main/java/org/sxkj/common/utils/GeomUtils.java
@@ -2,8 +2,10 @@
import org.apache.commons.lang3.StringUtils;
import org.geotools.geometry.jts.JTSFactoryFinder;
+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.io.ParseException;
import org.locationtech.jts.io.WKTReader;
@@ -50,4 +52,37 @@
return null;
}
}
+
+ /**
+ * 从几何数据中提取中心点坐标
+ *
+ * @param geom WKT格式的几何数据
+ * @return 中心点坐标数组,格式为 [经度, 纬度],如果提取失败返回null
+ */
+ public static double[] extractCenterPoint(String geom) {
+ if (StringUtils.isBlank(geom)) {
+ return null;
+ }
+
+ try {
+ // 解析WKT字符串
+ Geometry geometry = wktReader.read(geom);
+
+ // 获取几何对象的中心点
+ Point centroid = geometry.getCentroid();
+ if (centroid == null) {
+ return null;
+ }
+
+ Coordinate coordinate = centroid.getCoordinate();
+ if (coordinate == null) {
+ return null;
+ }
+
+ // 返回 [经度, 纬度]
+ return new double[]{coordinate.x, coordinate.y};
+ } catch (ParseException e) {
+ return null;
+ }
+ }
}
--
Gitblit v1.9.3