Exemplo n.º 1
0
        // 测试导入道路
        public static Form TestCase1()
        {
            var factory2 = new CadWorkspaceFactory();
            try
            {
                var path = System.IO.Path.GetDirectoryName(@"C:\Temp\Traffic\temp.dxf");
                var ws2 = factory2.OpenFromFile(path, 0) as IFeatureWorkspace;

                var fc2 = ws2.OpenFeatureClass(System.IO.Path.GetFileName(@"C:\Temp\Traffic\temp.dxf") + ":polyline");

                var cursor = fc2.Search(null, true);
                var f = cursor.NextFeature();

                var lst = new List<IPolyline>();
                while (f != null)
                {
                    var geo = f.ShapeCopy;
                    if (!(geo is IPolyline) || geo.IsEmpty == true)
                    {
                        MessageBox.Show("当前CAD文件中包含的路线类型信息不正确,请检查。", "注意");
                        Marshal.ReleaseComObject(cursor);
                        return null;
                    }
                    else
                    {
                        lst.Add(geo as IPolyline);
                    }
                    f = cursor.NextFeature();
                }
                Marshal.ReleaseComObject(cursor);

                if (lst.Count == 0)
                {
                    MessageBox.Show("当前CAD文件中不包含路线信息,请检查。", "注意");
                    return null;
                }

                RoadMerger.FragmentThreshold = 20;
                var ls = RoadMerger.SplitLine(lst);

                var factory = new AccessWorkspaceFactory();
                var ws = factory.OpenFromFile(@"C:\Temp\Traffic\db.mdb", 0) as IFeatureWorkspace;
                var fc = ws.OpenFeatureClass("AROAD");
                var historyFC = ws.OpenFeatureClass("ROADHIS");
                var nodeFC = ws.OpenFeatureClass("NODE");

                var lines = RoadMerger.QueryIntersects(ls, fc);

                var form = new ImportRoadForm(ls, fc, historyFC, nodeFC, lines);
                return form;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "注意");
                return null;
            }
        }
Exemplo n.º 2
0
        private void ImportRoad(List<IPolyline> pls)
        {
            var fc = RoadFeatureClass;
            var historyFC = RoadHistoryFeatureClass;
            var crossFC = RoadNodeFeatureClass;
            RoadMerger.FragmentThreshold = 20;
            var ls = RoadMerger.SplitLine(pls);
            m_ImportRoads.Clear();
            m_ImportRoads.AddRange(ls);
            var lines = RoadMerger.QueryIntersects(ls, fc);
            m_Crossroads.Clear();
            foreach(var line in lines)
            {
                m_Crossroads.AddRange(line.Crossings.Select(x=>x.Crossing));
            }

            /*
            var ret = RoadHelper.QueryIntersectPoints(pls, RoadFeatureClass);

            var list = ret.Where(x => x.Value == null).ToList();

            if (list.Count > 0)
            {
                var f = fc.GetFeature(list[0].Key);
                MessageBox.Show(string.Format("导入的路线与已有线路'{0}({1})'部分重合,无法完成导入", f.get_Value(f.Fields.FindField("NAME")), f.get_Value(f.Fields.FindField("NO_"))), "注意", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            var conditions = ret.Select(x => string.Format("{0} = {1}", RoadFeatureClass.OIDFieldName, x.Key));
            var fl = GetFeatureLayer(RoadName.GetLayer());

            // 选中图形
            axMapControl1.Map.ClearSelection();
            var featureSelection = fl as IFeatureSelection;
            featureSelection.SelectFeatures(
                new QueryFilter { WhereClause = string.Join(" OR ", conditions.ToArray()) },
                esriSelectionResultEnum.esriSelectionResultNew,
                false);

            // 将交点也加入显示
            m_Crossroads.Clear();
            m_Crossroads.AddRange(TransformToCrossroadInfo(ret, fc));

            m_ImportRoads = pl;

            Center(pl);*/

            axMapControl1.Refresh(esriViewDrawPhase.esriViewForeground, Type.Missing, Type.Missing);
            //axMapControl1.ActiveView.Refresh();

            var form = new ImportRoadForm(ls, fc, historyFC, crossFC, lines);
            form.Show(this);
        }