




已阅读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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- GB/T 46122.2-2025烟花爆竹特定化学物质检测方法第2部分:六氯代苯含量的测定气相色谱法
- 2025咨询工程师自我提分评估含答案详解【A卷】
- 应急安全培训致辞稿件课件
- 打包站转让合同(标准版)
- 农村折屋合同(标准版)
- 国外的进口合同(标准版)
- 2024-2025学年度制冷与空调作业能力检测试卷及完整答案详解(典优)
- 2025自考专业(金融)全真模拟模拟题重点附答案详解
- 中班美术教案《漂亮的大鱼》反思
- 2025年智慧生态公园规划初步设计评估与实施策略报告
- 机械原理课程设计-自动盖章机
- 会议及活动拍摄技巧
- GB/T 9460-2008铜及铜合金焊丝
- GB/T 2362-1990小模数渐开线圆柱齿轮基本齿廓
- 【桂美版】六年级美术上册-六年级(桂教版)上册美术教案(详案)全
- GB/T 17238-2022鲜、冻分割牛肉
- 第四章集装箱箱务管理
- 高尔夫人群消费及行为习惯调研报告-课件
- 天气预报的发展历程课件
- 2022年国家公务员考试申论真题及答案(地市级)
- 西方法律思想史教案课件
评论
0/150
提交评论