zoukankan      html  css  js  c++  java
  • 线面采集操作消息体封装与解译

    项目:基于GIS操作语义的协作制图系统

    需求:将线面封装,写入和读取XML

    1 修订XML结构

    <Project ID="">
        <CooperationMap ID="">
            <Layer Name="" Type="">
                <esriGeometryType ID="" Operation="">
                    <Point></Point>
                    <Point></Point>
                </esriGeometryType>
            </Layer>
        </CooperationMap>
    </Project>

     增添了PointCollectionID属性,作为几何图形唯一识别,每次消息体再客户端解译后会再次生成新的XML,使用PointCollection作为XML文件命名(目前使用时间命名)。

    2 几何图像的绘制采集

    使用 INewPolygonFeedback 和 INewLineFeedback 接口获取,目前实在 axMapControl 的鼠标交互事件内写的,暂未封装成 Command 和 Tool ,然后再转成PointCollection。

    3 封装与解译

    3.1 封装

    去除 IEngineEditEvents_Event 草图完成事件,这个事件需要鼠标焦点离开编辑中的几何图形才生效。

    public void WriteXML(string absolutePath)
    {
        IPoint pnt = PointCollection.get_Point(0);
        //创建节点
        XElement project = new XElement("Project",
            new XAttribute("ID", this.ProjectID));
        XElement cooperationMap = new XElement("CooperationMap",
            new XAttribute("ID", this.CooperationMapID));
        XElement layer = new XElement("Layer",
            new XAttribute("Name", this.LayerName),
            new XAttribute("Type", this.LayerType));
        XElement geometry = new XElement(LayerType.ToString(),
                new XAttribute("ID", this.PointCollectionID),
                new XAttribute("Operation", this.OperationEnum));
        for (int i = 0; i < PointCollection.PointCount; i++)
        {
            pnt = PointCollection.get_Point(i);
            XElement point = new XElement("Point", pnt.X, " ", pnt.Y);
            geometry.Add(point);
        }
        //添加节点
        project.Add(cooperationMap);
        cooperationMap.Add(layer);
        layer.Add(geometry);
        //保存
        project.Save(absolutePath);
    }

    3.2 解译

    读取XML的PointCollection的实例化要和几何图形类型(esriGeometryType)要对应;草图工具 IEngineEditSketch 的点的添加为 pEnginEditSketch.AddPoint(point, true); ,线面则是将PointCollection赋值给 pEnginEditSketch.Geometry ,然后调用 pEnginEditSketch.FinishSketch(); 

    public void ReadXML(string absolutePath)
    {
        //加载文档
        XDocument document = XDocument.Load(absolutePath);
        //获取参数
        XElement project = document.Root;
        ProjectID = project.Attribute("ID").Value;
        XElement cooperationMap = project.Element("CooperationMap");
        CooperationMapID = cooperationMap.Attribute("ID").Value;
        XElement layer = cooperationMap.Element("Layer");
        LayerName = layer.Attribute("Name").Value;
        LayerType = (esriGeometryType)Enum.Parse(typeof(esriGeometryType),
            layer.Attribute("Type").Value);
        XElement geometry = layer.Element(LayerType.ToString());
        PointCollectionID = geometry.Attribute("ID").Value;
        OperationEnum = (OperationEnum)Enum.Parse(typeof(OperationEnum),
            geometry.Attribute("Operation").Value);
        //获取点集
        string[] sPoint;
        IPoint point = new PointClass();
        PointCollection = point as IPointCollection;
        if (LayerType == esriGeometryType.esriGeometryPoint)
            PointCollection = new MultipointClass();
        else if (LayerType == esriGeometryType.esriGeometryPolyline)
            PointCollection = new PolylineClass();
        else
            PointCollection = new PolygonClass();
        IEnumerable<XElement> pointcollection = geometry.Elements();
        foreach (XElement pnt in pointcollection)
        {
            sPoint = pnt.Value.Split(' ');
            point.X = double.Parse(sPoint[0]);
            point.Y = double.Parse(sPoint[1]);
            this.PointCollection.AddPoint(point);
        }
    }
  • 相关阅读:
    按钮在点击的时候,怎么取消按钮中的文本被选中
    JS观察者模式-自定义事件
    DIV中文字换行显示
    JS、CSS中的相对路径
    监听窗口大小改变,同时根据窗口大小修改某个元素的大小
    jquery中点击切换的实现
    lua_自己对“lua函数”知识点的总结
    Lua习题练习(9*9乘法表,输出所指定的图像,斐波那契数列)
    对 Lua闭包 知识点的学习的总结 ,在这里和大家分享一下,希望对大家有所帮助
    Lua的string库函数、lua中string的模式匹配
  • 原文地址:https://www.cnblogs.com/liuwenzhen/p/12779775.html
Copyright © 2011-2022 走看看