




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、Excel列表坐標(biāo)點(diǎn)轉(zhuǎn)成帶Z值的shape點(diǎn)文件和線文件using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using ESRI.ArcGIS.Controls;using ESRI.ArcGIS.Geodatabase;using ESRI.ArcGIS.DataSourcesFile;using
2、 ESRI.ArcGIS.Geometry;namespace NetWorkDatamanger public partial class CreateShpFileBaseOnExcel : Form private DataGridView excelDataGridViewX; private AxMapControl axMapControl; private string fileName; private string filePath; public CreateShpFileBaseOnExcel(AxMapControl _axMapControl, DataGridVie
3、w _DataView) axMapControl = _axMapControl; excelDataGridViewX = _DataView; InitializeComponent(); private void delFieldButtonX_Click(object sender, EventArgs e) if (addFieldListBox.SelectedItem != null) fieldListBox.Items.Add(addFieldListBox.SelectedItem); addFieldListBox.Items.Remove(addFieldListBo
4、x.SelectedItem); private void addFieldButtonX_Click(object sender, EventArgs e) if (fieldListBox.SelectedItem != null) addFieldListBox.Items.Add(fieldListBox.SelectedItem); fieldListBox.Items.Remove(fieldListBox.SelectedItem); private void CreateShpFileBaseOnExcel_Load(object sender, EventArgs e) fo
5、r (int i = 0; i excelDataGridViewX.Columns.Count; i+) string HeaderString = excelDataGridViewX.Columnsi.HeaderText; xComboBoxEx.Items.Add(HeaderString); yComboBoxEx.Items.Add(HeaderString); zComboBoxEx.Items.Add(HeaderString); fieldListBox.Items.Add(HeaderString); private void Create_Click(object se
6、nder, EventArgs e) switch (shpTypeComboBox.Text) case Point: CreatPointShp(); break; case Polyline: CreatePolylineShp(); break; case PolylineZM: CreatePolylineZMShp(); break; default: MessageBox.Show(請選擇創(chuàng)建的shp類型!); break; public void CreatPointShp() try IWorkspaceFactory pShpWksFact = new ShapefileW
7、orkspaceFactory(); IFeatureWorkspace pFeatWks; pFeatWks = (IFeatureWorkspace)pShpWksFact.OpenFromFile(filePath, 0); const string strShapeFieldName = Shape; /定義屬性字段 IFields pFields = new Fields(); IFieldsEdit pFieldsEdit; pFieldsEdit = pFields as IFieldsEdit; IField pField = new Field(); IFieldEdit p
8、FieldEdit = new Field() as IFieldEdit; pFieldEdit.Name_2 = strShapeFieldName; pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry; pField = pFieldEdit as IField; /定義幾何屬性 IGeometryDef pGeomDef = new GeometryDef(); IGeometryDefEdit pGeomDefEdit = new GeometryDef() as IGeometryDefEdit; pGeomDefEdit
9、 = pGeomDef as IGeometryDefEdit; pGeomDefEdit.HasZ_2 = true;/圖層是有高程值的 switch (shpTypeComboBox.Text) case Point: pGeomDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint; break; case Polyline: pGeomDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolyline; break; case Polygon: pGeomDefEd
10、it.GeometryType_2 = esriGeometryType.esriGeometryPolygon; break; pGeomDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint; pGeomDefEdit.SpatialReference_2 = new UnknownCoordinateSystem() as ISpatialReference; pFieldEdit.GeometryDef_2 = pGeomDef; pFieldsEdit.AddField(pField); pFields = pField
11、sEdit as IFields; IFeatureClass pFeatureClass; pFeatureClass = pFeatWks.CreateFeatureClass(fileName, pFields, null, null, esriFeatureType.esriFTSimple, strShapeFieldName, ); /添加屬性字段 for (int i = 0; i addFieldListBox.Items.Count; i+) IField pfield = new Field(); IFieldEdit pfieldEdit = new Field() as
12、 IFieldEdit; pfieldEdit.Name_2 = addFieldListBox.Itemsi.ToString(); pfieldEdit.Type_2 = esriFieldType.esriFieldTypeString; pfield = pfieldEdit as IField; pFeatureClass.AddField(pfield); /繪制點(diǎn) for (int i = 0; i excelDataGridViewX.Rows.Count - 1; i+) DataGridViewRow dataRow = excelDataGridViewX.Rowsi;
13、double pointX, pointY, pointZ; pointX = double.Parse(dataRow.CellsxComboBoxEx.Text.Value.ToString(); pointY = double.Parse(dataRow.CellsyComboBoxEx.Text.Value.ToString(); pointZ = double.Parse(dataRow.CellszComboBoxEx.Text.Value.ToString(); IPoint pPoint = new ESRI.ArcGIS.Geometry.Point() as IPoint;
14、 /pPoint.PutCoords(pointX, pointY); pPoint.X = pointX; pPoint.Y = pointY; pPoint.Z = pointZ; IZAware fromZAware = pPoint as IZAware; fromZAware.ZAware = true; IFeature pFeature = pFeatureClass.CreateFeature(); pFeature.Shape = pPoint; /為該點(diǎn)添加屬性值 for (int j = 0; j addFieldListBox.Items.Count; j+) stri
15、ng fieldName = addFieldListBox.Itemsj.ToString(); pFeature.set_Value(pFeature.Fields.FindField(fieldName), dataRow.CellsfieldName.Value.ToString(); pFeature.Store(); /添加新建的數(shù)據(jù)至Map中 axMapControl.AddShapeFile(filePath, fileName); this.Hide(); MessageBox.Show(Excel轉(zhuǎn)換shp完畢!); catch (Exception ex) Message
16、Box.Show(ex.Message); public void CreatePolylineShp() try IWorkspaceFactory pShpWksFact = new ShapefileWorkspaceFactory(); IFeatureWorkspace pFeatWks; pFeatWks = (IFeatureWorkspace)pShpWksFact.OpenFromFile(filePath, 0); IFeatureClass pFeatureClass; pFeatureClass = CreateFeatureClassFromFactory(pFeat
17、Wks, fileName,false); ISegment segmentArray = new ISegmentexcelDataGridViewX.Rows.Count - 1; string strname = ; /每條線的名稱 int nStartI = 0; /每條線的起始位置 /繪制線 for (int i = 0; i 0) IGeometryCollection seColletion = new PolylineClass(); ISpatialReference psRef = new UnknownCoordinateSystemClass(); ISegmentCo
18、llection pathCollection = new PolylineClass(); IGeometry pGeometry = seColletion as PolylineClass; pGeometry.SpatialReference = psRef; ILine line = segmentArray0 as ILine; object o1 = Type.Missing; object o2 = Type.Missing; for (int m = nStartI; m segmentArray.Length; m+) /IZAware iPolylineAware = (
19、IZAware)(segmentArraym as IPolyline); /iPolylineAware.ZAware = true; pathCollection.AddSegment(segmentArraym, ref o1, ref o2); pGeometry = pathCollection as IGeometry; seColletion.AddGeometryCollection(pGeometry as IGeometryCollection); IFeature pFeature = pFeatureClass.CreateFeature(); pFeature.Sha
20、pe = (seColletion as IGeometry); pFeature.set_Value(pFeature.Fields.FindField(name), strname); pFeature.Store(); strname = dataRow2.Cellsname.Value.ToString(); nStartI = i + 1; continue; double pointX2, pointY2, pointZ2; pointX2 = double.Parse(dataRow2.CellsxComboBoxEx.Text.Value.ToString(); pointY2
21、 = double.Parse(dataRow2.CellsyComboBoxEx.Text.Value.ToString(); pointZ2 = double.Parse(dataRow2.CellszComboBoxEx.Text.Value.ToString(); IPoint fromPoint = new PointClass(); IPoint toPoint = new PointClass(); IPath pPathA = new PathClass(); ILine pLine = new LineClass(); /IPolyline pLine = new Polyl
22、ineClass(); fromPoint.X = pointX; fromPoint.Y = pointY; fromPoint.Z = pointZ; IZAware fromZAware = fromPoint as IZAware; fromZAware.ZAware = true; toPoint.X = pointX2; toPoint.Y = pointY2; toPoint.Z = pointZ2; IZAware toZAware = toPoint as IZAware; toZAware.ZAware = true; pPathA.FromPoint = fromPoin
23、t; pPathA.ToPoint = toPoint; pLine.PutCoords(fromPoint, toPoint); /pLine.FromPoint = fromPoint; /pLine.ToPoint = toPoint; segmentArrayi = pLine as ISegment; /處理最后一段線 if (dataRow2.Cellsname.Value.ToString().Length = 0 & i = excelDataGridViewX.Rows.Count - 2) IGeometryCollection seColletion = new Poly
24、lineClass(); ISpatialReference psRef = new UnknownCoordinateSystemClass(); ISegmentCollection pathCollection = new PolylineClass(); IGeometry pGeometry = seColletion as PolylineClass; pGeometry.SpatialReference = psRef; ILine line = segmentArray0 as ILine; object o1 = Type.Missing; object o2 = Type.
25、Missing; for (int m = nStartI; m segmentArray.Length; m+) /IZAware iPolylineAware = (IZAware)(segmentArraym as IPolyline); /iPolylineAware.ZAware = true; pathCollection.AddSegment(segmentArraym, ref o1, ref o2); pGeometry = pathCollection as IGeometry; seColletion.AddGeometryCollection(pGeometry as
26、IGeometryCollection); IFeature pFeature = pFeatureClass.CreateFeature(); pFeature.Shape = (seColletion as IGeometry); pFeature.set_Value(pFeature.Fields.FindField(name), strname); pFeature.Store(); continue; /添加新建的數(shù)據(jù)至Map中 axMapControl.AddShapeFile(filePath, fileName); this.Hide(); MessageBox.Show(Ex
27、cel轉(zhuǎn)換shp完畢!); catch (Exception ex) MessageBox.Show(ex.Message); public void CreatePolylineZMShp() try IWorkspaceFactory pShpWksFact = new ShapefileWorkspaceFactory(); IFeatureWorkspace pFeatWks; pFeatWks = (IFeatureWorkspace)pShpWksFact.OpenFromFile(filePath, 0); IFeatureClass pFeatureClass; pFeatur
28、eClass = CreateFeatureClassFromFactory(pFeatWks, fileName,true); ISegment segmentArray = new ISegmentexcelDataGridViewX.Rows.Count - 1; string strname = ; /每條線的名稱 int nStartI = 0; /每條線的起始位置 /繪制線 for (int i = 0; i 0) IGeometryCollection seColletion = new PolylineClass(); ISpatialReference psRef = new
29、 UnknownCoordinateSystemClass(); ISegmentCollection pathCollection = new PolylineClass(); IGeometry pGeometry = seColletion as PolylineClass; pGeometry.SpatialReference = psRef; ILine line = segmentArray0 as ILine; object o1 = Type.Missing; object o2 = Type.Missing; for (int m = nStartI; m segmentAr
30、ray.Length; m+) if (segmentArraym = null) continue; pathCollection.AddSegment(segmentArraym, ref o1, ref o2); /IZAware ipathColAware = (IZAware)pathCollection as IZAware; /ipathColAware.ZAware = true; pGeometry = (IGeometry)pathCollection;/ as IGeometry; /IZAware iGeometryAware = (IZAware)pGeometry
31、as IZAware; /iGeometryAware.ZAware = true; IZAware iseColle = (IZAware)seColletion as IZAware; iseColle.ZAware = true; seColletion.AddGeometryCollection(pGeometry as IGeometryCollection); IFeature pFeature = pFeatureClass.CreateFeature(); pFeature.Shape = (seColletion as IGeometry); pFeature.set_Val
32、ue(pFeature.Fields.FindField(name), strname); pFeature.Store(); strname = dataRow2.Cellsname.Value.ToString(); nStartI = i + 1; continue; double pointX2, pointY2, pointZ2; pointX2 = double.Parse(dataRow2.CellsxComboBoxEx.Text.Value.ToString(); pointY2 = double.Parse(dataRow2.CellsyComboBoxEx.Text.Value.ToString(); pointZ2 = double.Parse(dataRow2.CellszComboBoxEx.Text.Value.ToString(); IPoint fromPoint = new PointClass(); IPoint toPoint = new PointClass(); ILine pLine = new LineClass(
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 科技教育在課堂中的有效運(yùn)用計(jì)劃
- 社區(qū)團(tuán)結(jié)互助的活動示范計(jì)劃
- 《大方縣宏能能源開發(fā)有限公司貴州省大方縣金沙煤田巖腳-白花塔井田煤礦(新建)礦產(chǎn)資源綠色開發(fā)利用方案(三合一)》評審意見
- 2025年美麗的大自然標(biāo)準(zhǔn)教案合集
- 規(guī)范化銷售培訓(xùn)
- 個人年終總結(jié)培訓(xùn)
- 透析患者導(dǎo)管感染護(hù)理
- Unit 5 Lesson 28 The Study of Living Things2024-2025學(xué)年九年級英語上冊同步教學(xué)設(shè)計(jì)(冀教版)河北專版
- 2025年安徽貨運(yùn)從業(yè)資格證考試500題題庫
- 高中數(shù)學(xué) 第一章 空間幾何體 1.2 空間幾何體的三視圖和直觀圖 1.2.3 空間幾何體的直觀圖教學(xué)實(shí)錄 新人教A版必修2
- 2025年湖南商務(wù)職業(yè)技術(shù)學(xué)院單招職業(yè)技能測試題庫必考題
- 中儲糧黑龍江分公司招聘考試試卷2023
- 化學(xué)實(shí)驗(yàn)室安全職責(zé)分配
- 9 楓樹上的喜鵲 【知識精研】語文二年級下冊 統(tǒng)編版
- 2025年工程策劃勘察設(shè)計(jì)合作框架協(xié)議書
- 2025年哈爾濱鐵道職業(yè)技術(shù)學(xué)院高職單招語文2018-2024歷年參考題庫頻考點(diǎn)含答案解析
- 國外銀發(fā)經(jīng)濟(jì)發(fā)展
- 2025年高考作文素材積累之《人民日報》時評觀點(diǎn)摘抄(標(biāo)題、開頭、分論點(diǎn)、結(jié)尾)
- 2024年07月上海興業(yè)銀行上海分行招考筆試歷年參考題庫附帶答案詳解
- 中藥玫瑰花培訓(xùn)
- 廣東省佛山市(2024年-2025年小學(xué)六年級語文)統(tǒng)編版小升初真題((上下)學(xué)期)試卷及答案
評論
0/150
提交評論