1
13693261870
2024-11-06 568696691efa96f44f1e88304459f612acc7e6e7
1
已修改2个文件
51 ■■■■■ 文件已修改
src/main/java/com/se/simu/helper/GdalHelper.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/se/simu/service/WaterService.java 47 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/se/simu/helper/GdalHelper.java
@@ -239,13 +239,13 @@
    /**
     * WGS84转换为目标坐标
     */
    public static int fromWgs84(SpatialReference sr, Geometry point) {
    public static int fromWgs84(SpatialReference sr, Geometry g) {
        // 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 point.TransformTo(sr);
        return g.TransformTo(sr);
    }
}
src/main/java/com/se/simu/service/WaterService.java
@@ -6,12 +6,14 @@
import com.se.simu.domain.po.DataPo;
import com.se.simu.domain.po.SimuPo;
import com.se.simu.domain.vo.*;
import com.se.simu.domain.vo.Layer;
import com.se.simu.helper.GdalHelper;
import com.se.simu.helper.StringHelper;
import lombok.extern.slf4j.Slf4j;
import org.gdal.gdal.Dataset;
import org.gdal.gdal.gdal;
import org.gdal.gdalconst.gdalconst;
import org.gdal.ogr.*;
import org.gdal.osr.SpatialReference;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
@@ -113,6 +115,7 @@
    public Double getWaterHeight(SimuPo simu, double x, double y, Long timestamp) {
        String filePath = config.getOutPath() + File.separator + simu.getServiceName() + File.separator + "waters"
                + File.separator + timestamp + File.separator + "water.tif";
        if (!FileUtil.exist(filePath)) return null;
        Dataset ds = null;
        try {
@@ -172,9 +175,51 @@
    }
    public Double getWaterArea(SimuPo simu, double x, double y, Long timestamp) {
        return null;
        String filePath = config.getOutPath() + File.separator + simu.getServiceName() + File.separator + "waters"
                + File.separator + timestamp + File.separator + "water.geojson";
        if (!FileUtil.exist(filePath)) return null;
        Driver driver = null;
        DataSource dataSource = null;
        org.gdal.ogr.Layer layer = null;
        try {
            driver = ogr.GetDriverByName("GeoJSON");
            if (null == driver) return null;
            DataSource ds = driver.Open(filePath);
            if (null == ds) return null;
            layer = ds.GetLayer(0);
            double[] xy = GdalHelper.fromWgs84(layer.GetSpatialRef(), x, y);
            Geometry p = new Geometry(ogr.wkbPoint);
            p.AddPoint_2D(xy[0], xy[1]);
            p.AssignSpatialReference(layer.GetSpatialRef());
            for (long i = 0, d = layer.GetFeatureCount(); i < d; i++) {
                Feature f = layer.GetFeature(i);
                if (f.GetGeometryRef().Intersects(p)) {
                    /*f.GetFieldAsDouble("val");
                    Geometry g = f.GetGeometryRef();
                    GdalHelper.fromWgs84(layer.GetSpatialRef(), g);
                    Double area= g.GetArea();*/
                    return f.GetGeometryRef().Area();
                }
            }
            return null;
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
            return null;
        } finally {
            GdalHelper.delete(layer, dataSource, driver);
        }
    }
    /**
     * 根据seid查询建筑物涉水深度
     */
    public List<BuildingDepthVo> getBuildingDepthBySeid(String serviceName, String seid) {
        List<BuildingDepthVo> list = readBuildingJson(serviceName);
        if (CollectionUtils.isEmpty(list)) return null;