using System; using System.Collections.Generic; using System.Linq; using System.Text; using GeoScene.Data; using GeoScene.Globe; using GeoScene.Engine; using System.Windows.Forms; namespace Cyberpipe { class FeatureStatisticsService { /// <summary> /// 统计指定图层在指定范围内的所有feature对象 /// </summary> /// <param name="polygon"></param> /// <param name="layer"></param> /// <param name="type"></param> /// <returns></returns> public static GSOFeatures Intersect_PointLayerByType(GSOGeoPolygon3D polygon, GSOLayer layer, string type) { if (layer == null) return null; GSOFeatureLayer flayer = layer as GSOFeatureLayer; if (polygon == null) { return flayer.GetFeatureByFieldValue("附属物名称", type, true); } GSOFeatures feats = flayer.FindFeaturesInPolygon(polygon, false); GSOFeatures newfeats = new GSOFeatures(); for (int j = 0; j < feats.Length; j++) { if (feats[j].GetFieldAsString("附属物名称").EndsWith(type)) { newfeats.Add(feats[j]); } } return newfeats; } /// /// <summary> /// 根据附属物列表,统计该类附属物个数 /// </summary> ///<param name="feats">附属物列表</param> /// <returns></returns> public Dictionary<string, int> getFeatureCountByFeatures(GSOFeatures feats) { if (feats == null || feats.Length == 0) return null; Dictionary<string, int> result = new Dictionary<string, int>(); result.Add(feats[0].GetFieldAsString("附属物名称"), feats.Length); return result; } /// <summary> /// 获取指定图层、范围以及上下限的管线信息 /// </summary> /// <param name="polygon"></param> /// <param name="layer"></param> /// <param name="minDepth"></param> /// <param name="maxDepth"></param> /// <param name="fieldName"></param> /// <returns></returns> public FeaturesClassfyResult getPipesInfoByValueSection(GSOGeoPolygon3D polygon, GSOLayer layer, double? min, double? max, string fieldName) { if (layer == null) return null; FeaturesClassfyResult result = new FeaturesClassfyResult(); double totalLength = 0.0; int ncount = 0; GSOFeatures features = getPipesByValueSection(polygon, layer, min, max, fieldName); for (int i = 0; i < features.Length; i++) { GSOGeoPolyline3D line = features[i].Geometry as GSOGeoPolyline3D; double length = line.GetSpaceLength(true, 6378137); totalLength += length; ncount += 1; } string filedValue = (min == null) ? "不限" : min + "-"; filedValue += (max == null) ? "不限" : max + ""; result.layerName = layer.Caption; result.groupFieldValue = filedValue;//上下限的拼接 result.ncount = ncount; result.sum = Math.Round(totalLength, 2); return result; } /// <summary> /// 根据绘制区域、图层以及上下限获取满足条件的管线列表 /// </summary> /// <param name="polygon">绘制的区域,为空则表示全区域统计</param> /// <param name="layer">所选的图层</param> /// <param name="min">下限</param> /// <param name="max">上限</param> /// <param name="fieldName">统计类型:"起始埋深"或"管径_毫米"</param> /// <returns></returns> public GSOFeatures getPipesByValueSection(GSOGeoPolygon3D polygon, GSOLayer layer, double? min, double? max, string fieldName) { if (layer == null) return null; GSOFeatures result = new GSOFeatures(); GSOFeatureLayer flayer = layer as GSOFeatureLayer; //TODOLIST:优化为只获取管线,目前不清楚调用方式 GSOFeatures feats = (polygon == null) ? flayer.GetAllFeatures() : flayer.FindFeaturesInPolygon(polygon, false); double minValue = min ?? Double.MinValue; double maxValue = max ?? Double.MaxValue; //筛选出符合条件的 for (int i = 0; i < feats.Length; i++) { double radius = feats[i].GetFieldAsDouble(fieldName); if (radius >= min && radius <= max) { result.Add(feats[i]); } } return result; } //图层名称、管径、条数、总长度 public List<FeaturesClassfyResult> groupPipeByDiameter(GSOGeoPolygon3D polygon, GSOLayer layer) { if (layer == null) return null; List<FeaturesClassfyResult> result = new List<FeaturesClassfyResult>(); GSOFeatureLayer flayer = layer as GSOFeatureLayer; //TODOLIST:优化为只获取管线,目前不清楚调用方式 GSOFeatures feats = (polygon == null) ? flayer.GetAllFeatures() : flayer.FindFeaturesInPolygon(polygon, false); List<float> lstDiameter = new List<float>(); for (int j = 0; j < feats.Length; j++) { if (!lstDiameter.Contains(feats[j].GetFieldAsFloat("管径_毫米"))) { lstDiameter.Add(feats[j].GetFieldAsFloat("管径_毫米")); } } lstDiameter.Sort(); if (lstDiameter.Count > 0) { for (int m = 0; m < lstDiameter.Count; m++) { double totalLength = 0.00; int ncount = 0; for (int j = 0; j < feats.Length; j++) { if (feats[j].GetFieldAsFloat("管径_毫米") == lstDiameter[m]) { GSOGeoPolyline3D line = feats[j].Geometry as GSOGeoPolyline3D; double length = line.GetSpaceLength(true, 6378137); totalLength += length; ncount += 1; } } FeaturesClassfyResult featuresClass = new FeaturesClassfyResult(); featuresClass.layerName = layer.Caption; featuresClass.groupFieldValue = lstDiameter[m].ToString(); featuresClass.ncount = ncount; featuresClass.sum = Math.Round(totalLength, 2); result.Add(featuresClass); } } return result; } //图层名称、附属物个数 /// <summary> /// 分类统计图层中附属物个数 /// </summary> /// <param name="polygon"></param> /// <param name="layer"></param> /// <returns></returns> public List<FeaturesClassfyResult> groupAccessories(GSOGeoPolygon3D polygon, GSOLayer layer) { if (layer == null) return null; List<FeaturesClassfyResult> result = new List<FeaturesClassfyResult>(); GSOFeatureLayer flayer = layer as GSOFeatureLayer; //layer.Name是表名 string[] accessStrs = Utility.getAccStrsByLayer(layer.Name); for (int j = 0; j < accessStrs.Length; j++) { GSOFeatures feats = null; int ncount = 0; if (polygon == null) { feats = flayer.GetFeatureByFieldValue("附属物名称", accessStrs[j], true); ncount = feats.Length; } else { feats = flayer.FindFeaturesInPolygon(polygon, false); GSOFeatures newfeats = new GSOFeatures(); //过滤 for (int n = 0; n < feats.Length; n++) { if (feats[n].GetFieldAsString("附属物名称").Contains(accessStrs[j])) newfeats.Add(feats[n]); } ncount = newfeats.Length; } FeaturesClassfyResult featuresClass = new FeaturesClassfyResult(); featuresClass.layerName = accessStrs[j]; featuresClass.ncount = ncount; result.Add(featuresClass); } return result; } /// <summary> /// 统计指定材质的管线信息 /// </summary> /// <param name="polygon"></param> /// <param name="layer"></param> /// <param name="material">材质</param> /// <returns></returns> public FeaturesClassfyResult groupPipeByMaterial(GSOGeoPolygon3D polygon, GSOLayer layer, string material) { if (layer == null) return null; FeaturesClassfyResult result = new FeaturesClassfyResult(); GSOFeatureLayer flayer = layer as GSOFeatureLayer; //TODOLIST:优化为只获取管线,目前不清楚调用方式 GSOFeatures feats = (polygon == null) ? flayer.GetAllFeatures() : flayer.FindFeaturesInPolygon(polygon, false); string fixedMaterial = material == "无" ? "" : material; double totalLength = 0.00; int ncount = 0; for (int i = 0; i < feats.Length; i++) { if (feats[i].GetFieldAsString("材质").Equals(fixedMaterial)) { GSOGeoPolyline3D line = feats[i].Geometry as GSOGeoPolyline3D; if (line != null) { double length = line.GetSpaceLength(true, 6378137); totalLength += length; ncount += 1; } } } result.layerName = layer.Caption; result.groupFieldValue = material; result.ncount = ncount; result.sum = totalLength; return result; } } }