标签:提取 empty tab 百度云 思路 赋值 ref sum 技术分享
信息提取和解译的过程中,经常会生成一部分中间临时矢量数据,这些数据在执行完对应操作后就失去了存在的价值,针对这种情况,PIE增加了内存矢量数据集,来协助用户完成对自定义矢量数据的读取和显示。
下面以Micaps1类数据为例介绍自定义矢量数据的构建和显示。
第一步 |
构建数据的字段、空间参考等信息; |
第二步 |
根据字段和空间参考信息创建内存矢量数据集; |
第三步 |
在内存矢量数据集中逐条添加数据记录(包括几何图形和属性); |
第四步 |
通过内存数据集创建矢量图层; |
第五步 |
添加第四步中的图层到地图,并刷新; |
接口/类 |
方法 |
说明 |
IField |
构造函数 |
构造字段 |
IFields |
AddField () |
添加字段 |
DatasetFactory |
CreateFeatureDataset |
创建数据集 |
IFeatureDataset |
CreateNewFeature() |
创建要素 |
AddFeature() |
添加要素 |
|
IFeature |
SetValue() |
属性赋值 |
项目名称 |
百度云盘地址下/PIE示例程序/10.打开自定义矢量数据 |
项目位置 |
百度云盘地址下/矢量数据/Micaps/micaps1下数据 |
代码位置 |
百度云盘地址下/PIE视频教程/10. 打开自定义矢量数据.avi |
示例代码 |
|
1 方法(一)打开自定义矢量数据 2 //以解析Micaps1数据为例 3 OpenFileDialog openFileDialog = new OpenFileDialog(); 4 openFileDialog.Filter = "Micaps文件(*.000)|*.000"; 5 if (openFileDialog.ShowDialog() == DialogResult.OK) 6 { 7 IFeatureLayer defineLayer = OpenDefineShp(openFileDialog.FileName); 8 if (defineLayer != null) 9 { 10 (defineLayer as ILayer).Name = "自定义矢量图层"; 11 mapControlMain.FocusMap.AddLayer(defineLayer as ILayer); 12 mapControlMain.ActiveView.PartialRefresh(ViewDrawPhaseType.ViewAll); 13 } 14 } 15 /// <summary> 16 /// 解析自定义数据,生成矢量 17 /// 以解析Micaps1数据为例,字段只添加站号、经度、纬度、海拔高度 18 /// </summary> 19 /// <param name="filePath">输出SHP文件路径</param> 20 /// <returns></returns> 21 private IFeatureLayer OpenDefineShp(string filePath) 22 { 23 IFeatureLayer featureLayer = null; 24 int count = 0;//记录读取数据的行数 25 string[] lineValues = null;//每一行的数据值 26 //字段声明 27 IField field_id = new Field("PointID", FieldType.OFTInteger, 20, 4); 28 field_id.AliasName = "站号"; 29 30 IField field_x = new Field("lon", FieldType.OFTInteger, 20, 4); 31 field_x.AliasName = "经度"; 32 33 IField field_y = new Field("lat", FieldType.OFTInteger, 20, 4); 34 field_y.AliasName = "纬度"; 35 36 IField field_h = new Field("height", FieldType.OFTInteger, 20, 4); 37 field_h.AliasName = "海拔高度"; 38 39 IFields fields = new Fields(); 40 fields.AddField(field_id); 41 fields.AddField(field_x); 42 fields.AddField(field_y); 43 fields.AddField(field_h); 44 //建立内存数据集 45 IFeatureDataset pDataset = PIE.DataSource.DatasetFactory.CreateFeatureDataset("", fields, GeometryType.GeometryPoint, null, "MEM"); 46 //解析数据文件,写入数据集中 47 string[] valueLines = System.IO.File.ReadAllLines(filePath); 48 char[] charSeperate = { ‘ ‘ }; 49 for (int j = 0; j < valueLines.Length; j++) 50 { 51 string str = valueLines[j]; 52 if (count == 0 || count == 1) 53 { 54 count = count + 1; 55 continue; 56 } 57 //解析字符串,生成Feature 58 IFeature newFeature = pDataset.CreateNewFeature(); 59 lineValues = str.Split(charSeperate, StringSplitOptions.RemoveEmptyEntries); 60 //字段赋值 61 newFeature.SetValue(0, Convert.ToInt32(lineValues[0])); 62 newFeature.SetValue(1, Convert.ToDouble(lineValues[1])); 63 newFeature.SetValue(2, Convert.ToDouble(lineValues[2])); 64 newFeature.SetValue(3, Convert.ToDouble(lineValues[3])); 65 66 //生成Geometry 67 IPoint point = new PIE.Geometry.Point(); 68 point.PutCoords(Convert.ToDouble(lineValues[1]), Convert.ToDouble(lineValues[2])); 69 newFeature.Geometry = point as IGeometry; 70 pDataset.AddFeature(newFeature); 71 count = count + 1; 72 (newFeature as IDisposable).Dispose(); 73 } 74 featureLayer = PIE.Carto.LayerFactory.CreateDefaultFeatureLayer(pDataset); 75 return featureLayer; 76 } |
标签:提取 empty tab 百度云 思路 赋值 ref sum 技术分享
原文地址:https://www.cnblogs.com/PIESat/p/10145048.html