月球大数据地理空间分析展示平台-【后端】-月球后台服务
1
13693261870
2024-11-17 796b44ea813a1133beae4f3a67f1c0263510c0c7
src/main/java/com/moon/server/service/data/ReadRasterService.java
@@ -19,18 +19,11 @@
import java.util.ArrayList;
import java.util.List;
/**
 * 读取栅格服务
 * @author WWW
 * @date 2023-08-25
 */
@Service
@SuppressWarnings("ALL")
public class ReadRasterService {
    private final static Log log = LogFactory.getLog(ReadRasterService.class);
    /**
     * 读取栅格信息
     */
    public void readRasterInfo(MetaFileEntity mf, String file) {
        Dataset ds = null;
        try {
@@ -45,33 +38,23 @@
            }
            SpatialReference sr = ds.GetSpatialRef();
            // 坐标系统
            mf.setCoorSys(sr.GetName());
            if (StaticData.MOON200.equals(mf.getCoorSys())) {
                // EPSG编码
                mf.setEpsg("ESRI:" + StaticData.I104903);
            } else {
                // EPSG编码:PROJCS、GEOGCS、GEOGCS|UNIT 或 NULL
                String code = sr.GetAuthorityCode(null);
                mf.setEpsg(StringHelper.isEmpty(code) ? null : "EPSG:" + code);
            }
            // 行列数
            mf.setGridsize(String.format("%d,%d", ds.getRasterXSize(), ds.getRasterYSize()));
            // 波段数
            mf.setBands(String.valueOf(ds.getRasterCount()));
            // 数据类型
            int dataType = ds.GetRasterBand(1).GetRasterDataType();
            mf.setBandType(getDataType(dataType));
            // 数据颜色表
            ColorTable colorTable = ds.GetRasterBand(1).GetRasterColorTable();
            mf.setCt(null == colorTable ? null : colorTable.toString());
            // 高程基准
            mf.sethDatum(null);
            // 设置最值
            setMinAndMax(ds, mf);
            // 分辨率
            double[] tr = new double[6];
            ds.GetGeoTransform(tr);
            mf.setResolution(String.format("%f,%f", tr[1], Math.abs(tr[5])));
@@ -86,7 +69,6 @@
            double xmax = maxPoint.GetX(0);
            double ymax = maxPoint.GetY(0);
            // 四至范围
            String geom = String.format("ST_GeomFromText('POLYGON ((%f %f,%f %f,%f %f,%f %f,%f %f))')", xmin, ymax, xmax, ymax, xmax, ymin, xmin, ymin, xmin, ymax);
            mf.setGeom(geom);
        } catch (Exception ex) {
@@ -98,9 +80,6 @@
        }
    }
    /**
     * 获取数据类型
     */
    private String getDataType(int dataType) {
        if (dataType == gdalconst.GDT_Byte) {
            return "GDT_Byte";
@@ -139,9 +118,6 @@
        return null;
    }
    /**
     * 获取Dataset的最小点
     */
    private Geometry getMinPoint(Dataset ds) {
        double[] transform = new double[6];
        ds.GetGeoTransform(transform);
@@ -155,19 +131,7 @@
        return transform(ds, point);
    }
    /**
     * 获取Dataset的最大点
     */
    private Geometry getMaxPoint(Dataset ds) {
        /*
         * transform[0] 左上角x坐标
         * transform[1] 东西方向分辨率
         * transform[2] 旋转角度, 0表示图像 "北方朝上"
         *
         * transform[3] 左上角y坐标
         * transform[4] 旋转角度, 0表示图像 "北方朝上"
         * transform[5] 南北方向分辨率
         */
        double[] transform = new double[6];
        ds.GetGeoTransform(transform);
@@ -180,9 +144,6 @@
        return transform(ds, point);
    }
    /**
     * 坐标转换
     */
    private Geometry transform(Dataset ds, Geometry point) {
        point.AssignSpatialReference(ds.GetSpatialRef());
        if (ds.GetSpatialRef().IsGeographic() > 0) {
@@ -200,10 +161,6 @@
        return point;
    }
    /**
     * 设置最值
     * GDALRasterBand::GetHistogram ​​统计直方图
     */
    private void setMinAndMax(Dataset ds, MetaFileEntity mf) {
        List<Double> minList = new ArrayList<>();
        List<Double> maxList = new ArrayList<>();