Exemplo n.º 1
0
        public Topology(GeomLayer _parent)
        {
            parent          = _parent;
            parent.topology = this;

            originArcs = new Dictionary <GeomPoint, List <GeomArc> >();
            arcLeft    = new Dictionary <GeomArc, GeomPoly>();
            arcRight   = new Dictionary <GeomArc, GeomPoly>();

            // 点:起始弧段
            foreach (var arc in parent.arcs)
            {
                foreach (var pt in arc.points)
                {
                    AddList(originArcs, pt, arc);
                }
            }

            // 弧段:左右多边形
            foreach (var poly in parent.polygons)
            {
                DumpPoly(poly, poly.Clockwise);
                if (poly.holes != null)
                {
                    foreach (var hole in poly.holes)
                    {
                        DumpPoly(hole, !hole.Clockwise);
                    }
                }
            }
        }
Exemplo n.º 2
0
        // 栅格/TIN图层等值线
        public static GeomLayer Value2Contour(ValueLayer layer, IEnumerable <double> targetSplits, string postFix = "")
        {
            List <GeomPoint> points = null;
            List <GeomArc>   arcs   = null;

            // 执行搜索算法
            switch (layer)
            {
            case GridLayer layer1:
                Contour.GenContourGrid(layer1.data, targetSplits, out points, out arcs);
                break;

            case TINLayer layer1:
                Contour.GenContourTIN(layer1.edgeSides, layer1.values, targetSplits, out points, out arcs);
                break;

            default:
                return(null);
            }

            // 创建图层
            var result = new GeomLayer(GeomType.Arc, layer.Name + "_等值线" + postFix)
            {
                points = points,
                arcs   = arcs
            };

            // 默认样式
            result.colors["arc"] = ColorOps.Random();
            result.SetPartVisible("point", false);

            return(result);
        }
        public LayerSettingsGeom(GeomLayer layer)
        {
            InitializeComponent();
            origin = layer;
            LayerSettings.BindTitle(layer, layerName, this);
            LayerSettings.BindColor(layer, button1, "point", splitContainer1.Panel1);
            LayerSettings.BindColor(layer, button2, "arc", splitContainer2.Panel1);
            LayerSettings.BindColor(layer, button3, "polygon", splitContainer3.Panel1);
            LayerSettings.BindSize(layer, numericUpDown1, "point");
            LayerSettings.BindSize(layer, numericUpDown2, "arc");

            // 绑定清除多边形颜色功能
            button4.Click += (object o, EventArgs e) => {
                splitContainer3.Panel1.BackColor = origin.colors["polygon"] = Color.Empty;
                MainForm.port.Render();
            };

            // 禁用图层缺失部分
            if (layer.points == null)
            {
                splitContainer1.Enabled = false;
            }
            if (layer.arcs == null)
            {
                splitContainer2.Enabled = false;
            }
            if (layer.polygons == null)
            {
                splitContainer3.Enabled = false;
            }
        }
Exemplo n.º 4
0
        // 从三角序列创建矢量图层
        static GeomLayer FromTriangles(IEnumerable <Triangle> triangles, List <GeomPoint> originalPoints)
        {
            // 创建字典用于反查
            var pt_mapper = new Dictionary <Vector2, GeomPoint>();

            foreach (GeomPoint tmp in originalPoints)
            {
                pt_mapper[tmp] = tmp;
            }

            // 构造矢量图层
            GeomLayer result = new GeomLayer(GeomType.Polygon);
            var       g_points = new Dictionary <Vector2, GeomPoint>();
            var       g_arcs = new Dictionary <Edge, GeomArc>();
            int       point_cnt = 0, arc_cnt = 0, poly_cnt = 0;

            foreach (Triangle tri in triangles)
            {
                // 按需创建点
                foreach (Vector2 tmp in tri.Points())
                {
                    if (!g_points.ContainsKey(tmp))
                    {
                        var new_point = pt_mapper[tmp].Copy(); // 反查原始数据
                        new_point.id  = ++point_cnt;
                        g_points[tmp] = new_point;
                    }
                }

                // 去重获取三边
                var arcs = new List <GeomArc>();
                foreach (var tmp in tri.Edges())
                {
                    GeomArc cur_arc;
                    if (g_arcs.ContainsKey(tmp))
                    {
                        cur_arc = g_arcs[tmp];
                    }
                    else
                    {
                        cur_arc     = new GeomArc(new GeomPoint[] { g_points[tmp.Item1], g_points[tmp.Item2] }, ++arc_cnt);
                        g_arcs[tmp] = g_arcs[tmp.Reverse()] = cur_arc;
                    }
                    arcs.Add(cur_arc);
                }

                // 创建三角形
                GeomPoly tri_poly = new GeomPoly(arcs, ++poly_cnt);
                result.polygons.Add(tri_poly);
            }

            // 加入点集、边集
            result.points.AddRange(g_points.Values);
            result.arcs.AddRange(g_arcs.Values);

            return(result);
        }
Exemplo n.º 5
0
        // 等值线图层生成拓扑多边形
        public static GeomLayer Arc2Topology(GeomLayer layer)
        {
            GeomLayer newLayer = new GeomLayer(GeomType.Polygon, layer.Name + "_拓扑");

            GenTopology.Entry(layer.arcs, layer.MBR, out newLayer.points, out newLayer.arcs, out newLayer.polygons);
            new Topology(newLayer); // 生成拓扑记录

            return(newLayer);
        }
Exemplo n.º 6
0
        // 导出图层拓扑关系至文件
        public static bool ExportTopology(GeomLayer layer)
        {
            var dial = new SaveFileDialog();

            dial.Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*";
            if (dial.ShowDialog() == DialogResult.OK)
            {
                using (var fs = new FileStream(dial.FileName, FileMode.Create))
                {
                    var writer = new StreamWriter(fs);
                    layer.topology.ExportContent(writer);
                    writer.Flush();
                }
                return(true);
            }
            return(false);
        }
Exemplo n.º 7
0
        // 点图层转栅格
        public static GridLayer Point2Grid(GeomLayer layer, string method,
                                           double xmin, double xmax, double ymin, double ymax,
                                           uint xsplit, uint ysplit)
        {
            Grid result = new Grid(xmin, xmax, ymin, ymax, xsplit, ysplit);

            switch (method)
            {
            case "方位取点加权法": result.GenGrid_DirGrouped(layer.points); break;

            case "距离倒数法": result.GenGrid_DistRev(layer.points); break;

            case "距离平方倒数法": result.GenGrid_DistPow2Rev(layer.points); break;
            }

            // 创建图层
            return(new GridLayer(result, layer.Name + "_" + method));
        }
Exemplo n.º 8
0
        // 导入CSV为多点对象
        private void ImportPoints(object sender = null, EventArgs e = null)
        {
            // 创建图层
            GeomLayer newLayer = new GeomLayer(GeomType.Point, filePath.Text);

            CSVParser.OutputPoints(
                table, newLayer.points, readHeader.Checked,
                (int)selectX.SelectedValue, (int)selectY.SelectedValue, (int)selectValue.SelectedValue,
                (int)selectID.SelectedValue, (int)selectName.SelectedValue
                );

            // 判断是否成功
            if (newLayer.points.Count > 0)
            {
                newLayer.Add(LayerTag.Points);
            }
            else
            {
                MessageBox.Show("图层为空", "插入失败");
            }

            // 关闭窗口
            Close();
        }
Exemplo n.º 9
0
        // 等值线光滑
        public static GeomLayer ContourSmooth(GeomLayer layer)
        {
            // 逐个平滑转换
            List <double> values   = new List <double>();
            var           raw_arcs = new List <TensionSpline>();

            foreach (var arc in layer.arcs)
            {
                raw_arcs.Add(new TensionSpline(arc.points, 200)); // 使用低精度检查相交
                values.Add(arc.value);
            }

            // 处理相交:整体增加张力
            while (true)
            {
                var crossings = new HashSet <int>();
                for (int i = 0; i < raw_arcs.Count; i++)
                {
                    for (int j = i; j < raw_arcs.Count; j++)
                    {
                        if (raw_arcs[i].Crossing(raw_arcs[j]))
                        {
                            crossings.Add(i);
                            crossings.Add(j);
                        }
                    }
                }
                if (crossings.Count == 0)
                {
                    break;
                }
                foreach (int i in crossings)
                {
                    raw_arcs[i].IncreaseTension(3);
                }
            }

            // 增加精度
            foreach (var r in raw_arcs)
            {
                r.SetDetail(1200);
            }

            // 输出至图层
            GeomLayer result = new GeomLayer(GeomType.Arc, layer.Name + "_平滑");
            int       idxPoint = 0, idxArc = 0;

            for (int i = 0; i < values.Count; i++)
            {
                var currValue = values[i];
                var newPoints = new List <GeomPoint>();
                foreach (var v in raw_arcs[i].Smooth())
                {
                    newPoints.Add(new GeomPoint(v.X, v.Y, ++idxPoint, currValue));
                }
                result.points.AddRange(newPoints);
                result.arcs.Add(new GeomArc(newPoints, ++idxArc, currValue));
            }

            // 默认样式
            result.colors["arc"] = Color.Red;
            result.sizes["arc"]  = 1;
            result.SetPartVisible("point", false);

            return(result);
        }
Exemplo n.º 10
0
 // 点图层转TIN
 public static TINLayer Point2TIN(GeomLayer layer) => new TINLayer(layer.points, layer.Name + "_TIN");