目录

1 问题描述

2 问题解析

3 要点分析

3.1 ArcGIS的接口与方法

3.3 DataGridView的学习总结

3.3.1 属性设置

3.3.2 添加新行

3.3.3 绘制行号

3.3.4 点击首行或首列选中

3.3.5 选中单一的格子

4 源码实现

5 结果展示

6 参考优质博文:



1 问题描述

从栅格属性中提取分辨率信息、焦点坐标信息、参考坐标系统信息、中央子午线等

2 问题解析

3 要点分析

3.1 ArcGIS的接口与方法

主要用到的接口:

IRasterProps
IRasterBandCollection
IRasterDataset
IRasterPyramid3
IRasterBand
栅格属性列表:
列数和行数(Columns and Rows):通过IRasterProps的Width和Height属性获取
波段数量(Number of Bands):通过IRasterBandCollection接口获取(可以由IRaster对象跳转接口到此接口)
像元大小(CellSize(X,Y)):通过IRasterProps的MeanCellSize
格式(Format):通过IRasterDataset的Format属性获取
源类型(Source Type):可以通过GP工具SetRasterProperties来设置。
像素类型(Pixel Type):通过IRasterProps接口的PixelType 属性获取
像素位深(Pixel Depth):根据像素类型来判断像素位深
无数据值(NoData Value):通过IRasterProps 的NoDataValue属性获取
颜色表/色带(Colormap):通过IRaster2接口的Colormap属性获取色带
金字塔(Pyramids):通过IRasterPyramid3接口来创建、获取、删除金字塔(PS:用IRasterDataset接口跳转到IRasterPyramid3接口)
压缩(Compression):通过IRasterDataset的CompressionType属性获取压缩类型
范围(Extent):将IRasterDataset接口对象转换成IGeoDataset对象来范围信息
空间参考(Spatial Reference):1)将IRasterDataset接口对象转换成IGeoDataset对象来获取空间参考信息 2)通过IRasterProps 的属性SpatialReference获取 3)其它方法
统计(Statistics):通过IRasterBand接口的Statistics属性获取波段的统计信息
波段集合:通过IRasterBandCollection 接口来添加、删除、获取波段。

3.3 DataGridView的学习总结

3.3.1 属性设置

  • DataGridView的最后一行不显示:dataGridView1.AllowUserToAddRows = false;
  • 自动填充列宽:AutoSizeColumns: Fill
  • 不进行列排序

3.3.2 添加新行

方法一:使用add方法

            //采用Add()方法添加新行int index1 = dataGridView1.Rows.Add();dataGridView1.Rows[index1].Cells[0].Value = "行数";dataGridView1.Rows[index1].Cells[1].Value = myRasterProp.Height.ToString();

方法二:添加add(row)

        private void addPropToDgv(string propDiscription, string propValue){//采用DataGridViewRow添加新行DataGridViewRow row = new DataGridViewRow();DataGridViewTextBoxCell textboxcell0 = new DataGridViewTextBoxCell();textboxcell0.Value = propDiscription;row.Cells.Add(textboxcell0);DataGridViewTextBoxCell textboxcell1 = new DataGridViewTextBoxCell();textboxcell1.Value = propValue;row.Cells.Add(textboxcell1);//DataGridViewComboBoxCell comboxcell = new DataGridViewComboBoxCell();//row.Cells.Add(comboxcell);dataGridView1.Rows.Add(row);}

3.3.3 绘制行号

方式一

//显示行号private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e){var grid = sender as DataGridView;var rowIdx = (e.RowIndex + 1).ToString();var centerFormat = new StringFormat() { // right alignment might actually make more sense for numbersAlignment = StringAlignment.Center, LineAlignment = StringAlignment.Center};var headerBounds = new Rectangle(e.RowBounds.Left, e.RowBounds.Top, grid.RowHeadersWidth, e.RowBounds.Height);e.Graphics.DrawString(rowIdx, this.Font, SystemBrushes.ControlText, headerBounds, centerFormat);}

方式二

//显示行号private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e){SolidBrush b = new SolidBrush(this.dataGridview1.RowHeaderDefaultCellStyle.ForeColor);e.Graphics.DrawString((e.RowIndex + 1).Tostring(System.Golbalization.CultureInfo.CurrentCulture), this.dataGridview1.DefaultCellStyle.Font, b, e.RowBounds.Location.X + 10, e.RowBounds.Location.X + 4);}

3.3.4 点击首行或首列选中

        //点击列头选中整列private void dataGridView1_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e){this.dataGridView1.SelectionMode = DataGridViewSelectionMode.FullColumnSelect;dataGridView1.Columns[e.ColumnIndex].Selected = true;}//点击行头选中整行private void dataGridView1_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e){this.dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;dataGridView1.Rows[e.RowIndex].Selected = true;}

3.3.5 选中单一的格子

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e){if (e.ColumnIndex != -1){this.dataGridView1.SelectionMode = DataGridViewSelectionMode.CellSelect;dataGridView1.Rows[e.ColumnIndex].Selected = true;}           }

4 源码实现

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 ESRI.ArcGIS.DataSourcesRaster;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geometry;
//https://blog.csdn.net/yh0503/article/details/52644017
//https://blog.csdn.net/mengxiangzhengfaya/article/details/52985746
namespace WindowsFormsApplication1
{public partial class Form1 : Form{public Form1(){ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.EngineOrDesktop);InitializeComponent();}private void textBox1_DragDrop(object sender, DragEventArgs e){textBox1.Text = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();}private void textBox1_DragEnter(object sender, DragEventArgs e){if (e.Data.GetDataPresent(DataFormats.FileDrop)){e.Effect = DragDropEffects.Link;}else{e.Effect = DragDropEffects.None;}}private void addPropToDgv(string propDiscription, string propValue){//采用DataGridViewRow添加新行DataGridViewRow row = new DataGridViewRow();DataGridViewTextBoxCell textboxcell0 = new DataGridViewTextBoxCell();textboxcell0.Value = propDiscription;row.Cells.Add(textboxcell0);DataGridViewTextBoxCell textboxcell1 = new DataGridViewTextBoxCell();textboxcell1.Value = propValue;row.Cells.Add(textboxcell1);//DataGridViewComboBoxCell comboxcell = new DataGridViewComboBoxCell();//row.Cells.Add(comboxcell);dataGridView1.Rows.Add(row);}private void btn_GetRasterInfo_Click(object sender, EventArgs e){IWorkspaceFactory myWorkFact = new RasterWorkspaceFactoryClass();string rasterData = textBox1.Text;IRasterWorkspace myRasterWorkspce = myWorkFact.OpenFromFile(System.IO.Path.GetDirectoryName(rasterData), 0) as IRasterWorkspace;IRasterDataset myRasterDataset = myRasterWorkspce.OpenRasterDataset(System.IO.Path.GetFileName(rasterData)) as IRasterDataset;IRasterLayer myRasterLayer = new RasterLayerClass();myRasterLayer.CreateFromDataset(myRasterDataset);IRasterProps myRasterProp = myRasterLayer.Raster as IRasterProps;//采用Add()方法添加新行int index1 = dataGridView1.Rows.Add();dataGridView1.Rows[index1].Cells[0].Value = "行数";dataGridView1.Rows[index1].Cells[1].Value = myRasterProp.Height.ToString();addPropToDgv("列数", myRasterProp.Width.ToString());addPropToDgv("像素类型", myRasterProp.PixelType.ToString());addPropToDgv("波段数",(myRasterLayer.Raster as IRasterBandCollection).Count.ToString());addPropToDgv("压缩类型", myRasterDataset.CompressionType.ToString());//四个角点的最大最小坐标addPropToDgv("最大X坐标", myRasterProp.Extent.XMax.ToString());addPropToDgv("最小X坐标", myRasterProp.Extent.XMin.ToString());addPropToDgv("最大Y坐标", myRasterProp.Extent.YMax.ToString());addPropToDgv("最小Y坐标", myRasterProp.Extent.YMin.ToString());//四个角点的坐标addPropToDgv("左下X坐标", myRasterProp.Extent.LowerLeft.X.ToString());addPropToDgv("左下Y坐标", myRasterProp.Extent.LowerLeft.Y.ToString());addPropToDgv("左上X坐标", myRasterProp.Extent.UpperLeft.X.ToString());addPropToDgv("左上Y坐标", myRasterProp.Extent.UpperLeft.Y.ToString());addPropToDgv("右下X坐标", myRasterProp.Extent.LowerRight.X.ToString());addPropToDgv("右下Y坐标", myRasterProp.Extent.LowerRight.Y.ToString());addPropToDgv("右上X坐标", myRasterProp.Extent.UpperRight.X.ToString());addPropToDgv("右上Y坐标", myRasterProp.Extent.UpperRight.Y.ToString());//X和Y坐标的格网分辨率addPropToDgv("X尺寸", myRasterProp.MeanCellSize().X.ToString());addPropToDgv("Y尺寸", myRasterProp.MeanCellSize().Y.ToString());//参考坐标信息ISpatialReference pSpatialReference = myRasterProp.SpatialReference;addPropToDgv("空间参考", pSpatialReference.Name.ToString());//投影坐标系IProjectedCoordinateSystem pcs = pSpatialReference as IProjectedCoordinateSystem;addPropToDgv("地理坐标系", pcs.GeographicCoordinateSystem.Name);addPropToDgv("基准面", pcs.GeographicCoordinateSystem.Datum.Name);addPropToDgv("参考椭球", pcs.GeographicCoordinateSystem.Datum.Spheroid.Name);addPropToDgv("投影坐标系", pcs.Projection.Name);addPropToDgv("中央子午线", pcs.get_CentralMeridian(true).ToString());addPropToDgv("线性单位", pcs.CoordinateUnit.Name.ToString());addPropToDgv("尺度因子", pcs.ScaleFactor.ToString());addPropToDgv("假东距", pcs.FalseEasting.ToString());addPropToDgv("假北距", pcs.FalseNorthing.ToString());}//显示行号private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e){var grid = sender as DataGridView;var rowIdx = (e.RowIndex + 1).ToString();var centerFormat = new StringFormat() { // right alignment might actually make more sense for numbersAlignment = StringAlignment.Center, LineAlignment = StringAlignment.Center};var headerBounds = new Rectangle(e.RowBounds.Left, e.RowBounds.Top, grid.RowHeadersWidth, e.RowBounds.Height);e.Graphics.DrawString(rowIdx, this.Font, SystemBrushes.ControlText, headerBounds, centerFormat);}//点击列头选中整列private void dataGridView1_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e){this.dataGridView1.SelectionMode = DataGridViewSelectionMode.FullColumnSelect;dataGridView1.Columns[e.ColumnIndex].Selected = true;}//点击行头选中整行private void dataGridView1_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e){this.dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;dataGridView1.Rows[e.RowIndex].Selected = true;}//选中格子private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e){if (e.ColumnIndex != -1){this.dataGridView1.SelectionMode = DataGridViewSelectionMode.CellSelect;dataGridView1.Rows[e.ColumnIndex].Selected = true;}           }}
}

5 结果展示

6 参考优质博文:

ArcEngine 栅格数据 总结

C# ArcEngine获取坐标系、投影类型、计量单位、带号、几度分带、精度


一起进步,欢迎关注个人微信公众账号【学而立行】

基于C#的ArcEngine二次开发教程(17):获取栅格属性的接口及代码实现相关推荐

  1. 基于C#的ArcEngine二次开发教程(11):矢量数据属性查询接口介绍及实现源码

    目录 1 使用ArcMap进行矢量数据属性查询 示例1:根据Name字段进行查询 示例2:根据KIND字段进行多条记录查询 2 基于AE的矢量数据属性查询的实现 2.1 IFeatureLayer 2 ...

  2. 基于C#的ArcEngine二次开发教程(03):ArcEngine的接口查询技术底层分析

    目录 1 准备工作 2 类和接口的实现 2.1 定义接口IArea 2.2 定义接口ILength 2.3 定义类calc并显式实现IArea和ILength接口 3 主窗体的展示 3.1 直接通过接 ...

  3. 基于C#的ArcEngine二次开发教程(12):缓冲区分析

    目录 1 利用ArcMap实现缓冲区分析 1.1 打开缓冲区向导工具 1.2 缓冲区分析 2 缓冲区分析常用接口 2.1 ITopologicalOperator接口 2.2 IGraphicsCon ...

  4. 基于C#的ArcEngine二次开发46:编辑内容回撤与炸开multipart feature

    目录 1 支持撤销操作 1.1 方法接口介绍 1.1.1 StartOperation() 1.1.2 StopOperation 1.2 代码实现 2 炸开复合要素(explode multipar ...

  5. 基于C#的ArcEngine二次开发28: 等高线高程值与国标码一致性检查思路及代码分析

    1 高程值 类型 说明 首曲线 基本等高线.是按基本等高距测绘的等高线,一般用细实线(0.15mm)描绘,是表示地貌状态的主要等高线 计曲线 加粗等高线.为了便于判读等高线的高程,自高程起算面开始,每 ...

  6. UG二次开发教程(基于NX12.0/VS2015版本)

    ** UG二次开发教程(基于NX12.0/VS2015版本) 安装教程 ** UG NX12.0安装 NX12.0 安装包下载地址: 链接:https://pan.baidu.com/s/1I0CCF ...

  7. 基于Python的ArcGIS二次开发实验实习教程

    基于Python的ArcGIS二次开发实验实习教程. ISBN编号: 9787307221772 原价(定价): 39元, 武汉大学出版社 天猫正版链接: https://detail.tmall.c ...

  8. C#ArcEngine二次开发——创建与调用AOI书签

    基于ArcEngine10.2和VS2012进行C#ArcEngine二次开发 创建与调用AOI书签 在如图所示的程序主窗体菜单栏中添加一个菜单项"创建书签",其控件名为" ...

  9. Arcgis ArcEngine二次开发: 输出宗地图、宗地草图、权属协议书附图、房产分层分户图、公示图、三调土地利用图、行政区划图、标准分幅图等各种图件

    1.Arcgis  ArcEngine二次开发: 输出宗地图.宗地草图.权属协议书附图.房产分层分户图.公示图.三调土地利用图.行政区划图.标准分幅图等各种图件 有需要联系QQ:185242573. ...

最新文章

  1. android settings源代码分析(3)
  2. 电气工程及其自动化专业英语苏小林翻译_“万千星光 智能点亮” 电气工程及其自动化专业讲座...
  3. 第一周周日DailyReporting——PM(李忠)
  4. 基于python的聊天室_Python实现文字聊天室
  5. C 迭代器iterator的实现原理
  6. Node简单服务器开发
  7. 【收藏】HTML颜色参考
  8. 推荐背单词最有效的方法:使用艾宾浩斯记忆曲线背单词
  9. Frame帧动画帧布局Android
  10. python xml解析库_Python xml解析库xml_models2
  11. 阿里云贾扬清发布大数据+AI产品体系“阿里灵杰” | 云栖大会
  12. Table变量和临时表区别
  13. java拼接sql字符串
  14. Vue子组件与父组件(看了就会)
  15. 【博客5】缤果LabView串口调试助手V2.0 (高级篇)
  16. HDWiki/插件开发指南
  17. 电源芯片选择DC/DC还是LDO?
  18. 如何将M4A格式的音频转换为MP3格式?只需一步搞定
  19. Python爬取手机APP
  20. Cocos2D中的Framerate状态

热门文章

  1. Linux内核分析(四)之“暗流涌动”
  2. 进入Docker 容器 docker exec [CONTAINER ID] bin/bash报错问题
  3. 全国大学生软件测试大赛 备赛准备——持续更新中
  4. Win11提示Outlook搜索错误怎么办?Win11提示Outlook搜索错误
  5. HTML的常见标签及用法
  6. ps调黄褐色调照片教程
  7. python--实现微信自动回复机器人和定时发送每日一句与天气预报
  8. CGAL环境配置(VS2019 PCL1.8)
  9. 最早walkman android,入手一年,聊聊索尼 ZX505、艾利和SR15 两款安卓播放器使用体验...
  10. sql之having用法