gdal将shp数据转换为geojson数据

<pre name="code" class="java">package VetToGeo;
//下载gdal
//将所有的dll文件复制到jdk的安装路径下,比如“C:\Program Files (x86)\Java\jdk1.7.0_17\jre\bin”
//将JDAL.jar文件添加到Java项目的lib引用里

import org.gdal.gdal.*;
import org.gdal.ogr.DataSource;
import org.gdal.ogr.Driver;
import org.gdal.ogr.*;

public class VectorToGeojson {
	public static void main(String[] args){
		//注册所有驱动
		ogr.RegisterAll();
		//为了支持中文路径,请添加下面这句代码
		gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "YES");
		//为了使属性标志段支持中文,添加下面这句代码
		gdal.SetConfigOption("SHAPE_ENCODING", "");
		
		//使用ogr库打开shape文件
		DataSource ds = ogr.Open("C:\\Users\\Administrator\\Documents\\shpData\\中国地图ArcGIS练习数据\\国界线.shp",0);
		if(ds == null){
			System.out.println("DataSource is null");
			return;
		}
		Driver dv = ogr.GetDriverByName("GeoJSON");
		if(dv == null){
                        System.out.println("DataSource is null");
                        return;
		}
		dv.CopyDataSource(ds, "C:\\Users\\Administrator\\Documents\\shpData\\国界线.geojson");
		System.out.println("well done!!");
	}
}
            
转载自:https://blog.csdn.net/qq_27268757/article/details/51711162

You may also like...