转:http://www.jianshu.com/p/6d9a65839f7f
java-gdal安装配置
下载地址:https://yunpan.cn/cB2tdzVMQ3nLB 访问密码 d03f
1 将java-gdal文件夹中所有的dll复制到Java\jre7\bin文件夹中。
2 将java-gdal文件夹中的gdal.jar在java工程中引用即可完成配置。
package GIS;
import org.gdal.*;
import org.gdal.ogr.DataSource;
import org.gdal.ogr.Driver;
import org.gdal.ogr.ogr;
import org.gdal.gdal.*;
public class Test {
public static void main(String[] args) {
// 注册所有的驱动
ogr.RegisterAll();
// 为了支持中文路径,请添加下面这句代码
gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8","YES");
// 为了使属性表字段支持中文,请添加下面这句
gdal.SetConfigOption("SHAPE_ENCODING","");
String strVectorFile = "D:\\data\\fibercable.shp";
//打开数据
DataSource ds = ogr.Open(strVectorFile,0);
if (ds == null)
{
System.out.println("打开文件失败!" );
return;
}
System.out.println("打开文件成功!" );
Driver dv = ogr.GetDriverByName("GeoJSON");
if (dv == null)
{
System.out.println("打开驱动失败!" );
return;
}
System.out.println("打开驱动成功!" );
dv.CopyDataSource(ds, "D:\\data\\fibercable.geojson");
System.out.println("转换成功!" );
}
}