已阅读5页,还剩11页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Excel列表坐标点转成带Z值的shape点文件和线文件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 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, DataGridView _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(addFieldListBox.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) for (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 sender, EventArgs e) switch (shpTypeComboBox.Text) case Point: CreatPointShp(); break; case Polyline: CreatePolylineShp(); break; case PolylineZM: CreatePolylineZMShp(); break; default: MessageBox.Show(请选择创建的shp类型!); break; public void CreatPointShp() try IWorkspaceFactory pShpWksFact = new ShapefileWorkspaceFactory(); 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 pFieldEdit = 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 = 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: pGeomDefEdit.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 = pFieldsEdit 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 IFieldEdit; pfieldEdit.Name_2 = addFieldListBox.Itemsi.ToString(); pfieldEdit.Type_2 = esriFieldType.esriFieldTypeString; pfield = pfieldEdit as IField; pFeatureClass.AddField(pfield); /绘制点 for (int i = 0; i excelDataGridViewX.Rows.Count - 1; i+) DataGridViewRow dataRow = excelDataGridViewX.Rowsi; 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; /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; /为该点添加属性值 for (int j = 0; j addFieldListBox.Items.Count; j+) string fieldName = addFieldListBox.Itemsj.ToString(); pFeature.set_Value(pFeature.Fields.FindField(fieldName), dataRow.CellsfieldName.Value.ToString(); pFeature.Store(); /添加新建的数据至Map中 axMapControl.AddShapeFile(filePath, fileName); this.Hide(); MessageBox.Show(Excel转换shp完毕!); catch (Exception ex) MessageBox.Show(ex.Message); public void CreatePolylineShp() try IWorkspaceFactory pShpWksFact = new ShapefileWorkspaceFactory(); IFeatureWorkspace pFeatWks; pFeatWks = (IFeatureWorkspace)pShpWksFact.OpenFromFile(filePath, 0); IFeatureClass pFeatureClass; pFeatureClass = CreateFeatureClassFromFactory(pFeatWks, 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(); 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 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 IGeometryCollection); IFeature pFeature = pFeatureClass.CreateFeature(); pFeature.Shape = (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 = 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 PolylineClass(); 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 = fromPoint; 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 PolylineClass(); 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.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 IGeometryCollection); IFeature pFeature = pFeatureClass.CreateFeature(); pFeature.Shape = (seColletion as IGeometry); pFeature.set_Value(pFeature.Fields.FindField(name), strname); pFeature.Store(); continue; /添加新建的数据至Map中 axMapControl.AddShapeFile(filePath, fileName); this.Hide(); MessageBox.Show(Excel转换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; pFeatureClass = 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 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 segmentArray.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 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_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 = 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. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 中国各类电子零件项目投资可行性研究报告
- 集光机行业深度研究报告
- 中国牵引钩钳项目投资可行性研究报告
- 高纯草酸行业深度研究报告
- 纯古仿古建筑施工行业深度研究报告
- 2026年钻头市场前景分析
- 声光显示指示报警仪行业深度研究报告
- 双层叉车行业深度研究报告
- 数字图标机行业深度研究报告
- 刹车油壶总成行业深度研究报告
- 台湾大学欧丽娟老师的中国文学史讲义
- 突发环境事件预案演练脚本及总结
- 电气控制与plc应用技术课件
- 苏教版小学英语单词汇总译林版级完整版
- Q-CR 783.1-2021 铁路通信网络安全技术要求 第1部分:总体技术要求
- 纺织商务英语课件
- YY/T 0308-2015医用透明质酸钠凝胶
- 华北理工大学材料力学刘文增第五版第5章 弯曲应力
- GB/T 19000-2016质量管理体系基础和术语
- 身份证原件使用承诺书
- 幼儿园绘本+《不要随便亲我》
评论
0/150
提交评论