src/main/java/com/lf/server/entity/ctrl/CoordinateEntity.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/lf/server/helper/JtsHelper.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/lf/server/mapper/sys/ReportMapper.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/lf/server/service/sys/ReportService.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/resources/mapper/sys/ReportMapper.xml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
src/main/java/com/lf/server/entity/ctrl/CoordinateEntity.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,32 @@ package com.lf.server.entity.ctrl; /** * åæ å®ä½ç±» * * @author WWW * @date 2024-02-28 */ public class CoordinateEntity { public CoordinateEntity() { } private Double x; private Double y; public Double getX() { return x; } public void setX(Double x) { this.x = x; } public Double getY() { return y; } public void setY(Double y) { this.y = y; } } src/main/java/com/lf/server/helper/JtsHelper.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,44 @@ package com.lf.server.helper; import com.lf.server.entity.ctrl.CoordinateEntity; import org.locationtech.jts.geom.Coordinate; import org.locationtech.jts.geom.Geometry; import org.locationtech.jts.geom.GeometryFactory; import org.locationtech.jts.geom.MultiPoint; import org.locationtech.jts.triangulate.ConformingDelaunayTriangulationBuilder; import java.util.List; /** * JTS帮å©ç±» * * @author WWW * @date 2024-02-28 */ public class JtsHelper { /** * æ ¹æ®åæ ç¹è®¡ç®é¢ç§¯ */ public static double calcAreaByPoints(List<CoordinateEntity> ces) { Coordinate[] cs = new Coordinate[ces.size()]; for (int i = 0, c = ces.size(); i < c; i++) { cs[i] = new Coordinate(ces.get(i).getX(), ces.get(i).getY()); } GeometryFactory gf = new GeometryFactory(); MultiPoint mp = gf.createMultiPointFromCoords(cs); ConformingDelaunayTriangulationBuilder builder = new ConformingDelaunayTriangulationBuilder(); builder.setSites(mp); // å®é 为GeometryCollectionï¼ç»æçgeometryç´§å¯ç¸è¿ï¼ Geometry ts = builder.getTriangles(gf); // 以0çè·ç¦»è¿è¡ç¼å²ï¼å 为åå¤è¾¹å½¢ä¸¤ä¸¤å ±è¾¹ï¼ï¼æ¤æ¶åå°ç¹äºæé æäºå¤è¾¹å½¢ Geometry union = ts.buffer(0); // String text = union.toText() double area = union.getArea(); return Math.round(area * 100.0) / 100.0; } } src/main/java/com/lf/server/mapper/sys/ReportMapper.java
@@ -1,5 +1,6 @@ package com.lf.server.mapper.sys; import com.lf.server.entity.ctrl.CoordinateEntity; import com.lf.server.entity.ctrl.CountEntity; import com.lf.server.entity.sys.ReportEntity; import org.apache.ibatis.annotations.Mapper; @@ -138,4 +139,12 @@ * @return */ public List<CountEntity> countExplorationPoints(); /** * æ ¹æ®é¡¹ç®ç¼ç æ¥è¯¢é»åæ°æ®åæ ç¹ * * @return * @date */ public List<CoordinateEntity> selectExplorationPoints(String code); } src/main/java/com/lf/server/service/sys/ReportService.java
@@ -1,9 +1,9 @@ package com.lf.server.service.sys; import com.lf.server.entity.all.RedisCacheKey; import com.lf.server.entity.all.ResAuthEntity; import com.lf.server.entity.all.SettingData; import com.lf.server.entity.all.StaticData; import com.lf.server.entity.ctrl.CoordinateEntity; import com.lf.server.entity.ctrl.CountEntity; import com.lf.server.entity.data.DownloadEntity; import com.lf.server.entity.sys.AttachEntity; @@ -13,7 +13,6 @@ import com.lf.server.mapper.sys.ReportMapper; import com.lf.server.service.all.RedisService; import com.lf.server.service.data.DownloadService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import javax.annotation.Resource; @@ -139,12 +138,28 @@ return list; } @Override public List<CoordinateEntity> selectExplorationPoints(String code) { return reportMapper.selectExplorationPoints(StringHelper.getRightLike(code)); } /** * ç»è®¡é»åç¹é¢ç§¯ */ private void countExplorationArea(List<CountEntity> list) { for (CountEntity ce : list) { if (0 == ce.getCount()) { continue; } List<CoordinateEntity> ces = selectExplorationPoints(ce.getM3()); if (null == ces || ces.size() < 3) { continue; } double area = JtsHelper.calcAreaByPoints(ces); ce.setArea(area); } } /** src/main/resources/mapper/sys/ReportMapper.xml
@@ -122,7 +122,7 @@ <!-- æé¡¹ç®ç»è®¡é»åæ°æ® --> <select id="countExplorationPoints" resultType="com.lf.server.entity.ctrl.CountEntity"> select name "m1", name "m1", a.code "m3", (select count(*) from bs.s_explorationpoint b where dirid like a.code || '%') "count", (select coalesce(round(sum(sizes)::numeric, 3), 0) from bs.s_explorationpoint b @@ -133,4 +133,12 @@ where pid = 0 order by code; </select> <select id="selectExplorationPoints" resultType="com.lf.server.entity.ctrl.CoordinateEntity"> select ST_X(geom) "x", ST_Y(geom) "y" from bs.s_explorationpoint b <where> dirid like #{code} and geom is not null </where> </select> </mapper>