管道基础大数据平台系统开发-【后端】-Server
13693261870
2023-06-12 f7b5d34d998461b78dbadf7fe03db257bc41a39f
src/main/java/com/lf/server/helper/GdbHelper.java
@@ -1,6 +1,5 @@
package com.lf.server.helper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lf.server.entity.all.BaseGeoEntity;
import com.lf.server.entity.all.StaticData;
import com.lf.server.mapper.all.BasicMapper;
@@ -108,7 +107,7 @@
    /**
     * 读取数据
     */
    public static <T> List<T> readData(Class clazz, String filePath, String layerName) {
    public static <T> List<T> readData(Class clazz, String filePath, String layerName, boolean isTransform) {
        List<T> list = new ArrayList<>();
        Driver driver = null;
@@ -128,7 +127,7 @@
            for (int i = 0, count = dataSource.GetLayerCount(); i < count; i++) {
                Layer layer = dataSource.GetLayer(i);
                if (layer.GetName().equals(layerName)) {
                    GdbHelper.readLayer(clazz, layer, list);
                    GdbHelper.readLayer(clazz, layer, list, isTransform);
                    break;
                }
@@ -146,7 +145,7 @@
    /**
     * 读取图层
     */
    public static <T> void readLayer(Class clazz, Layer layer, List<T> list) {
    public static <T> void readLayer(Class clazz, Layer layer, List<T> list, boolean isTransform) {
        try {
            Field gField = getGeomField(clazz);
@@ -163,9 +162,8 @@
                }
                T t = (T) clazz.newInstance();
                if (readFeature(t, f, map, gField)) {
                    list.add(t);
                }
                readFeature(t, f, map, gField);
                list.add(t);
            } while (true);
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
@@ -222,20 +220,18 @@
    /**
     * 读取Feature
     */
    private static <T> boolean readFeature(T t, Feature f, Map<Integer, Field> map, Field gField) {
        try {
            for (Integer i : map.keySet()) {
    private static <T> void readFeature(T t, Feature f, Map<Integer, Field> map, Field gField) {
        for (Integer i : map.keySet()) {
            try {
                Field field = map.get(i);
                setValue(t, f, field, i);
            } catch (Exception e) {
                log.error(e.getMessage(), e);
            }
        }
            if (null != gField) {
                setGeom(t, f, gField);
            }
            return true;
        } catch (Exception ex) {
            return false;
        if (null != gField) {
            setGeom(t, f, gField);
        }
    }
@@ -261,10 +257,16 @@
                field.set(t, f.GetFieldAsInteger(i));
                break;
            case "java.sql.Timestamp":
                field.set(t, getTimestamp(f, i));
                Timestamp ts = getTimestamp(f, i);
                if (null != ts) {
                    field.set(t, ts);
                }
                break;
            case "java.time.LocalDate":
                field.set(t, getLocalDate(f, i));
                LocalDate ld = getLocalDate(f, i);
                if (null != ld) {
                    field.set(t, ld);
                }
                break;
            default:
                field.set(t, f.GetFieldAsString(i));
@@ -286,28 +288,33 @@
     * wkbNone = 100,
     * wkbLinearRing = 101
     */
    private static <T> void setGeom(T t, Feature f, Field gField) throws Exception {
        String geo = "null";
        if (null != f.GetGeometryRef()) {
            String wkt = f.GetGeometryRef().ExportToWkt();
            // noinspection AlibabaRemoveCommentedCode
            switch (f.GetGeometryRef().GetGeometryType()) {
                //case 1:
                //    wkt = wkt.replace("POINT", "MULTIPOINT");
                //    break;
                case 2:
    private static <T> void setGeom(T t, Feature f, Field gField) {
        try {
            String geo = "null";
            if (null != f.GetGeometryRef()) {
                String wkt = f.GetGeometryRef().ExportToWkt();
                // f.GetGeometryRef().GetGeometryType()
                if (wkt.contains(StaticData.LINESTRING) && !wkt.contains(StaticData.MULTILINESTRING)) {
                    wkt = wkt.replace("LINESTRING (", "MULTILINESTRING ((") + ")";
                    break;
                case 3:
                }
                if (wkt.contains(StaticData.POLYGON) && !wkt.contains(StaticData.MULTIPOLYGON)) {
                    wkt = wkt.replace("POLYGON (", "MULTIPOLYGON ((") + ")";
                    break;
                default:
                    break;
            }
            geo = String.format("ST_GeomFromText('%s')", wkt);
        }
                }
                wkt = wkt.replace(" 0,", ",").replace(" 0)", ")");
                if (wkt.contains(StaticData.MULTICURVE)) {
                    wkt = wkt.replace("MULTICURVE (", "MULTILINESTRING (").replace("CIRCULARSTRING ", "");
                    if (wkt.contains(StaticData.COMPOUNDCURVE)) {
                        wkt = wkt.replace("COMPOUNDCURVE (", "").replace(")))", "))");
                    }
                }
        gField.set(t, geo);
                geo = String.format("ST_GeomFromText('%s')", wkt);
            }
            gField.set(t, geo);
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
        }
    }
    /**
@@ -327,6 +334,10 @@
        float fSecond = pfSecond[0];
        int s = (int) fSecond;
        int ns = (int) (1000000000 * fSecond - s);
        if (pnYear[0] > StaticData.I2050 || pnMonth[0] > StaticData.I12 || pnDay[0] > StaticData.I31 || pnHour[0] > StaticData.I24 || pnMinute[0] > StaticData.I60) {
            return null;
        }
        LocalDateTime localDateTime = LocalDateTime.of(
                LocalDate.of(pnYear[0], pnMonth[0], pnDay[0]),
@@ -349,6 +360,9 @@
        int[] pnTzFlag = new int[1];
        f.GetFieldAsDateTime(index, pnYear, pnMonth, pnDay, pnHour, pnMinute, pfSecond, pnTzFlag);
        if (pnYear[0] > StaticData.I2050 || pnMonth[0] > StaticData.I12 || pnDay[0] > StaticData.I31) {
            return null;
        }
        return LocalDate.of(pnYear[0], pnMonth[0], pnDay[0]);
    }
@@ -390,8 +404,7 @@
                    }
                    List<Field> fields = new ArrayList<>();
                    // fields.add(getGeomField(clazz))
                    getFields(clazz, fields);
                    getFields(clazz, fields, StaticData.GDB_EXCLUDE_FIELDS);
                    addLayerField(layer, fields);
                    setLayerData(layer, fields, map.get(key));
@@ -433,7 +446,7 @@
        SpatialReference sr = new SpatialReference();
        sr.ImportFromEPSG(null == srid ? 4490 : srid);
        return dataSource.CreateLayer(tab, sr, getGeomType(geomType), null);
        return dataSource.CreateLayer(tab.replace(".", "_"), sr, getGeomType(geomType), null);
    }
    /**
@@ -465,11 +478,11 @@
    /**
     * 获取字段
     */
    public static void getFields(Class clazz, List<Field> list) {
    public static void getFields(Class clazz, List<Field> list, List<String> excludeFields) {
        try {
            Field[] fields = clazz.getDeclaredFields();
            for (Field f : fields) {
                if (StaticData.GDB_EXCLUDE_FIELDS.contains(f.getName())) {
                if (excludeFields.contains(f.getName())) {
                    continue;
                }
@@ -478,7 +491,7 @@
            }
            if (!StaticData.OBJECT.equals(clazz.getSuperclass().getName())) {
                getFields(clazz.getSuperclass(), list);
                getFields(clazz.getSuperclass(), list, excludeFields);
            }
        } catch (Exception ex) {
            //