由坐标文件生成shp图层
文件 生成 坐标 图层 shp
2023-09-14 08:59:41 时间
一、坐标文件
二、实现代码
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.IO; using ESRI.ArcGIS.Controls; using ESRI.ArcGIS.Geometry; using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.Geodatabase; using ESRI.ArcGIS.DataSourcesFile; using ESRI.ArcGIS.esriSystem; namespace CreateShapefileFromText public partial class Form1 : Form public Form1() InitializeComponent(); private AxMapControl buddyMap; /// summary /// 关联地图控件 /// /summary public AxMapControl BuddyMap get { return buddyMap; } set { buddyMap = value; } string shapeFileFullName = string.Empty; string surveyDataFullName = string.Empty; List string pColumns = new List string List CPoint pCPointList = new List CPoint struct CPoint public double x; public double y; public string name;
pOFD.Title = "打开测量数据坐标文件:"; pOFD.InitialDirectory = System.IO.Directory.GetCurrentDirectory(); pOFD.Filter = "测量坐标文件(*.TXT)|*.TXT"; if (pOFD.ShowDialog() == DialogResult.OK) surveyDataFullName = pOFD.FileName; this.textBox1.Text = surveyDataFullName; private void btnSave_Click(object sender, EventArgs e) SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "Shape文件(*.shp)|*.shp"; DialogResult dialogresult = saveFileDialog.ShowDialog(); if (dialogresult == DialogResult.OK) shapeFileFullName = saveFileDialog.FileName; else shapeFileFullName = null; return; this.textBox2.Text = shapeFileFullName; /// summary /// 从测量数据中获取所有点 /// /summary /// param name="surveyDataFullName" 测量数据路径 /param /// returns 获取的点 /returns private List CPoint GetAllPoint(string surveyDataFullName) List CPoint pList = new List CPoint if (surveyDataFullName == null || surveyDataFullName == string.Empty) MessageBox.Show("选择野外测量数据!"); return null; if (!System.IO.File.Exists(surveyDataFullName)) MessageBox.Show("野外测量数据不存在!"); string strLine; char[] charArray = new char[] { , }; string[] strArray; System.IO.FileStream aFile = new System.IO.FileStream(surveyDataFullName, FileMode.Open); StreamReader sr = new StreamReader(aFile, Encoding.Default); strLine = sr.ReadLine(); strArray = strLine.Split(charArray); if (strArray.Length 0) for (int x = 0; x strArray.Length; x++) pColumns.Add(strArray[x]); else return null; strLine = sr.ReadLine(); while (strLine != null) strArray = strLine.Split(charArray); CPoint pCpoint = new CPoint(); pCpoint.x = Convert.ToDouble(strArray[0]); pCpoint.y = Convert.ToDouble(strArray[1]); pCpoint.name = strArray[2].Trim(); pList.Add(pCpoint); strLine = sr.ReadLine(); sr.Close(); catch (Exception ex) MessageBox.Show(ex.Message); return pList; /// summary /// 通过点创建shp文件 /// /summary /// param name="outfileNamePath" 输出文件路径 /param /// returns 创建的shp图层 /returns private IFeatureLayer CreateShpFromPoints(string outfileNamePath) int index = outfileNamePath.LastIndexOf(\\); string folder = outfileNamePath.Substring(0, index); shapeFileFullName = outfileNamePath.Substring(index + 1); IWorkspaceFactory pWSF = new ShapefileWorkspaceFactoryClass(); IFeatureWorkspace pFWS = (IFeatureWorkspace)pWSF.OpenFromFile(folder, 0); if(File.Exists(outfileNamePath)) IFeatureClass featureClass = pFWS.OpenFeatureClass(shapeFileFullName); IDataset pDataset = (IDataset)featureClass; pDataset.Delete(); IFields pFields = new FieldsClass(); IFieldsEdit pFieldsEdit; pFieldsEdit = (IFieldsEdit)pFields; IField pField = new FieldClass(); IFieldEdit pFieldEdit = (IFieldEdit)pField; pFieldEdit.Name_2 = "Shape"; pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry; IGeometryDef pGeometryDef = new GeometryDefClass(); IGeometryDefEdit pGDefEdit = (IGeometryDefEdit)pGeometryDef; pGDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon; pFieldEdit.GeometryDef_2 = pGeometryDef; pFieldsEdit.AddField(pField); pField = new FieldClass(); pFieldEdit = (IFieldEdit)pField; pFieldEdit.Length_2 = 20; pFieldEdit.Name_2 = pColumns[2]; pFieldEdit.Type_2 = esriFieldType.esriFieldTypeString; pFieldsEdit.AddField(pField); IFeatureClass pFeatureClass; pFeatureClass = pFWS.CreateFeatureClass(shapeFileFullName, pFields, null, null, esriFeatureType.esriFTSimple, "Shape", ""); List string pBuildingList = new List string for (int i = 0; i pCPointList.Count; i++) if(pBuildingList.Contains(pCPointList[i].name.Trim()) == false) pBuildingList.Add(pCPointList[i].name.Trim()); for (int i = 0; i pBuildingList.Count; i++) IPointCollection pPointColl = new PolygonClass(); object o = Type.Missing; for (int j = 0; j pCPointList.Count; j++) if (pCPointList[j].name.Trim() == pBuildingList[i].Trim()) IPoint pPoint = new PointClass(); pPoint.X = pCPointList[j].x; pPoint.Y = pCPointList[j].y; pPointColl.AddPoint(pPoint, ref o, ref o); if (pPointColl.PointCount 0) IClone pClone = pPointColl.get_Point(0) as IClone; IPoint pEndPoint = pClone.Clone() as IPoint; pPointColl.AddPoint(pEndPoint, ref o, ref o); IFeature pFeature = pFeatureClass.CreateFeature(); pFeature.Shape = pPointColl as IPolygon; pFeature.Store(); pFeature.set_Value(pFeature.Fields.FindField(pColumns[2]), pBuildingList[i].Trim()); pFeature.Store(); IFeatureLayer pFeatureLayer = new FeatureLayerClass(); pFeatureLayer.FeatureClass = pFeatureClass; return pFeatureLayer; private void btnCreate_Click(object sender, EventArgs e) pCPointList = this.GetAllPoint(surveyDataFullName); IFeatureLayer pFeatureLayer = CreateShpFromPoints(shapeFileFullName); pFeatureLayer.Name = "建筑物"; //this.buddyMap.Map.AddLayer(pFeatureLayer); private void btnCancel_Click(object sender, EventArgs e) this.Close(); }
三、效果图
转载:http://blog.csdn.net/foreverling/article/details/34423583
通过OpenLayers3调用TileMapServer的栅格瓦片服务与失量瓦片服务 TileMapServer是一个高性能的Web地图服务器,可以非常方便快速的将己有的失量地图发布为Web地图服务。失量地图支持shp、tab、mif三种文件格式的导入,并可以支持栅格瓦片,失量瓦片及空间信息查询等常用的web地图服务。
相关文章
- css-theme 通过一套源码生成一份包含多套皮肤配置的样式文件
- Java 动态生成 PDF 文件
- linux shell 脚本攻略学习10--生成任意大小的文件和文本文件的交集与差集详解
- ansible file模块:删除文件
- Spring MVC生成PDF文件代码示例
- 如何设置不让editplus生成bak文件
- MDK,IAR,GCC生成库文件的方法(2020-08-04)
- 打开cad文件的几种方法
- 去除文件BOM头工具
- android 如何在terminal中生成release apk文件
- pipres生成当前项目所有的依赖文件
- 【Android 逆向】Android 系统文件分析 ( 根目录下的目录和文件 | /data/ 应用和用户数据目录 | /mnt/ 挂载其它设备目录 )
- 【Android 热修复】热修复原理 ( Dex 文件拷贝后续操作 | 外部存储空间权限申请 | 执行效果验证 | 源码资源 )
- koa中上传文件到阿里云oss实现点击在线预览和下载
- 第二人生的源码分析(三十五)分析消息模板文件
- 6. 文件上传验证绕过技术总结
- pc不同分辨率引入不同css文件
- windows下,‘make‘ 不是内部或外部命令,也不是可运行的程序 或批处理文件。