載入shp檔案到地圖控制項mapcontrol有一般有兩種方式。
1、用mapcontrol控制項的addshapefile方法可載入shape格式檔案,呼叫該方法需要傳入兩個引數,分別是檔案路徑和不帶副檔名的檔名,其呼叫方法如下:
axmapcontrol1.addshapefile(pathname, filename);利用此方法載入shape檔案時,可能會報未知錯誤,試試:將licensecontrol控制項拖入窗體。
[csharp]view plain
copy
?
private
void addshp(object sender, eventargs e)
//將shp檔案的路徑分割為路徑和不帶格式字尾的檔名
string pathname = system.io.path.getdirectoryname(strfilename);
string filename = system.io.path.getfilenamewithoutextension(strfilename);
下面兩行為預設指定檔案路徑和檔名
//string pathname = @"e:\hios\datashp";
//string filename = "river_x";
axmapcontrol1.addshapefile(pathname, filename);
axmapcontrol1.extent = axmapcontrol1.fullextent;
}
private void addshp(object sender, eventargs e)
//將shp檔案的路徑分割為路徑和不帶格式字尾的檔名
string pathname = system.io.path.getdirectoryname(strfilename);
string filename = system.io.path.getfilenamewithoutextension(strfilename);
下面兩行為預設指定檔案路徑和檔名
//string pathname = @"e:\hios\datashp";
//string filename = "river_x";
axmapcontrol1.addshapefile(pathname, filename);
axmapcontrol1.extent = axmapcontrol1.fullextent;
}
2、也可以利用工作空間工廠開啟shape格式檔案
[csharp]view plain
copy
?
private
void addshpdata(object sender, eventargs e)
string pathname = system.io.path.getdirectoryname(strfilename);
string filename = system.io.path.getfilenamewithoutextension(strfilename);
//宣告shape檔案工作空間工廠,並獲取要素工作空間,載入要素類
iworkspacefactory pworkspacefactory = new shapefileworkspacefactoryclass();
iworkspace pworkspace = pworkspacefactory.openfromfile(pathname, 0);
ifeatureworkspace pfeatureworkspace;
pfeatureworkspace = pworkspace as ifeatureworkspace;
ifeatureclass pfeatureclass = pfeatureworkspace.openfeatureclass(filename);
idataset pdataset = pfeatureclass as idataset;
//宣告要素圖層,設定相應屬性
ifeaturelayer pfeaturelayer = new featurelayerclass();
pfeaturelayer.featureclass = pfeatureclass;
pfeaturelayer.name = pdataset.name;
//將要素圖層轉為圖層,add to mapcontrol
ilayer player = pfeaturelayer as ilayer;
axmapcontrol1.map.addlayer(player);
}
private void addshpdata(object sender, eventargs e)
string pathname = system.io.path.getdirectoryname(strfilename);
string filename = system.io.path.getfilenamewithoutextension(strfilename);
//宣告shape檔案工作空間工廠,並獲取要素工作空間,載入要素類
iworkspacefactory pworkspacefactory = new shapefileworkspacefactoryclass();
iworkspace pworkspace = pworkspacefactory.openfromfile(pathname, 0);
ifeatureworkspace pfeatureworkspace;
pfeatureworkspace = pworkspace as ifeatureworkspace;
ifeatureclass pfeatureclass = pfeatureworkspace.openfeatureclass(filename);
idataset pdataset = pfeatureclass as idataset;
//宣告要素圖層,設定相應屬性
ifeaturelayer pfeaturelayer = new featurelayerclass();
pfeaturelayer.featureclass = pfeatureclass;
pfeaturelayer.name = pdataset.name;
//將要素圖層轉為圖層,add to mapcontrol
ilayer player = pfeaturelayer as ilayer;
axmapcontrol1.map.addlayer(player);
}
shp2sdo工具匯入shp檔案到oracle
工具準備 備註 這裡以railway.shp名的檔案為例。一 資料預處理 啟動命令列工具,執行命令 shp2sdo.exe,然後按提示輸入 shp檔案路徑 輸出路徑 等。shp檔案的路徑 shp2sdo.exe shp檔案的路徑 轉換成功後生成三個檔案 railway.ctl railway.dat...
C 底層讀取Shp檔案
featureclass cgismapdoc importshapefiledata file fpshp,file fpdbf for int i 0 i 5 i fread filecode sizeof int 1 fpshp fread filelength sizeof int 1 fp...
關於C 解析shp檔案
最近在做專案時,要求可以上傳shp檔案到指定的地圖中,地圖開發使用的arcgisapi,網上找了好多解析shp檔案的js,但都不是太理想,直到群裡的小夥伴提到gdal 這裡需要注意,其中有乙個版本的的dll需要在bin資料夾中找到,連同csharp資料夾下的8個dll同時放到自己編譯專案的bin檔案...