MapObject shape数据操作 一

  利用MO 的GeoDataset  、DataConnection  Recordset 进行数据操作

 在MO中。使用GeoDataset对象和DataConnection 对象来连接和读取地理数据。

   GeoDataset: 是表达一个图层的地利数据的对象

 DatasetConnection对象指定一个和地理数据文件的连接,用Database 属性表示数据文件的地址。

Recordset 是Geodataset的记录集合或者查询后的数据集合

下面给一段 他们的使用  主要用于加载shp数据集并通过遍历获取线的每个节点

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MapObjects2;

namespace mo
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        public MapObjects2.MapLayer AddShape(string basepath, string fileName, bool mHasMeasure)
        {
            DataConnection dCon = new DataConnection();
            GeoDataset gSet;
            mHasMeasure = false;

            dCon.Database = basepath;

            if (dCon.Connect())
            {
                gSet = dCon.FindGeoDataset(fileName);
                if (gSet == null)
                {
                    MessageBox.Show("打开shape文件异常");
                    return null;
                }
                else
                {
                    MapLayer newLayer = new MapLayer();
                    newLayer.GeoDataset = gSet;
                    mHasMeasure = gSet.HasMeasure;
                    dCon = null;
                    gSet = null;
                    MessageBox.Show(newLayer.Records.Count.ToString());
                    return newLayer;
                }
            }
            else
            {
                dCon = null;
                gSet = null;
                return null;
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
           
           
        }
        //  h获取 图层中的每个节点 
        public void getLine(string mPath, string Name,bool fea)
        {
            Application.DoEvents();
            string txt = null;
            MapObjects2.MapLayer mLay;
            MapObjects2.Recordset mrec;
            Line mline = new Line();
            MapObjects2.Point mpt = new MapObjects2.Point(); ;
            mLay = AddShape(mPath, Name, false);
            mrec = mLay.Records;
            do
            {
                //从第一条数据开始处理
                //MessageBox.Show(mrec.Fields.Item("shape").);
                mline = mrec.Fields.Item("shape").Value ;
                MessageBox.Show(mline.Parts.Count.ToString());
               
                String mlxdm = mrec.Fields.Item("roadcode").Value.ToString();
                MessageBox.Show(mlxdm);
                if (mline.Parts.Count < 1)
                {
                    MessageBox.Show("line is nothing");
                    break;
                }
                for (int i = 0; i < mline.Parts.Count; i++)
                {
                    MapObjects2.Points   pt=   mline.Parts.Item(i) as MapObjects2.Points;

                    for (int j = 0; j < pt.Count;j++ )
                    {
                        richTextBox1.Text =  "x=" + pt.Item(j).X.ToString() + " y=" + pt.Item(j).Y.ToString() + " z=" + pt.Item(j).Z.ToString() + "\n" +richTextBox1.Text ;
                        //MessageBox.Show("x=" + pt.Item(i).X.ToString() + " y=" + pt.Item(i).Y.ToString() + " z=" + pt.Item(i).Z.ToString());
                        // MessageBox.Show( pt.ToString());
                    }
                  
                 
                   

                }
                mrec.MoveNext();
            } while (!mrec.EOF);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            getLine(Application.StartupPath + "\\layerdata", "nmg_route", true);
        }
    }
}


 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值