Excel列表坐標(biāo)點(diǎn)轉(zhuǎn)成帶Z值的shape點(diǎn)文件和線文件_第1頁
Excel列表坐標(biāo)點(diǎn)轉(zhuǎn)成帶Z值的shape點(diǎn)文件和線文件_第2頁
Excel列表坐標(biāo)點(diǎn)轉(zhuǎn)成帶Z值的shape點(diǎn)文件和線文件_第3頁
Excel列表坐標(biāo)點(diǎn)轉(zhuǎn)成帶Z值的shape點(diǎn)文件和線文件_第4頁
Excel列表坐標(biāo)點(diǎn)轉(zhuǎn)成帶Z值的shape點(diǎn)文件和線文件_第5頁
已閱讀5頁,還剩11頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(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)容里面會(huì)有圖紙預(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)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論