引入POM文件
<dependency>
<groupId>org.gdal</groupId>
<artifactId>gdal</artifactId>
<version>3.5.0</version>
</dependency>
代码
ogr.RegisterAll();
gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "YES");
gdal.SetConfigOption("SHAPE_ENCODING", "");
gdal.SetConfigOption("DXF_FEATURE_LIMIT_PER_BLOCK", "-1");
gdal.SetConfigOption("DXF_ENCODING", "ASCII"); //设置DXF缺省编码
String strVectorFile = "文件路径";
DataSource ds = ogr.Open(strVectorFile, 0);
if (ds == null) {
return AjaxJson.error("打开文件失败!");
}
System.out.println("打开文件成功!");
Driver dv = ogr.GetDriverByName("GeoJSON");
if (dv == null) {
return AjaxJson.error("打开驱动失败!");
}
System.out.println("打开驱动成功!");
String uuid = IdUtil.simpleUUID();
String geojsonPath = absolutePath.replace(".dxf", "");
geojsonPath = geojsonPath + "" + uuid + ".geojson";
Vector options = new Vector<String>();
options.add("COORDINATE_PRECISION=2");// 小数位
DataSource ods = dv.CopyDataSource(ds, geojsonPath);
ds.FlushCache();
ds.delete();
ods.FlushCache();
ods.delete();
dv.delete();