#!/usr/bin/python
# -*- coding:utf8 -*-
from osgeo import ogr
import gdal
import sys
import os
def ChangeToJson(vector, output):
print("Starting........")
#打开矢量图层
gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "YES")
gdal.SetConfigOption("SHAPE_ENCODING", "GBK")
shp_ds = ogr.Open(vector)
shp_lyr = shp_ds.GetLayer(0)
# 创建结果Geojson
baseName = os.path.basename(output)
out_driver = ogr.GetDriverByName('GeoJSON')
out_ds = out_driver.CreateDataSource(output)
if out_ds.GetLayer(baseName):
out_ds.DeleteLayer(baseName)
out_lyr = out_ds.CreateLayer(baseName, shp_lyr.GetSpatialRef())
out_lyr.CreateFields(shp_lyr.schema)
out_feat = ogr.Feature(out_lyr.GetLayerDefn())
#生成结果文件
for feature in shp_lyr: