2016-07-20 32 views
1
 Gdal.AllRegister(); 
     //为了支持中文路径,请添加下面这句代码 
     OSGeo.GDAL.Gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "NO"); 
     //为了使属性表字段支持中文,请添加下面这句 
     OSGeo.GDAL.Gdal.SetConfigOption("SHAPE_ENCODING", ""); 
     Ogr.RegisterAll(); 
     OSGeo.OGR.Driver outDriver = Ogr.GetDriverByName("GeoJSON"); 
     OSGeo.OGR.DataSource outDataSource = outDriver.CreateDataSource("aaa.geojson",null); 
     DataSource pnn3 = Ogr.Open("MSSQL:server=192.168.1.9,1433;database=KS_DataBase;UId=sa;PWD=sa", 0); 

     OSGeo.OGR.Layer layer = pnn3.ExecuteSQL("select * from KS_HXStation", null, ""); 
     OSGeo.OGR.Feature f; 
     layer.ResetReading(); 

Ich weiß nicht, wie man die mssql räumliche Datenübertragung Geojson ist.C# gdal lesen mssql spatial zu geojson

Antwort

0
var driver = Ogr.GetDriverByName("GeoJSON"); 
var trgPath = ""; //export geojson destination path 
var trgDataset = driver.CreateDataSource(trgPath, null); 
trgDataset.CopyLayer(layer, layer.GetName(), null); 
trgDataset.Dispose(); 
+0

Dank ist meine qq 75.762.476, was Sie? – dlsyaim

1
string sqlConn = "MSSQL:server=[IP];database=[DB];uid=[id]; pwd=[pwd];tables=[tablName];"; 
string filePath = [email protected]"D:\shp\shpFile.shp"; 

// 註冊所有的驅動 
Ogr.RegisterAll(); 

// in order to support chinese path 
//OSGeo.GDAL.Gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "NO"); 

// in order to support chinese attribute (CP950 for big5, CP936 for GB) 
// reference: http://blog.xuite.net/ebeaoi/beast/9836928-%E7%B7%A8%E7%A2%BC%E5%95%8F%E9%A1%8C--charset%E5%8F%8Acodepage 
Gdal.SetConfigOption("SHAPE_ENCODING", "CP950 | CP936"); 

// auto dispose DataSource 
using (DataSource ds = Ogr.Open(sqlConn, 0)) 
{ 
    // load first layer 
    Layer oLayer = ds.GetLayerByIndex(0); 

    // output file type 
    var outDriver = Ogr.GetDriverByName("ESRI Shapefile"); 

    // auto dispose DataSource 
    using (var targetDataSet = outDriver.CreateDataSource(filePath, null)) 
    { 
     targetDataSet.CopyLayer(oLayer, oLayer.GetName(), null); 
    } 
}