今天在機關做圖層合并的工作,剛開始找不到相應的接口,現在解決了,放出來與大家共享
本程式實作了對具有同類型資料結構的shapefile的圖層合并,并在MapControl中顯示.
ILayer pLayer;
IFeatureLayer pFeatureLayer;
IFeatureClass pFeatureClass;
IWorkspaceName pNewWSName;
IBasicGeoprocessor pBasicGeop;
IFeatureClassName pFeatureClassName;
IDatasetName pDatasetName;
IFeatureClass pOutputFeatClass;
IFeatureLayer pOutputFeatLayer;
IArray pArray;
ITable pTable;
//合并圖層的集合
pArray = new ArrayClass();
for (int i = 0; i < this.axMapcontrol1.LayerCount;i++ )
{
pLayer = this.MapC_main.get_Layer(i);
pArray.Add(pLayer);
}
//定義輸出圖層的fields表
pLayer = this.MapC_main.get_Layer(0);
pTable = (ITable)pLayer;
pFeatureLayer=(IFeatureLayer)pLayer;
pFeatureClass = pFeatureLayer.FeatureClass;
//判斷圖層是否大于2個
if(this..axMapcontrol1.LayerCount< 2){
MessageBox.Show("Table QI failed");
return;
//輸出檔案類型
pFeatureClassName = new FeatureClassNameClass();
pFeatureClassName.FeatureType = esriFeatureType.esriFTSimple;
pFeatureClassName.ShapeFieldName = "Shape";
pFeatureClassName.ShapeType = pFeatureClass.ShapeType;
//輸出shapefile的名稱和位置
pNewWSName = new WorkspaceNameClass();
pNewWSName.WorkspaceFactoryProgID="esriDataSourcesFile.ShapefileWorkspaceFactory";
pNewWSName.PathName = "E:\\Cshape";
pDatasetName = (IDatasetName)pFeatureClassName;
pDatasetName.Name = "Union_result_1";
pDatasetName.WorkspaceName = pNewWSName;
//合并圖層
pBasicGeop = new BasicGeoprocessorClass();
pOutputFeatClass=pBasicGeop.Merge(pArray,pTable,pFeatureClassName);
//Add the output layer to the map
pOutputFeatLayer = new FeatureLayerClass();
pOutputFeatLayer.FeatureClass = pOutputFeatClass;
pOutputFeatLayer.Name = pOutputFeatClass.AliasName;
this..axMapcontrol1.AddLayer(pOutputFeatLayer as ILayer, 0);
版權說明
如果标題未标有<轉載、轉>等字則屬于作者原創,歡迎轉載,其版權歸作者和部落格園共有。
作 者:溫景良

<a href="http://home.cnblogs.com/u/wenjl520/">溫景良(Jason)</a>
<a href="http://home.cnblogs.com/u/wenjl520/followees">關注 - 32</a>
<a href="http://home.cnblogs.com/u/wenjl520/followers">粉絲 - 161</a>
<a>+加關注</a>
<a></a>
Post Comment
我試驗了為什麼總是在pOutputFeatClass=pBasicGeop.Merge(pArray,pTable,pFeatureClassName);句的時候報錯呢?是不是還要有pNewWSName.ConnectionProperties的設定啊? 我主要是想注記層和點層或者線層進行合并
看你的文章真是種享受!篇篇短小精悍!太喜歡了!
<a href="http://www.ucancode.com/index.htm" target="_blank">【推薦】超50萬VC++源碼: 大型工控、組态\仿真、模組化CAD源碼2018!</a>
<a href="https://dnspod.cloud.tencent.com/act/yearendsales?from=IT&fromSource=gwzcw.741110.741110.741110" target="_blank">【推薦】騰訊雲新使用者域名搶購1元起,抓緊搶購</a>
<b>最新IT新聞</b>:
<b>最新知識庫文章</b>: