GIS实习报告 - 图文

2026/1/27 15:25:20

4、编译运行

7.2、右键菜单实现的基本思路如下 

1、设计图层控制的菜单。响应ContextMenuStrip菜单控件为图层添加菜单项显示属性 表菜单和删除图层菜单。该菜单是在鼠标右键点击图层时弹出的快捷菜单。

2、实现图层与图层控制菜单间的关联。响应TOCControl控件的OnMouseDown事件添加 相关代码。

private void axTOCControl1_OnMouseDown(object sender, ITOCControlEvents_OnMouseDownEvent e) {

axTOCControl1.ContextMenuStrip = null; IBasicMap map = new MapClass() ; System.Object other = null ; System.Object index = null;

esriTOCControlItem item = esriTOCControlItem.esriTOCControlItemNone;

axTOCControl1.HitTest(e.x, e.y, ref item, ref map, ref layer, ref other, ref index); if (item == esriTOCControlItem.esriTOCControlItemLayer && e.button == 2) {

System.Drawing.Point pt = new System.Drawing.Point(); pt.X = e.x; pt.Y = e.y;

pt = this.axTOCControl2.PointToScreen(pt);

this.contextMenuStrip1.Show(pt); } }

3、设计一个属性表窗体。a.添加一个属性表窗体。b.为属性表窗体添加DataGridView控件。 c.为属性表窗体编写相关代码实现图层属性信息往属性表中的添加。

1在解决方案管理器中右击选择“MyForm.cs|添加|新建项|Windows窗体”命名为 “attribute.cs”.

3.2加载控件Panel(容器)至TOCControl控件中加载控件DataGirdView(数据)至Panel(容 器)控件中并全部设置其Dock属性为Fill.

3.3双击“attribute.cs”类在代码框中引用类库并修改加载代码如下 using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.Controls; using ESRI.ArcGIS.esriSystem; using ESRI.ArcGIS.Display; using ESRI.ArcGIS.Geometry; using ESRI.ArcGIS.Output; using ESRI.ArcGIS.SystemUI; using ESRI.ArcGIS.Geodatabase; namespace MyForms {

public partial class attribute : Form {

24

private ILayer layer;

public attribute(ILayer lyr) {

InitializeComponent(); layer = lyr;

this.Text = \属性表\ }

private void attribute_Load(object sender, EventArgs e) {

} } }

try {

ITable lyrtable = (ITable)layer;

DataTable table = new DataTable(); IField field;

for (int i = 0; i < lyrtable.Fields.FieldCount; i++) {

field = lyrtable.Fields.get_Field(i); table.Columns.Add(field.Name); }

object[] values = new object[lyrtable.Fields.FieldCount]; IQueryFilter queryFilter = new QueryFilterClass(); ICursor cursor = lyrtable.Search(queryFilter, true); IRow row; while ((row = cursor.NextRow()) != null) {

for (int j = 0; j < lyrtable.Fields.FieldCount; j++) {

object ob = row.get_Value(j); values[j] = ob; }

table.Rows.Add(values); }

this.dataGridView1.DataSource = table; }

catch {

MessageBox.Show(\无法显示属性表\ this.Close(); } 25

4、建立图层控制菜单与属性表的连接实现属性表界面的显示。双击图层控制菜单上的“显 示属性表”菜单项在响应的Click事件中添加代码。 private void 打开属性表Click(object sender, EventArgs e) {

attribute AttributeForm = new attribute(layer); AttributeForm.Show(); }

private void 删除属性表ContextMenu_Click(object sender, EventArgs e) {

for (int i = 0; i < this.axMapControl1.Map.LayerCount; i++) {

if (this.axMapControl1.Map.get_Layer(i) == layer) {

this.axMapControl1.DeleteLayer(i); } } }

 5.运行。 8.打开GPS: 添加打开、关闭按纽。添加serialport控件、label控件、状态栏控件、 checkBox控件、combobox控件、textBox控件(Multiline属性改为TRUE)。

serialport控件中的DataRecevied事件中添加:

private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e) {

this.BeginInvoke(new myDelegate(showdata)); }

public void showdata()

{ //string Data = serialPort1.ReadLine(); //txtDataReceived.AppendText(Data); //txtDataReceived.ScrollToCaret();

try {

//string Data = serialPort.ReadExisting(); string Data = serialPort1.ReadLine(); txtDataReceived.AppendText(Data); txtDataReceived.ScrollToCaret();

//toolStripStatusLabel2.Text = \正接受数据\ /获取数据

if (Data.StartsWith(\))

26

{

if (!processGPSData(Data)) {

toolStripStatusLabel1.Text = \信号不稳定¨\; } } }

catch (Exception ex) {

Console.WriteLine(ex.ToString()); } }

private bool processGPSData(string str) { try {

string[] field;

field = str.Split(','); if (field[2] != \) {

//无效定位返回 //return false; }

//latitude double rawLatLng;

rawLatLng = Convert.ToDouble(field[3]);

lat = ((int)(rawLatLng / 100)) + ((rawLatLng - (((int)(rawLatLng / 100) * 100)) / 60));

if (field[4] == \) {

lat *= -1; }

//longtitude

rawLatLng = Convert.ToDouble(field[5]);

lng = ((int)(rawLatLng / 100)) + ((rawLatLng - (((int)(rawLatLng / 100) * 100)) / 60));

if (field[6] == \) {

lng *= -1; }

toolStripStatusLabel1.Text = \ + lat.ToString() + \ + lng.ToString();

if (this.record.Checked)//记录GPS数据 { recordGPSData();

27


GIS实习报告 - 图文.doc 将本文的Word文档下载到电脑
搜索更多关于: GIS实习报告 - 图文 的文档
相关推荐
相关阅读
× 游客快捷下载通道(下载后可以自由复制和排版)

下载本文档需要支付 10

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:xuecool-com QQ:370150219