管道基础大数据平台系统开发-【后端】-Server
12
13693261870
2022-11-21 07a68b8d93aa059968a9709f2c81e6625338032c
src/main/java/com/lf/server/helper/GdalHelper.java
@@ -28,7 +28,7 @@
public class GdalHelper {
    private final static Log log = LogFactory.getLog(GdalHelper.class);
    static {
    public static void init() {
        // 注册所有的驱动
        gdal.AllRegister();
@@ -77,29 +77,9 @@
        gdal.GDALDestroyDriverManager();
    }
    private static void writeShp(String filePath) {
        try {
            org.gdal.ogr.Driver driver = ogr.GetDriverByName("ESRI shapefile");
            if (driver == null) {
                System.out.println(" ESRI shapefile驱动不可用!\n");
                System.out.println("fail");
            }
            // Open()的第二个参数默认为0,是以只读方式打开文件;1是读写方式打开
            DataSource dSource = driver.Open(filePath, 0);
            Layer layer = dSource.GetLayerByIndex(0);
            FieldDefn fieldDefn = new FieldDefn("name", ogr.OFTString);
            fieldDefn.SetWidth(50);
            layer.CreateField(fieldDefn, 1);
            layer.DeleteField(layer.FindFieldIndex("name", 1));
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    /**
     * 读取shp文件
     *
     * @param filePath
     */
    public static void readShp(String filePath) {
@@ -223,6 +203,7 @@
    /**
     * 读取gdb文件
     *
     * @param filePath
     */
    public static void readGdb(String filePath) {
@@ -257,7 +238,7 @@
                } while (true);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            log.error(ex.getMessage(), ex);
        }
    }
@@ -275,7 +256,7 @@
            return propertyGetter.get(feature, index);
        } catch (Exception ex) {
            // ex.printStackTrace()
            log.error(ex.getMessage() + ex.getStackTrace() + "\n");
            log.error(ex.getMessage(), ex);
            return null;
        }