91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 12KB
    文件類型: .cs
    金幣: 1
    下載: 0 次
    發布日期: 2021-05-09
  • 語言: C#
  • 標簽: gdal??c#??中文亂碼??

資源簡介

最新版本的gdal版本為(release-1700-x64-gdal-1-11-4-mapserver-6-4-3)下載后讀取shp文件總是亂碼,查看了無數大神的文章后發現解決方案,但是對于我們這樣的小白來講,涉及到了反射,指針一類的東西,該方案并不是很懂,看了還是不知道咋寫c#版本的代碼。。。所以把解決好后的源碼發上來,供我這種小白去學習!

資源截圖

代碼片段和文件信息

using?System;
using?System.Collections.Generic;
using?System.Linq;
using?System.Text;
using?System.Windows.Forms;
//
using?System.IO;
using?OSGeo.GDAL;
using?OSGeo.OGR;
using?OSGeo.OSR;
using?System.Collections;
using?System.Data;
using?System.Runtime.InteropServices;

namespace?App_Code
{
????///?
????///?定義SHP解析類
????///?

????public?class?ShpHandle
????{
????????///?保存SHP屬性字段
????????public?OSGeo.OGR.Driver?oDerive;
???????
????????public?ShpHandle()
????????{
????????????InitinalGdal();//注冊所有gdal
????????}

????????///?
????????///?初始化Gdal
????????///?

????????protected?void?InitinalGdal()
????????{
????????????Gdal.AllRegister();
????????????Ogr.RegisterAll();
????????????//?為了支持中文路徑
????????????Gdal.SetConfigOption(“GDAL_FILENAME_IS_UTF8“?“YES“);
????????????//?為了使屬性表字段支持中文
????????????Gdal.SetConfigOption(“SHAPE_ENCODING“?““);?
????????????
????????????
????????????oDerive?=?Ogr.GetDriverByName(“ESRI?Shapefile“);
????????????if?(oDerive?==?null)
????????????{
????????????????MessageBox.Show(“文件不能打開,請檢查“);
????????????}

????????}?????
????}

????public?class?ShpHandle_R?:?ShpHandle
????{
????????public?layer?player;
????????public?Dictionary?fieldmap;
????????//注意“gdal202.dll“要隨著你的gdal版本改變而改變,注意查看bin目錄下的gdal文件名即可
????????[DllImport(“gdal202.dll“?EntryPoint?=?“OGR_F_GetFieldAsString“?CallingConvention?=?CallingConvention.Cdecl)]
????????public?extern?static?IntPtr?OGR_F_GetFieldAsString(HandleRef?handle?int?i);


????????public?ShpHandle_R(string?sfilename)
????????{
????????????InitinalGdal();//注冊所有gdal
????????????player?=?GetShplayer(sfilename);//獲取shp的圖層
????????????fieldmap?=?GetFeilds();//獲取字段結構
????????}

????????public?ShpHandle_R()
????????{
????????????InitinalGdal();//注冊所有gdal
????????}

????????///?
????????///?獲取SHP文件的layer
????????///?

????????///?
????????///?yer“>
????????///?
????????private?layer?GetShplayer(string?sfilename)
????????{
????????????layer?olayer?=?null;
????????????if?(null?==?sfilename?||?sfilename.Length?<=?3)
????????????{
????????????????return?null;
????????????}
????????????if?(oDerive?==?null)
????????????{
????????????????MessageBox.Show(“文件不能打開,請檢查“);
????????????}
????????????DataSource?ds?=?oDerive.Open(sfilename?1);
????????????if?(null?==?ds)
????????????{
????????????????return?null;
????????????}
????????????//int?iPosition?=?sfilename.LastIndexOf(“\\“);
????????????//string?sTempName?=?sfilename.Substring(iPosition?+?1?sfilename.Length?-?iPosition?-?4?-?1);
????????????olayer?=?ds.GetlayerByIndex(0);
????????????if?(olayer?==?null)
????????????{
????????????????ds.Dispose();
????????????????return?null;
????????????}
????????????return?olayer;
????????}
????????///?
????????///?獲取所有的屬性字段名稱列表
????????///?

????????///?

評論

共有 條評論