| | |
| | | public class GdalHelper { |
| | | private final static Log log = LogFactory.getLog(GdalHelper.class); |
| | | |
| | | static { |
| | | public static void init() { |
| | | // 注册所有的驱动 |
| | | gdal.AllRegister(); |
| | | |
| | |
| | | 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) { |
| | |
| | | |
| | | /** |
| | | * 读取gdb文件 |
| | | * |
| | | * @param filePath |
| | | */ |
| | | public static void readGdb(String filePath) { |
| | |
| | | } while (true); |
| | | } |
| | | } catch (Exception ex) { |
| | | ex.printStackTrace(); |
| | | log.error(ex.getMessage(), ex); |
| | | } |
| | | } |
| | | |
| | |
| | | return propertyGetter.get(feature, index); |
| | | } catch (Exception ex) { |
| | | // ex.printStackTrace() |
| | | log.error(ex.getMessage() + ex.getStackTrace() + "\n"); |
| | | log.error(ex.getMessage(), ex); |
| | | |
| | | return null; |
| | | } |