ArcGIS Engine获取栅格数据属性值
ArcGIS Engine提供获取栅格数据的接口,要获取栅格数据,首先要将IRaster转为IRaster2,然后获取IRatster2的属性表ITable,最后从ITable中获取值字段。
获取栅格数据
ILayer pLayer = axMapControl1.get_Layer(0);
IRasterLayer pRasterLayer = pLayer as IRasterLayer;
转为IRaster2
IRaster2 pRaster = (IRaster2)pRasterLayer.Raster;
读取属性表
ITable table = pRaster.AttributeTable;
纯栅格数据可能没有属性表,即为null,因此应首先判断table是否为null,再进行下一步操作。
获得属性值
string attr = "";
for (int i = 0; i < table.Fields.FieldCount; i++)
{
attr += table.Fields.Field[i].Name;
}
全部代码(函数):
private void 读取栅格属性表ToolStripMenuItem_Click(object sender, EventArgs e)
{
ILayer pLayer = axMapControl1.get_Layer(0);
IRasterLayer pRasterLayer = pLayer as IRasterLayer;
IRaster2 pRaster = (IRaster2)pRasterLayer.Raster;
ITable table = pRaster.AttributeTable;
if (table == null)
{
MessageBox.Show("无属性值");
return;
}
string attr = "";
for (int i = 0; i < table.Fields.FieldCount; i++)
{
attr += table.Fields.Field[i].Name;
}
MessageBox.Show(attr);
}
转载自:https://blog.csdn.net/ScapeD/article/details/82877667