简要说明
在java开发中,利用gdal解析gdb,获取gdb中各个图层的名称
maven依赖
<!--需要安装完gdal后,本地install gdal包才能使用 -->
<!--gdal安装可参考 https://blog.csdn.net/qq_41613913/article/details/135743562 -->
<dependency>
<groupId>org.gdal</groupId>
<artifactId>gdal</artifactId>
<version>3.7.3</version>
</dependency>
样例代码
public static List<String> getGdbLayerNames(String dataPath) {
//获取OpenFileGDB驱动,gdal在3.6之后,OpenFileGDB除了读还能写
//亦可通过 gdal.open 直接打开 gdb
Driver ogrDriver = ogr.GetDriverByName("OpenFileGDB");
if(Objects.isNull(ogrDriver )) {
System.out.println("驱动不可用!");
}
DataSource dataSource = ogrDriver.Open(dataPath, 0);
if(Objects.isNull(dataSource)) {
System.out.println("文件打开失败!");
}
int layerCount = dataSource.GetLayerCount();
//图层数组
List<String> layerNames = new ArrayList<>(layerCount);
for (int i = 0; i < layerCount; i++) {
String layerName = dataSource.GetLayer(i).GetName();
layerNames.add(layerName);
}
return layerNames;
}