管道基础大数据平台系统开发-【后端】-Server
13693261870
2024-02-29 e9509391ffd3e90c64872836ad64d112a89a26a4
计算多边形面积
已修改2个文件
46 ■■■■■ 文件已修改
src/main/java/com/lf/server/service/sys/ReportService.java 44 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/application.yml 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/service/sys/ReportService.java
@@ -13,7 +13,11 @@
import com.lf.server.mapper.sys.ReportMapper;
import com.lf.server.service.all.RedisService;
import com.lf.server.service.data.DownloadService;
import com.lf.server.service.data.PublishService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.locationtech.jts.geom.Coordinate;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@@ -28,6 +32,9 @@
 */
@Service
public class ReportService implements ReportMapper {
    @Value("${sys.turfServer}")
    private String turfServer;
    @Resource
    ReportMapper reportMapper;
@@ -42,6 +49,8 @@
    @Resource
    RedisService redisService;
    private final static Log log = LogFactory.getLog(ReportService.class);
    @Override
    public Integer selectCount(String name, String code) {
@@ -153,26 +162,31 @@
                continue;
            }
            List<CoordinateEntity> ces = selectExplorationPoints(ce.getM3());
            if (null == ces || ces.size() < 3) {
                continue;
            }
            StringBuilder sb = new StringBuilder();
            sb.append("[");
            for (CoordinateEntity e : ces) {
                sb.append(e.getX() + "," + e.getY() + ",");
            }
            sb.replace(sb.length() - 1, sb.length(), "]");
            // double area = JtsHelper.calcAreaByPoints(ces)
            double area = callJsFn(sb.toString());
            double area = calcPolygonArea(ce.getM3());
            ce.setArea(area);
        }
    }
    /**
     * 调用JS方法
     * 计算多边形面积
     */
    private double calcPolygonArea(String code) {
        try {
            String url = turfServer + "/Call/CalcArea?code=" + code;
            String str = RestHelper.get(url);
            if (StringHelper.isEmpty(str)) {
                return 0d;
            }
            return Double.parseDouble(str);
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
            return 0d;
        }
    }
    /**
     * 调用JS方法 *
     */
    private double callJsFn(String str) {
        String staticPath = PathHelper.getStaticPath();
src/main/resources/application.yml
@@ -138,6 +138,8 @@
  # 出图服务
  exportServer: http://127.0.0.1/ExportMap
  #exportServer: http://103.85.165.99:8050/ExportMap
  # Turf服务
  turfServer: http://127.0.0.1/Turf
  # Gdal驱动目录
  gdal_path: E:\terrait\TianJin\Zip\release-1928-x64-dev\release-1928-x64\bin
  # 瓦片地址