13693261870
2024-09-29 ca8d3861b4e9a28beead77e81ecfa23d15d5eb5f
获取CPU核心数
已修改3个文件
53 ■■■■■ 文件已修改
src/main/java/com/se/simu/domain/dto/ConfigDto.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/se/simu/helper/ShpHelper.java 44 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/se/simu/helper/WebHelper.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/se/simu/domain/dto/ConfigDto.java
@@ -1,6 +1,7 @@
package com.se.simu.domain.dto;
import com.se.simu.config.PropertiesConfig;
import com.se.simu.helper.WebHelper;
import java.text.SimpleDateFormat;
import java.util.Calendar;
@@ -97,6 +98,7 @@
        this.drainage_outfile = dirName + ".h5";
        this.sww_outfile = dirName + ".sww";
        this.flow_units = config.getFlowUnits();
        this.threads = WebHelper.getCpuCores();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
src/main/java/com/se/simu/helper/ShpHelper.java
@@ -6,8 +6,11 @@
import com.se.simu.domain.dto.GeField;
import com.se.simu.domain.dto.GeLayer;
import lombok.extern.slf4j.Slf4j;
import org.gdal.gdal.Dataset;
import org.gdal.ogr.*;
import org.gdal.osr.CoordinateTransformation;
import org.gdal.osr.SpatialReference;
import org.gdal.osr.osr;
import java.sql.Timestamp;
import java.time.LocalDateTime;
@@ -64,7 +67,15 @@
    }
    private static Geometry createPolygon(SpatialReference sr, Double minx, Double miny, Double maxx, Double maxy) {
        //
        String epsg = sr.GetAuthorityCode(null);
        if (!("4326".equals(epsg) || "4490".equals(epsg))) {
            double[] dmin = fromWgs84(sr, minx, miny);
            double[] dmax = fromWgs84(sr, maxx, maxy);
            minx = dmin[0];
            miny = dmin[1];
            maxx = dmax[0];
            maxy = dmax[1];
        }
        Geometry ring = new Geometry(ogr.wkbLinearRing);
        ring.AddPoint_2D(minx, maxy);
@@ -232,4 +243,35 @@
                return ogr.OFTString;
        }
    }
    private String getEpsg(SpatialReference sr) {
        return sr.GetAuthorityCode(null);
    }
    /**
     * 转换为WGS84坐标
     */
    public static Geometry toWgs84(SpatialReference sr, double x, double y) {
        Geometry point = new Geometry(ogr.wkbPoint);
        point.AssignSpatialReference(sr);
        point.AddPoint(x, y);
        point.TransformTo(GdalHelper.SR4326);
        //point.SwapXY();
        return point;
    }
    /**
     * WGS84转换为目标坐标
     */
    public static double[] fromWgs84(SpatialReference sr, double x, double y) {
        // https://blog.csdn.net/weixin_34910922/article/details/129208661
        CoordinateTransformation ct = new CoordinateTransformation(GdalHelper.SR4326, sr);
        if (sr.IsProjected() != 1) {
            sr.SetAxisMappingStrategy(osr.OAMS_TRADITIONAL_GIS_ORDER);
        }
        return ct.TransformPoint(x, y);
    }
}
src/main/java/com/se/simu/helper/WebHelper.java
@@ -38,6 +38,13 @@
    }
    /**
     * 获取CPU核心数
     */
    public static int getCpuCores() {
        return Runtime.getRuntime().availableProcessors();
    }
    /**
     * 格式化日期
     */
    public final static SimpleDateFormat YMDHMS = new SimpleDateFormat("yyyyMMddHHmmss");