From e9509391ffd3e90c64872836ad64d112a89a26a4 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期四, 29 二月 2024 17:01:33 +0800 Subject: [PATCH] 计算多边形面积 --- src/main/java/com/lf/server/service/sys/ReportService.java | 44 +++++++++++++++++++++++++++++--------------- src/main/resources/application.yml | 2 ++ 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/lf/server/service/sys/ReportService.java b/src/main/java/com/lf/server/service/sys/ReportService.java index cf96ef6..bfa119e 100644 --- a/src/main/java/com/lf/server/service/sys/ReportService.java +++ b/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(); diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 3b0e677..d78e38c 100644 --- a/src/main/resources/application.yml +++ b/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 # 鐡︾墖鍦板潃 -- Gitblit v1.9.3