月球大数据地理空间分析展示平台-【后端】-月球后台服务
1
13693261870
2024-11-13 024e90554d19c2342f27a26f91bbea378f84da82
src/main/java/com/moon/server/helper/GdbHelper.java
@@ -20,16 +20,10 @@
import java.time.LocalTime;
import java.util.*;
/**
 * GDB帮助类
 * @author WWW
 */
@SuppressWarnings("ALL")
public class GdbHelper {
    private final static Log log = LogFactory.getLog(GdbHelper.class);
    /**
     * 销毁资源
     */
    public static void delete(Layer layer) {
        try {
            if (null != layer) {
@@ -40,9 +34,6 @@
        }
    }
    /**
     * 销毁资源
     */
    public static void delete(DataSource dataSource, Driver driver) {
        try {
            if (null != dataSource) {
@@ -61,17 +52,11 @@
        }
    }
    /**
     * 销毁资源
     */
    public static void delete(Layer layer, DataSource dataSource, Driver driver) {
        delete(layer);
        delete(dataSource, driver);
    }
    /**
     * 获取表名
     */
    public static List<String> getTabNames(String filePath) {
        List<String> list = new ArrayList<>();
@@ -106,9 +91,6 @@
        return list;
    }
    /**
     * 读取数据
     */
    public static <T> List<T> readData(Class clazz, String filePath, String layerName, boolean isTransform) {
        List<T> list = new ArrayList<>();
@@ -144,9 +126,6 @@
        return list;
    }
    /**
     * 读取图层
     */
    public static <T> void readLayer(Class clazz, Layer layer, List<T> list, boolean isTransform) {
        try {
            Field gField = getGeomField(clazz);
@@ -176,9 +155,6 @@
        }
    }
    /**
     * 获取坐标转换器
     */
    private static CoordinateTransformation getCoordinateTransformation(Layer layer, boolean isTransform) {
        if (!isTransform) {
            return null;
@@ -190,7 +166,7 @@
        }
        int epsgId = Integer.parseInt(epsg);
        if (StaticData.I4326 == epsgId || StaticData.I4490 == epsgId) {
        if (StaticData.I4326 == epsgId || StaticData.I4490 == epsgId || StaticData.I104903 == epsgId) {
            return null;
        }
@@ -203,9 +179,6 @@
        return CoordinateTransformation.CreateCoordinateTransformation(layer.GetSpatialRef(), srTarget);
    }
    /**
     * 获取 geom 字段
     */
    private static Field getGeomField(Class clazz) {
        try {
            Field gField = clazz.getSuperclass().getDeclaredField("geom");
@@ -217,9 +190,6 @@
        }
    }
    /**
     * 获取字段映射
     */
    private static void getFieldMapper(Class clazz, Layer layer, Map<Integer, Field> map) {
        try {
            FeatureDefn fd = layer.GetLayerDefn();
@@ -247,9 +217,6 @@
        }
    }
    /**
     * 读取Feature
     */
    private static <T> void readFeature(T t, Feature f, Map<Integer, Field> map, Field gField, CoordinateTransformation ct) {
        for (Integer i : map.keySet()) {
            try {
@@ -265,9 +232,6 @@
        }
    }
    /**
     * 设置值
     */
    public static <T> void setValue(T t, Feature f, Field field, Integer i) throws Exception {
        switch (field.getType().getName()) {
            case "java.math.BigDecimal":
@@ -304,20 +268,6 @@
        }
    }
    /**
     * 设置 geom 字段值
     * <p>
     * wkbUnknown = 0,
     * wkbPoint = 1,
     * wkbLineString = 2,
     * wkbPolygon = 3,
     * wkbMultiPoint = 4,
     * wkbMultiLineString = 5,
     * wkbMultiPolygon = 6,
     * wkbGeometryCollection = 7,
     * wkbNone = 100,
     * wkbLinearRing = 101
     */
    private static <T> void setGeom(T t, Field gField, Geometry geometry, CoordinateTransformation ct) {
        try {
            if (null == geometry) {
@@ -349,9 +299,6 @@
        }
    }
    /**
     * 获取 Timestamp
     */
    public static Timestamp getTimestamp(Feature f, int index) {
        int[] pnYear = new int[1];
        int[] pnMonth = new int[1];
@@ -379,9 +326,6 @@
        return Timestamp.valueOf(localDateTime);
    }
    /**
     * 获取 LocalDate
     */
    public static LocalDate getLocalDate(Feature f, int index) {
        int[] pnYear = new int[1];
        int[] pnMonth = new int[1];
@@ -399,9 +343,6 @@
        return LocalDate.of(pnYear[0], pnMonth[0], pnDay[0]);
    }
    /**
     * 创建GDB
     */
    public static void createGdb(String filePath,  Map<String, List<?>> map) throws Exception {
        Driver driver = null;
        DataSource dataSource = null;
@@ -457,9 +398,6 @@
        }
    }
    /**
     * 创建图层
     */
    private static Layer createLayer(DataSource dataSource, BasicMapper baseMapper ) {
        String tab = BaseQueryService.getTabName(baseMapper);
        if (StringHelper.isNull(tab)) {
@@ -475,15 +413,18 @@
            srid = geomMapper.selectSrid(tab);
        }
        SpatialReference sr = new SpatialReference();
        sr.ImportFromEPSG(null == srid ? 4490 : srid);
        // SpatialReference sr = new SpatialReference(); sr.ImportFromEPSG(null == srid || 0 == srid ? StaticData.I104903 : srid)
        SpatialReference sr;
        if (null == srid || StaticData.DEFAULT_EPSG.contains(srid)) {
            sr = new SpatialReference(StaticData.MOON_2000_WKT);
        } else {
            sr = new SpatialReference();
            sr.ImportFromEPSG(srid);
        }
        return dataSource.CreateLayer(tab.replace(".", "_"), sr, getGeomType(geomType), null);
    }
    /**
     * 获取Geom类别
     */
    private static Integer getGeomType(String geomType) {
        if (StringHelper.isEmpty(geomType)) {
            return ogr.wkbPoint;
@@ -507,9 +448,6 @@
        }
    }
    /**
     * 获取字段
     */
    public static void getFields(Class clazz, List<Field> list, List<String> excludeFields) {
        try {
            Field[] fields = clazz.getDeclaredFields();
@@ -530,9 +468,6 @@
        }
    }
    /**
     * 添加图层字段
     */
    public static void addLayerField(Layer layer, List<Field> list) {
        for (int i = 0, c = list.size(); i < c; i++) {
            Field f = list.get(i);
@@ -544,9 +479,6 @@
        }
    }
    /**
     * 获取字段类型
     */
    private static Integer getFieldType(Field f) {
        switch (f.getType().getName()) {
            case "java.math.BigDecimal":
@@ -568,9 +500,6 @@
        }
    }
    /**
     * 设置图层数据
     */
    private static <T> void setLayerData(Layer layer,  List<Field> fields, List<T> list) throws Exception {
        for (T t : list) {
            Feature f = new Feature(layer.GetLayerDefn());
@@ -588,9 +517,6 @@
        }
    }
    /**
     * 设置要素的数据
     */
    public static <T> void setFeatureData(Feature f, List<Field> fields, T t) throws Exception {
        for (int i = 0, c = fields.size(); i < c; i++) {
            Field field = fields.get(i);
@@ -635,9 +561,6 @@
        }
    }
    /**
     * 设置Timestamp
     */
    private static void setTimestamp(Feature f, int i, Timestamp time) {
        if (null == time) {
            return;
@@ -647,9 +570,6 @@
        f.SetField(i, local.getYear(), local.getMonthValue(), local.getDayOfMonth(), local.getHour(), local.getMinute(), local.getSecond(), 8);
    }
    /**
     * 设置LocalDate
     */
    private static void setLocalDate(Feature f, int i, LocalDate local) {
        if (null == local) {
            return;