GIS开发作业4—获取工作空间所有图层记录值及字段信息

界面需要自己设计出来,代码功能为遍历所有的图层,较为简单,作业要求只需要部分核心代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using SuperMapLib;
using System.Runtime.InteropServices;

namespace test4
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void connectSupermap()
        {
            object objHandle = axSuperWorkspace1.ObjectHandle;
            axSuperMap1.Connect(objHandle);
            Marshal.ReleaseComObject(objHandle);        
        }

        private void menu_file_openWorkspace_Click(object sender, EventArgs e)
        {
            openFileDialog1.Filter = "(*.smw)|*.smw";
            openFileDialog1.FileName = "";
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                string path = openFileDialog1.FileName;
                bool flag = axSuperWorkspace1.Open(path, "");
                if (flag)
                {
                    MessageBox.Show("打开成功");
                    connectSupermap();
                }
                else
                {
                    MessageBox.Show("打开失败");
                }
            }
        }

        private void getDataToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int sourcesCount = axSuperWorkspace1.Datasources.Count;
            for (int i = 1; i <= sourcesCount; i++)
            {
                soDatasets dataSets = axSuperWorkspace1.Datasources[i].Datasets;
                int num = dataSets.Count;
                for (int j = 1; j <= num; j++)
                {
                    string s = dataSets[j].Name;
                    axSuperMap1.Layers.AddDataset(dataSets[j], true);
                    axSuperMap1.Refresh();
                    MessageBox.Show(s);
                }
            }
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            System.Diagnostics.Process.GetCurrentProcess().Kill();
        }
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值