管道基础大数据平台系统开发-【后端】-Server
13693261870
2024-02-28 7185f65d9e4087fef18567365ea621845fe2659e
使用JTS计算面积
已添加2个文件
已修改3个文件
114 ■■■■■ 文件已修改
src/main/java/com/lf/server/entity/ctrl/CoordinateEntity.java 32 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/helper/JtsHelper.java 44 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/mapper/sys/ReportMapper.java 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/service/sys/ReportService.java 19 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/sys/ReportMapper.xml 10 ●●●●● 补丁 | 查看 | 原始文档 | 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>