public DistrictImport() { this.ShapefileName = GetShapefileName(); if (File.Exists(this.ShapefileName)) { File.Delete(this.ShapefileName); } using (var mDrv = Ogr.GetDriverByName("ESRI Shapefile")) { } }
public static string GetVectorInfo(string strFilePath) { string strInfomation = ""; /* -------------------------------------------------------------------- */ /* Register format(s). */ /* -------------------------------------------------------------------- */ Ogr.RegisterAll(); /* -------------------------------------------------------------------- */ /* Open data source. */ /* -------------------------------------------------------------------- */ DataSource ds = Ogr.Open(strFilePath, 0); if (ds == null) { strInfomation = ("Can't open " + strFilePath); return(strInfomation); } /* -------------------------------------------------------------------- */ /* Get driver */ /* -------------------------------------------------------------------- */ Driver drv = ds.GetDriver(); if (drv == null) { strInfomation = ("Can't get driver."); return(strInfomation); } // TODO: drv.name is still unsafe with lazy initialization (Bug 1339) strInfomation += ("Using driver " + drv.name); /* -------------------------------------------------------------------- */ /* Iterating through the layers */ /* -------------------------------------------------------------------- */ for (int iLayer = 0; iLayer < ds.GetLayerCount(); iLayer++) { Layer layer = ds.GetLayerByIndex(iLayer); if (layer == null) { strInfomation = ("FAILURE: Couldn't fetch advertised layer " + iLayer); return(strInfomation); } strInfomation += ReportLayer(layer); } return(strInfomation); }
private async Task SaveToFile(string fileName) { var fileExtension = fileName.Split('.').ToArray().Last(); var shapefile = fileExtension == "shp"; string fileNameGTiff = null; fileNameGTiff = shapefile ? $"{fileName}.tmp" : fileName; await Task.Run(() => { string[] options = { "PHOTOMETRIC=RGB", "PROFILE=GeoTIFF" }; var finalDataset = Gdal.GetDriverByName("GTiff").Create(fileNameGTiff, _processingBand.XSize, _processingBand.YSize, 3, DataType.GDT_Byte, options); finalDataset.SetGeoTransform(_geoTransform); var spatialReference = new SpatialReference(WKT); spatialReference.ExportToWkt(out var exportedWkt); finalDataset.SetProjection(exportedWkt); var redBand = GetByteArrayFromRaster(_processedImage, _processingBand.XSize, _processingBand.YSize, 0); var greenBand = GetByteArrayFromRaster(_processedImage, _processingBand.XSize, _processingBand.YSize, 1); var blueBand = GetByteArrayFromRaster(_processedImage, _processingBand.XSize, _processingBand.YSize, 2); finalDataset.GetRasterBand(1).WriteRaster(0, 0, _processingBand.XSize, _processingBand.YSize, redBand, _processingBand.XSize, _processingBand.YSize, 0, 0); finalDataset.GetRasterBand(2).WriteRaster(0, 0, _processingBand.XSize, _processingBand.YSize, greenBand, _processingBand.XSize, _processingBand.YSize, 0, 0); finalDataset.GetRasterBand(3).WriteRaster(0, 0, _processingBand.XSize, _processingBand.YSize, blueBand, _processingBand.XSize, _processingBand.YSize, 0, 0); if (shapefile) { string[] optionsShapefile = null; var finalDatasource = Ogr.GetDriverByName("ESRI Shapefile") .CreateDataSource(fileName, optionsShapefile); var layer = finalDatasource.CreateLayer("trees", spatialReference, wkbGeometryType.wkbPolygon, optionsShapefile); Gdal.Polygonize(finalDataset.GetRasterBand(1), finalDataset.GetRasterBand(1), layer, -1, null, null, null); finalDatasource.FlushCache(); } else { finalDataset.FlushCache(); } }); }
static public bool SaveShp(string path, string fanme, wkbGeometryType t, List <Geometry> lstgeo) { // 为了支持中文路径,请添加下面这句代码 OSGeo.GDAL.Gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "NO"); // 为了使属性表字段支持中文,请添加下面这句 OSGeo.GDAL.Gdal.SetConfigOption("SHAPE_ENCODING", ""); string strVectorFile = path; // 注册所有的驱动 Ogr.RegisterAll(); //创建数据,这里以创建ESRI的shp文件为例 string strDriverName = "ESRI Shapefile"; Driver oDriver = Ogr.GetDriverByName(strDriverName); if (oDriver == null) { // Console.WriteLine("%s 驱动不可用!\n", strVectorFile); return(false); } // 创建数据源 DataSource oDS = oDriver.CreateDataSource(strVectorFile, null); if (oDS == null) { // Console.WriteLine("创建矢量文件【%s】失败!\n", strVectorFile); return(false); } // 创建图层,创建一个多边形图层,这里没有指定空间参考,如果需要的话,需要在这里进行指定 Layer oLayer = oDS.CreateLayer(fanme, null, t, null); if (oLayer == null) { // Console.WriteLine("图层创建失败!\n"); return(false); } FeatureDefn oDefn = oLayer.GetLayerDefn(); // 创建三角形要素 foreach (var item in lstgeo) { Feature oFeatureTriangle = new Feature(oDefn); oFeatureTriangle.SetGeometry(item); oLayer.CreateFeature(oFeatureTriangle); } return(true); }
/// <summary>初始化Gdal /// </summary> public virtual void InitinalGdal() { OSGeo.GDAL.Gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); // 为了支持中文路径 OSGeo.GDAL.Gdal.SetConfigOption("SHAPE_ENCODING", ""); // 为了使属性表字段支持中文CPLSetConfigOption OSGeo.GDAL.Gdal.SetConfigOption("GEOGSON_ENCODING", ""); // 为了使属性表字段支持中文CPLSetConfigOption OSGeo.GDAL.Gdal.AllRegister(); Ogr.RegisterAll(); this.InitDriver(); if (_Driver == null) { } }
/// <summary> /// Method to ensure the static constructor is being called. /// </summary> /// <remarks>Be sure to call this function before using Gdal/Ogr/Osr</remarks> public static void ConfigureOgr() { if (_configuredOgr) { return; } // Register drivers Ogr.RegisterAll(); _configuredOgr = true; PrintDriversOgr(); }
/// <summary> /// 初始化Gdal,注册所有驱动并支持中文 /// </summary> public static void GdalInit() { //若出现【无法加载 DLL“ogr_wrap”: 找不到指定的模块】, //请将附带的DLL.rar中的全部文件解压复制到生成目录bin\x86\Debug(或bin\x86\Debug\DLL),同时安装附带的VC++包(Vcredist_x86.exe) //Exception: Unable to load DLL "ogr_wrap": Cannot find the specified module. //Solution: ① Please unzip all the files in the attached DLL.rar to the build directory bin\x86\Debug(or bin\x86\Debug\DLL) // ② Install VC++ package (Vcredist_x86.exe) Ogr.RegisterAll(); // 注册所有GDAL的驱动,Register all GDAL drivers Gdal.AllRegister(); Gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); // 为了支持中文路径 Gdal.SetConfigOption("SHAPE_ENCODING", "CP936"); // 为了使属性表字段支持中文CP936 Gdal.SetConfigOption("GDAL_DATA", AppDomain.CurrentDomain.BaseDirectory + "Data"); //设置GDAL Data文件夹位置 }
private void ShpCreate_Load(object sender, EventArgs e) { OSGeo.GDAL.Gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); // 为了使属性表字段支持中文,请添加下面这句 OSGeo.GDAL.Gdal.SetConfigOption("SHAPE_ENCODING", ""); Ogr.RegisterAll(); InitListView(this.listView1); //this.listView1.Columns.Add("字段名", 65, HorizontalAlignment.Center); //this.listView1.Columns.Add("字段长度", 65, HorizontalAlignment.Center); //this.listView1.View = System.Windows.Forms.View.Details; }
/// <summary> /// Loads a OgrFeatureProvider datasource with the specified layer /// </summary> /// <param name="path">datasource</param> /// <param name="layerNumber">number of layer</param> public OgrFeatureProvider(string path, int layerNumber) : this() { this.path = path; if (!ogrInitialized) { InitializeOgr(); } ogrDataSource = Ogr.Open(path, 0); ogrLayer = ogrDataSource.GetLayerByIndex(layerNumber); this.layerName = ogrLayer.GetName(); Name = LayerName; _IsOpen = true; }
private static List <string> GetSupportVectorExtensions() { int driverCount = Ogr.GetDriverCount(); List <string> extensions = new List <string>(); for (int i = 0; i < driverCount; i++) { using (OSGeo.OGR.Driver driver = Ogr.GetDriver(i)) { } } return(extensions); }
public OgrDataReader(string sDataSource, string sLayer) { _ogrDataSource = Ogr.Open(sDataSource, 0); _ogrLayer = sLayer != null ? _ogrDataSource.GetLayerByName(sLayer) : _ogrDataSource.GetLayerByIndex(0); _ogrFeatureDefinition = _ogrLayer.GetLayerDefn(); _iFieldCount = _ogrFeatureDefinition.GetFieldCount(); BuildSchemaTable(); _currentFeature = null; bClosed = false; }
/// <summary> /// Loads a OgrFeatureProvider datasource with the specified layer /// </summary> /// <param name="path">datasource</param> /// <param name="layerName">name of layer</param> public OgrFeatureProvider(string path, string layerName) : this() { this.path = path; this.layerName = layerName; if (!ogrInitialized) { InitializeOgr(); } ogrDataSource = Ogr.Open(path, 1); ogrLayer = ogrDataSource.GetLayerByName(layerName); Name = layerName; _IsOpen = true; }
public void InitGDAL() { Gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); Gdal.SetConfigOption("SHAPE_ENCODING", ""); Gdal.AllRegister(); Ogr.RegisterAll(); oDriver = Ogr.GetDriverByName("ESRI Shapefile"); if (oDriver == null) { // MessageBox.Show("文件不能打开,请检查"); } }
public static void CreateShapeFile(MG_Layer mgLayer, string filePath) { string dataSourceName = filePath; string layerName = Path.GetFileNameWithoutExtension(filePath); mgLayer.SetLayerPath(filePath); try { Ogr.RegisterAll(); string driverName = "ESRI Shapefile"; Driver driver = Ogr.GetDriverByName(driverName); if (File.Exists(dataSourceName)) { //System.IO.File.Delete(dataSourceName);// only remove xxx.shp driver.DeleteDataSource(dataSourceName);// reomve xxx.shp dbf shx } DataSource ds = driver.CreateDataSource(dataSourceName, new string[] { }); wkbGeometryType gt = TowkbGeometryType(mgLayer.Type);// retrieve data Layer layer = ds.CreateLayer(layerName, null, gt, new string[] { }); // create three files xxx.shp xxx.dbf xxx.shx // fieldset int fieldCount = mgLayer.FieldSet.Count(); for (int i = 0; i < fieldCount; i++) { MG_Field field = mgLayer.FieldSet.GetAt(i); FieldDefn def = ToFieldDefn(field); layer.CreateField(def, 1); } // feature int featureCount = mgLayer.GetFeatureCount(); for (int i = 0; i < featureCount; i++) { Feature f = ToFeature(mgLayer.GetFeature(i)); layer.CreateFeature(f); f.Dispose(); } // flush data to file layer.Dispose(); ds.Dispose(); driver.Dispose(); } catch (System.Exception ex) { MessageBox.Show(ex.ToString()); } }
/// <summary> /// 获取所有列名 /// </summary> /// <param name="strVectorFile"></param> /// <returns></returns> public static List <string> getShapeFieldList(string strVectorFile) { List <string> list = new List <string>(); #region ReadShape { Gdal.AllRegister(); // 为了支持中文路径,请添加下面这句代码 OSGeo.GDAL.Gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "NO"); // 为了使属性表字段支持中文,请添加下面这句 OSGeo.GDAL.Gdal.SetConfigOption("SHAPE_ENCODING", ""); // 注册所有的驱动 Ogr.RegisterAll(); //打开数据 DataSource ds = Ogr.Open(strVectorFile, 0); if (ds == null) { MessageBox.Show("打开文件【{0}】失败!,文件名中不能包含中文!", strVectorFile); return(list); } //MessageBox.Show("打开文件【{0}】成功!", strVectorFile); // 获取该数据源中的图层个数,一般shp数据图层只有一个,如果是mdb、dxf等图层就会有多个 int iLayerCount = ds.GetLayerCount(); // 获取第一个图层 Layer oLayer = ds.GetLayerByIndex(0); if (oLayer == null) { MessageBox.Show("获取第{0}个图层失败!\n", "0"); return(list); } // 对图层进行初始化,如果对图层进行了过滤操作,执行这句后,之前的过滤全部清空 oLayer.ResetReading(); FeatureDefn oDefn = oLayer.GetLayerDefn(); // 输出图层中的要素个数 int iFieldCount = oDefn.GetFieldCount(); for (int iAttr = 0; iAttr < iFieldCount; iAttr++) { FieldDefn oField = oDefn.GetFieldDefn(iAttr); list.Add(oField.GetNameRef()); } } #endregion list.Sort(); return(list); }
public static DataSource OpenDataSource(string dataPath, int update = 0) { DataSource dataSource = null; try { dataSource = Ogr.Open(dataPath, update); } catch (Exception e) { Debug.WriteLine(e.Message); } return(dataSource); }
public List <string> GetTileNameFromShapefile(string shpfilepath) { string fieldname = "TileName"; bool gotit = false; List <string> tilenames = new List <string>(); DataSource ds1 = Ogr.Open(shpfilepath, 0); if (ds1 == null) { Console.WriteLine(" [-] Could not open {0}", shpfilepath); return(tilenames); } Layer newlayer = ds1.GetLayerByIndex(0); if (newlayer == null) { Console.WriteLine(" [-] Could not fetch layer."); ds1.Dispose(); return(tilenames); } newlayer.ResetReading(); FeatureDefn newfeaturedfn = newlayer.GetLayerDefn(); for (int i = 0; i < newfeaturedfn.GetFieldCount(); i++) { //find TileName field in provided shapefile FieldDefn fielddefn = newfeaturedfn.GetFieldDefn(i); if (fielddefn.GetName() == fieldname) { gotit = true; break; } } if (gotit == false) { Console.WriteLine(" [-] Could not find tile name field. Please provide shapefile with the attribute field TileName"); ds1.Dispose(); return(tilenames); } for (int i = 0; i < newlayer.GetFeatureCount(1); i++) { //return each string for TileName field in shapefile Feature newfeature = newlayer.GetFeature(i); string result = newfeature.GetFieldAsString(fieldname); tilenames.Add(result); } ds1.Dispose(); return(tilenames); }
public static string Amersfoort() { string proj4 = "+proj=sterea +lat_0=52.15616055555555 +lon_0=5.38763888888889 +k=0.9999079 +x_0=155000 +y_0=463000 +ellps=bessel +units=m +no_defs"; using (var osrs = new SpatialReference("+proj=sterea +lat_0=52.15616055555555 +lon_0=5.38763888888889 +k=0.9999079 +x_0=155000 +y_0=463000 +ellps=bessel +units=m +no_defs")) { Ogr.RegisterAll(); string stringOutput; osrs.ExportToProj4(out stringOutput); return(stringOutput); } }
// 获取Geometry public static Geometry GetGeometry(int fid) { // 打开数据 DataSource dataSource = Ogr.Open(dbPath, 0); Layer layer = dataSource.GetLayerByName("city"); Feature feature = layer.GetFeature(fid); Geometry geometry = feature.GetGeometryRef(); // 关闭数据 layer.Dispose(); return(geometry); }
private static void Open(string dataSetPath) { Driver fileGdbDriver = Ogr.GetDriverByName("OpenFileGDB"); DataSource dataSource = fileGdbDriver.Open(dataSetPath, 0); int layerCount = dataSource.GetLayerCount(); for (int i = 0; i < layerCount; i++) { Layer layer = dataSource.GetLayerByIndex(i); Console.WriteLine($"Layer: {layer.GetName()}"); } }
public void ShapefileTestMethod() { Ogr.RegisterAll(); var shpDriver = Ogr.GetDriverByName("ESRI Shapefile"); var shpDs = shpDriver.Open(@"C:\test\continents.shp", 0); var layer = shpDs.Layers().ToList()[0]; var fields = layer.Fields(); Trace.WriteLine(String.Join(" ", fields.Select(field => field.GetName()))); layer.Features().ToList().ForEach((feature) => { Trace.WriteLine(String.Join(" ", feature.Fields().Select(field => feature.GetFieldAsString(field.GetName())))); }); }
//public bool IsMaxEditesPerDay() //{ // pglayer.SetAttributeFilter($"DateInsert >= '{DateTime.Now:yyyy-MM-dd}'"); // if (pglayer.GetFeatureCount(0) < 5) // { // pglayer.SetAttributeFilter(""); // return true; // } // return false; //} public string GetObjectByCoordinates(double x, double y) { //x = Normalize(x); string wkt = $"POINT({x.ToString(nfi)} {y.ToString(nfi)})"; Geometry filter = null; Feature feature = null; try { filter = Ogr.CreateGeometryFromWkt(ref wkt, pglayer.GetLayerDefn().GetGeomFieldDefn(GEOM_FIELD_IDX).GetSpatialRef()); pglayer.SetSpatialFilter(filter); feature = pglayer.GetNextFeature(); if (feature != null) { string featureWkt = null; int error = feature.GetGeomFieldRef(GEOM_FIELD_IDX).ExportToWkt(out featureWkt); if (error == OGRERR_NONE) { var jsonobject = new { year = feature.GetFieldAsString("year"), address = feature.GetFieldAsString("address_in"), keyid = feature.GetFieldAsInteger("KEYID"), klgd_descr = feature.GetFieldAsString("klgd_gallery_descr"), klgd_img_url = feature.GetFieldAsString("klgd_gallery_img_url"), klgd_source = feature.GetFieldAsString("klgd_source_info"), geom = featureWkt }; return(Newtonsoft.Json.JsonConvert.SerializeObject(jsonobject)); } } } catch (Exception ex) { throw new GisException("Error getting feature by coordinates", ex); } finally { if (filter != null) { filter.Dispose(); } if (feature != null) { feature.Dispose(); } } return(null); }
public GeneralShp(string OutputPath, string shpfileNameWithoutExt, wkbGeometryType type) { _outShpPath = Path.GetDirectoryName(OutputPath) + "\\" + shpfileNameWithoutExt + ".shp"; _shpfileName = shpfileNameWithoutExt; _geoType = type; Ogr.RegisterAll(); //创建数据,这里以创建ESRI的shp文件为例 string strDriverName = "ESRI Shapefile"; int count = Ogr.GetDriverCount(); Driver oDriver = Ogr.GetDriverByName(strDriverName); if (oDriver == null) { Console.WriteLine("%s 驱动不可用!\n", _outShpPath); return; } // 创建数据源 if (File.Exists(_outShpPath)) { MessageBoxButtons messBut = MessageBoxButtons.YesNo; if (MessageBox.Show(_shpfileName + "存在同名文件,是否覆盖?", "文件重名", messBut) == DialogResult.Yes) { File.Delete(_outShpPath); } else { string dir = Path.GetDirectoryName(_outShpPath); string filename = Path.GetFileNameWithoutExtension(_outShpPath); string ext = Path.GetExtension(_outShpPath); _outShpPath = dir + "\\" + filename + "1" + ext; } } oDS = oDriver.CreateDataSource(_outShpPath, null); if (oDS == null) { Console.WriteLine("创建矢量文件【%s】失败!\n", _outShpPath); return; } // 创建图层,创建一个多边形图层,这里没有指定空间参考,如果需要的话,需要在这里进行指定 oLayer = oDS.CreateLayer(_shpfileName, null, type, null); if (oLayer == null) { Console.WriteLine("图层创建失败!\n"); return; } }
private void 矢量数据重投影ToolStripMenuItem_Click(object sender, EventArgs e) { //选择投影变换图层 SelectLayer selFrm = new SelectLayer(mapControl); selFrm.Text = "选择变换图层"; selFrm.label1.Text = "选择矢量图层"; selFrm.label2.Visible = false; selFrm.comboBox2.Visible = false; if (selFrm.ShowDialog(this) == DialogResult.OK) { int index = 0; for (int i = 0; i < mapControl._MapLayers.Count(); i++) { if (mapControl._MapLayers[i].Name == selFrm.cb1) { index = i; break; } } //选择输出文件路径 SaveFileDialog sfd = new SaveFileDialog(); sfd.Title = "选择重投影文件存储路径"; sfd.Filter = @"shp(*.shp)|*.shp"; if (sfd.ShowDialog() == DialogResult.OK) { string path = sfd.FileName; //文件路径 string[] path2 = path.Split(new char[1] { '\\' }); //文件名 string name = path2[path2.Count() - 1]; //打开需转换矢量文件 DataSource ds = Ogr.Open(mapControl._MapLayers[index].FilePath, 0); //投影转换 TransformProject transform = new TransformProject(); transform.TransformShp(ds, path); //转换结果添加至地图 mapControl.AddShpLayer(path, name); if (tVLayers.Nodes.Count == 0) { tVLayers.Nodes.Add("图层"); } tVLayers.Nodes[0].Nodes.Insert(0, name); tVLayers.ExpandAll(); tVLayers.SelectedNode = tVLayers.Nodes[0].Nodes[0]; MessageBox.Show("成功转换至Web墨卡托投影!", "投影转换结果"); } } }
/******************************* 算法一 *************************************/ /// /// 2 调用点矩法提出断点,标记在CUT字段中 /// /// 3 调用点角法提出平角点,标计在straight中 /// /// 4 通过cut字段提取分段点集,再通过straight提取选用点集 /// /// 5 用选出的点集拟合直线并保留参数 /// 6 用参数集进行求交 /// 7 主要参数:点距法中的最大点距、点角法中的最大角度和迭代次数 /// /******************************* 工作流 *************************************/ public static void getDLG(string inFile, string outFile) { //注册 Ogr.RegisterAll(); Gdal.AllRegister(); //驱动 OSGeo.OGR.Driver dr = Ogr.GetDriverByName("ESRI shapefile"); //原数据 DataSource inDS = dr.Open(inFile, 0); Layer inLayer = inDS.GetLayerByIndex(0); //out数据 if (File.Exists(outFile)) { File.Delete(outFile); } DataSource outDS = dr.CreateDataSource(outFile, null); Layer outLayer = outDS.CreateLayer("outLayer", null, wkbGeometryType.wkbPolygon, null); int featCount = inLayer.GetFeatureCount(0); for (int i = 0; i < featCount; i++) { Feature aFeatuer = inLayer.GetFeature(i); Geometry subGeom = aFeatuer.GetGeometryRef().GetGeometryRef(0); //工作流 2 , 返回所有断点的ID,有重要参数! List <int> cutIDS = _点距法提断点._提取断点(aFeatuer, 2); //工作流 3, 返回所有平角点的ID,有重要参数! List <int> straightIDS = _提取平角点._平角点ID集(aFeatuer, 175, 5); //输出准备工作 Feature newFeat = new Feature(new FeatureDefn("")); Geometry newGeom = new Geometry(wkbGeometryType.wkbPolygon); //工作流 4 , 通过cut字段提取分段点集,再通过straight提取选用点集 newGeom.AddGeometry(ForDLG._提取断平拟合直线(aFeatuer, cutIDS, straightIDS)); //收! newFeat.SetGeometry(newGeom); outLayer.CreateFeature(newFeat); newFeat.Dispose(); aFeatuer.Dispose(); } inLayer.Dispose(); outLayer.Dispose(); inDS.Dispose(); outDS.Dispose(); }
private void DatasetCopy(string srcPath, string trgPath, string driverName) { var dataset = Ogr.OpenShared(srcPath, 0); var layers = CommonUtils.GetDatasetLayers(dataset); OSGeo.OGR.Driver driver = Ogr.GetDriverByName(driverName); var trgDataset = driver.CreateDataSource(trgPath, null); foreach (var srcLayer in layers) { trgDataset.CopyLayer(srcLayer, srcLayer.GetName(), null); } trgDataset.Dispose(); }
/// <summary> /// Method to ensure the static constructor is being called. /// </summary> /// <remarks>Be sure to call this function before using Gdal/Ogr/Osr</remarks> public static void ConfigureOgr() { if (IsOgrConfigured) { return; } // Register drivers Ogr.RegisterAll(); IsOgrConfigured = true; #if DEBUG PrintDriversOgr(); #endif }
/// <summary> /// 初始化Gdal /// </summary> public void InitinalGdal() { // 为了支持中文路径 OSGeo.GDAL.Gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); // 为了使属性表字段支持中文 Gdal.SetConfigOption("SHAPE_ENCODING", ""); Gdal.AllRegister(); Ogr.RegisterAll(); oDerive = Ogr.GetDriverByName("ESRI Shapefile"); if (oDerive == null) { MessageBox.Show("文件不能打开,请检查"); } }
public void LayerCsvTest() { Trace.WriteLine(Uri.HexEscape(',')); var urus = Uri.EscapeDataString("ad,asd"); Trace.WriteLine(urus); Ogr.RegisterAll(); var shpDriver = Ogr.GetDriverByName("ESRI Shapefile"); var shpDs = shpDriver.Open(@"C:\test\continents.shp", 0); var layer = shpDs.GetLayerByIndex(0); var csv = GdalUtils.LayerToCsvString(layer, true); Trace.WriteLine(csv); }
Enyim.Collections.Envelope currentenv = null; // 当前view呈现的map范围 public void Open(string fname) { Clear(); ds = Ogr.Open(fname, 1); Assert.IsNotNull(ds); Assert.IsTrue(ds.GetLayerCount() > 0); layer = ds.GetLayerByIndex(0); Assert.IsNotNull(layer); spatialquery = new GisSpatialQuery(); spatialquery.Clear(); ReadFeature2Tree(); currentenv = new Enyim.Collections.Envelope(); }