年度变更建库软件5.0版本
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

785 lines
26 KiB

using ESRI.ArcGIS.DataSourcesRaster;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using KGIS.Plugin.LayerProperty.Enum;
using KGIS.Plugin.LayerProperty.Interface;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
namespace KGIS.Plugin.LayerProperty.Model
{
[Serializable]
internal class RasterProperty : IRasterProperty
{
private IRasterDataset m_RasterDataset;
public enumRasterDataType RasterType;
private string m_Raster = string.Empty;
private string m_DataType = string.Empty;
private string m_Folder = string.Empty;
private string m_Server = string.Empty;
private string m_User = string.Empty;
private string m_Instance = string.Empty;
private string m_Database = string.Empty;
private string m_Version = string.Empty;
private string m_Columns = string.Empty;
private string m_Rows = string.Empty;
private int m_Number_of_Bands = -1;
private double m_Cellsize_X = -1.0;
private double m_Cellsize_Y = -1.0;
private double m_Uncompressed_Size;
private string m_Format = string.Empty;
private string m_Source_Type = string.Empty;
private string m_Pixel_Type = string.Empty;
private string m_Pixel_Depth = string.Empty;
private string m_NoData_Value = string.Empty;
private string m_Colormap = string.Empty;
private string m_Pyramids = string.Empty;
private string m_Compression = string.Empty;
private double m_Top;
private double m_Left;
private double m_Right;
private double m_Bottom;
private string m_SpatialReference = string.Empty;
private string m_Linear_Unit = string.Empty;
private string m_Angular_Unit = string.Empty;
private string m_Datum = string.Empty;
private string m_False_Easting = string.Empty;
private string m_False_Northing = string.Empty;
private string m_Central_Meridian = string.Empty;
private string m_Scale_Factor = string.Empty;
private string m_Latitude_Of_Origin = string.Empty;
private string m_Build_Parameters = string.Empty;
private double m_Min;
private double m_Max;
private double m_Mean;
private double m_Std_dev;
private double m_Classes;
[Browsable(true), Category("数据源"), DisplayName("栅格"), ReadOnly(true), XmlElement("栅格名")]
public virtual string Raster
{
get
{
return this.m_Raster;
}
set
{
this.m_Raster = value;
}
}
[Browsable(true), Category("数据源"), DisplayName("数据类型"), ReadOnly(true), XmlElement("数据类型")]
public virtual string DataType
{
get
{
return this.m_DataType;
}
set
{
this.m_DataType = value;
}
}
[Browsable(true), Category("栅格信息"), DisplayName("列数"), ReadOnly(true), XmlElement("列数")]
public string Columns
{
get
{
return this.m_Columns;
}
set
{
this.m_Columns = value;
}
}
[Browsable(true), Category("栅格信息"), DisplayName("行数"), ReadOnly(true), XmlElement("行数")]
public string Rows
{
get
{
return this.m_Rows;
}
set
{
this.m_Rows = value;
}
}
[Browsable(true), Category("栅格信息"), DisplayName("波段数"), ReadOnly(true), XmlElement("波段数")]
public int Number_of_Bands
{
get
{
return this.m_Number_of_Bands;
}
set
{
this.m_Number_of_Bands = value;
}
}
[Browsable(true), Category("栅格信息"), DisplayName("X方向分辨率"), ReadOnly(true), XmlElement("X方向分辨率")]
public double Cellsize_X
{
get
{
return this.m_Cellsize_X;
}
set
{
this.m_Cellsize_X = value;
}
}
[Browsable(true), Category("栅格信息"), DisplayName("Y方向分辨率"), ReadOnly(true), XmlElement("Y方向分辨率")]
public double Cellsize_Y
{
get
{
return this.m_Cellsize_Y;
}
set
{
this.m_Cellsize_Y = value;
}
}
[Browsable(true), Category("栅格信息"), DisplayName("无压缩大小"), ReadOnly(true), XmlElement("无压缩大小")]
public double Uncompressed_Size
{
get
{
return this.m_Uncompressed_Size;
}
set
{
this.m_Uncompressed_Size = value;
}
}
[Browsable(true), Category("栅格信息"), DisplayName("格式"), ReadOnly(true), XmlElement("格式")]
public string Format
{
get
{
return this.m_Format;
}
set
{
this.m_Format = value;
}
}
[Browsable(true), Category("栅格信息"), DisplayName("源类型"), ReadOnly(true), XmlElement("源类型")]
public string Source_Type
{
get
{
return this.m_Source_Type;
}
set
{
this.m_Source_Type = value;
}
}
[Browsable(true), Category("栅格信息"), DisplayName("像素类型"), ReadOnly(true), XmlElement("像素类型")]
public string Pixel_Type
{
get
{
return this.m_Pixel_Type;
}
set
{
this.m_Pixel_Type = value;
}
}
[Browsable(true), Category("栅格信息"), DisplayName("像素深度"), ReadOnly(true), XmlElement("像素深度")]
public string Pixel_Depth
{
get
{
return this.m_Pixel_Depth;
}
set
{
this.m_Pixel_Depth = value;
}
}
[Browsable(true), Category("栅格信息"), DisplayName("空值"), ReadOnly(true), XmlElement("空值")]
public string NoData_Value
{
get
{
return this.m_NoData_Value;
}
set
{
this.m_NoData_Value = value;
}
}
[Browsable(true), Category("栅格信息"), DisplayName("颜色表"), ReadOnly(true), XmlElement("颜色表")]
public string Colormap
{
get
{
return this.m_Colormap;
}
set
{
this.m_Colormap = value;
}
}
[Browsable(true), Category("栅格信息"), DisplayName("金字塔"), ReadOnly(true), XmlElement("金字塔")]
public string Pyramids
{
get
{
return this.m_Pyramids;
}
set
{
this.m_Pyramids = value;
}
}
[Browsable(true), Category("栅格信息"), DisplayName("压缩"), ReadOnly(true), XmlElement("压缩")]
public string Compression
{
get
{
return this.m_Compression;
}
set
{
this.m_Compression = value;
}
}
[Browsable(true), Category("影像范围"), DisplayName("上"), ReadOnly(true), XmlElement("上")]
public double Top
{
get
{
return this.m_Top;
}
set
{
this.m_Top = value;
}
}
[Browsable(true), Category("影像范围"), DisplayName("左"), ReadOnly(true), XmlElement("左")]
public double Left
{
get
{
return this.m_Left;
}
set
{
this.m_Left = value;
}
}
[Browsable(true), Category("影像范围"), DisplayName("右"), ReadOnly(true), XmlElement("右")]
public double Right
{
get
{
return this.m_Right;
}
set
{
this.m_Right = value;
}
}
[Browsable(true), Category("影像范围"), DisplayName("下"), ReadOnly(true), XmlElement("下")]
public double Bottom
{
get
{
return this.m_Bottom;
}
set
{
this.m_Bottom = value;
}
}
[Browsable(true), Category("空间参考"), DisplayName("空间参考"), ReadOnly(true), XmlElement("空间参考")]
public string SpatialReference
{
get
{
return this.m_SpatialReference;
}
set
{
this.m_SpatialReference = value;
}
}
[Browsable(true), Category("空间参考"), DisplayName("线性单位"), ReadOnly(true), XmlElement("线性单位")]
public string Linear_Unit
{
get
{
return this.m_Linear_Unit;
}
set
{
this.m_Linear_Unit = value;
}
}
[Browsable(true), Category("空间参考"), DisplayName("角度单位"), ReadOnly(true), XmlElement("角度单位")]
public string Angular_Unit
{
get
{
return this.m_Angular_Unit;
}
set
{
this.m_Angular_Unit = value;
}
}
[Browsable(true), Category("空间参考"), DisplayName("基准面"), ReadOnly(true), XmlElement("基准面")]
public string Datum
{
get
{
return this.m_Datum;
}
set
{
this.m_Datum = value;
}
}
[Browsable(true), Category("空间参考"), DisplayName("东偏"), ReadOnly(true), XmlElement("东偏")]
public string False_Easting
{
get
{
return this.m_False_Easting;
}
set
{
this.m_False_Easting = value;
}
}
[Browsable(true), Category("空间参考"), DisplayName("北偏"), ReadOnly(true), XmlElement("北偏")]
public string False_Northing
{
get
{
return this.m_False_Northing;
}
set
{
this.m_False_Northing = value;
}
}
[Browsable(true), Category("空间参考"), DisplayName("中央经线"), ReadOnly(true), XmlElement("中央经线")]
public string Central_Meridian
{
get
{
return this.m_Central_Meridian;
}
set
{
this.m_Central_Meridian = value;
}
}
[Browsable(true), Category("空间参考"), DisplayName("比例系数"), ReadOnly(true), XmlElement("比例系数")]
public string Scale_Factor
{
get
{
return this.m_Scale_Factor;
}
set
{
this.m_Scale_Factor = value;
}
}
[Browsable(true), Category("空间参考"), DisplayName("起始纬度"), ReadOnly(true), XmlElement("起始纬度")]
public string Latitude_Of_Origin
{
get
{
return this.m_Latitude_Of_Origin;
}
set
{
this.m_Latitude_Of_Origin = value;
}
}
[Browsable(true), Category("统计信息"), DisplayName("构建参数"), ReadOnly(true), XmlElement("构建参数")]
public string Build_Parameters
{
get
{
return this.m_Build_Parameters;
}
set
{
this.m_Build_Parameters = value;
}
}
[Browsable(true), Category("统计信息"), DisplayName("最小值"), ReadOnly(true), XmlElement("最小值")]
public double Min
{
get
{
return this.m_Min;
}
set
{
this.m_Min = value;
}
}
[Browsable(true), Category("统计信息"), DisplayName("最大值"), ReadOnly(true), XmlElement("最大值")]
public double Max
{
get
{
return this.m_Max;
}
set
{
this.m_Max = value;
}
}
[Browsable(true), Category("统计信息"), DisplayName("平均值"), ReadOnly(true), XmlElement("平均值")]
public double Mean
{
get
{
return this.m_Mean;
}
set
{
this.m_Mean = value;
}
}
[Browsable(true), Category("统计信息"), DisplayName("标准偏差"), ReadOnly(true), XmlElement("标准偏差")]
public double Std_dev
{
get
{
return this.m_Std_dev;
}
set
{
this.m_Std_dev = value;
}
}
[Browsable(true), Category("统计信息"), DisplayName("类"), ReadOnly(true), XmlElement("类")]
public double Classes
{
get
{
return this.m_Classes;
}
set
{
this.m_Classes = value;
}
}
public void Init(IRasterDataset pRasterDataset)
{
this.m_RasterDataset = pRasterDataset;
this.RasterType = this.GetRasterProperty();
}
public virtual void ExportToXML()
{
try
{
//RasterProperty rasterProperty = new RasterProperty();
//rasterProperty.Init(this.m_RasterDataset);
//XmlSerializer xmlSerializer = new XmlSerializer(typeof(RasterProperty));
//SaveFileDialog saveFileDialog = new SaveFileDialog();
//saveFileDialog.Filter = "XML文件(*.xml)|*.xml";
//saveFileDialog.CheckPathExists = true;
//if (this.m_Raster.IndexOf(".") > 0)
//{
// saveFileDialog.FileName = this.m_Raster.Substring(this.m_Raster.IndexOf(".") + 1) + ".xml";
//}
//else
//{
// saveFileDialog.FileName = this.m_Raster + ".xml";
//}
//if (saveFileDialog.ShowDialog() == DialogResult.OK && saveFileDialog.FileName.Length != 0)
//{
// StreamWriter streamWriter = new StreamWriter(saveFileDialog.FileName);
// xmlSerializer.Serialize(streamWriter, rasterProperty);
// streamWriter.Close();
//}
}
catch (Exception)
{
}
}
private enumRasterDataType GetRasterProperty()
{
this.RasterType = enumRasterDataType.RDTUnknown;
enumRasterDataType rasterType;
try
{
IRaster raster = this.m_RasterDataset.CreateDefaultRaster();
IRasterBandCollection rasterBandCollection = (IRasterBandCollection)raster;
IRasterBand rasterBand = null;
rasterBand = rasterBandCollection.Item(0);
IDataset dataset = (IDataset)this.m_RasterDataset;
IWorkspace arg_3C_0 = dataset.Workspace;
this.m_Raster = dataset.Name;
IRasterProps rasterProps = (IRasterProps)raster;
this.m_Columns = rasterProps.Width.ToString();
this.m_Rows = rasterProps.Height.ToString();
this.m_Number_of_Bands = rasterBandCollection.Count;
this.m_Cellsize_X = rasterProps.MeanCellSize().X;
this.m_Cellsize_Y = rasterProps.MeanCellSize().Y;
this.m_Format = this.m_RasterDataset.Format;
this.m_Source_Type = "连续";
this.m_Pixel_Type = this.GetPixelType(rasterProps.PixelType);
this.m_Pixel_Depth = this.GetPixelDepth(rasterProps.PixelType);
this.m_NoData_Value = this.GetNoDataValue(rasterProps);
this.m_Colormap = this.GetColormapInfo(rasterBandCollection);
this.m_Pyramids = this.GetPyramidsInfo();
this.m_Compression = this.m_RasterDataset.CompressionType;
IEnvelope extent = rasterProps.Extent;
if (extent != null)
{
this.m_Top = extent.YMax;
this.m_Left = extent.XMin;
this.m_Bottom = extent.YMin;
this.m_Right = extent.XMax;
}
ISpatialReference spatialReference = rasterProps.SpatialReference;
if (spatialReference != null)
{
this.m_SpatialReference = spatialReference.Name;
if (spatialReference is IProjectedCoordinateSystem)
{
IProjectedCoordinateSystem projectedCoordinateSystem = (IProjectedCoordinateSystem)spatialReference;
this.m_Linear_Unit = projectedCoordinateSystem.CoordinateUnit.Name;
this.m_Angular_Unit = string.Empty;
this.m_Datum = string.Empty;
this.m_False_Easting = projectedCoordinateSystem.FalseEasting.ToString();
this.m_False_Northing = projectedCoordinateSystem.FalseNorthing.ToString();
this.m_Central_Meridian = projectedCoordinateSystem.get_CentralMeridian(true).ToString();
this.m_Scale_Factor = projectedCoordinateSystem.ScaleFactor.ToString();
try
{
this.m_Latitude_Of_Origin = projectedCoordinateSystem.LongitudeOfOrigin.ToString();
goto IL_2B7;
}
catch (Exception)
{
goto IL_2B7;
}
}
if (spatialReference is IGeographicCoordinateSystem)
{
IGeographicCoordinateSystem geographicCoordinateSystem = (IGeographicCoordinateSystem)spatialReference;
this.m_Linear_Unit = string.Empty;
this.m_Angular_Unit = geographicCoordinateSystem.CoordinateUnit.Name;
this.m_Datum = geographicCoordinateSystem.Datum.Name;
this.m_False_Easting = string.Empty;
this.m_False_Northing = string.Empty;
this.m_Central_Meridian = string.Empty;
this.m_Scale_Factor = string.Empty;
this.m_Latitude_Of_Origin = string.Empty;
}
}
IL_2B7:
bool flag;
rasterBand.HasStatistics(out flag);
if (flag)
{
IRasterStatistics statistics = rasterBand.Statistics;
this.m_Build_Parameters = this.GetBuildParameters(statistics);
this.m_Min = statistics.Minimum;
this.m_Max = statistics.Maximum;
this.m_Mean = statistics.Mean;
this.m_Std_dev = statistics.StandardDeviation;
this.m_Classes = 0.0;
}
rasterType = this.RasterType;
}
catch (Exception)
{
rasterType = this.RasterType;
}
return rasterType;
}
private string GetBuildParameters(IRasterStatistics statistics)
{
string text = "";
try
{
text = "忽略列: " + statistics.SkipFactorY.ToString();
text = text + " 忽略行: " + statistics.SkipFactorX.ToString();
text += " 忽略值: ";
if (statistics.IgnoredValues != null)
{
text += statistics.IgnoredValues.ToString();
}
}
catch (Exception)
{
}
return text;
}
private string GetNoDataValue(IRasterProps pRasterProps)
{
string result;
try
{
string text = "";
result = text;
}
catch (Exception)
{
result = "";
}
return result;
}
private string GetPyramidsInfo()
{
string result;
try
{
IRasterPyramid rasterPyramid = (IRasterPyramid)this.m_RasterDataset;
if (rasterPyramid.Present)
{
IRasterPyramid2 rasterPyramid2 = (IRasterPyramid2)rasterPyramid;
result = string.Concat(new object[]
{
"金字塔等级:",
rasterPyramid2.PyramidLevel,
" 重采样方法:",
rasterPyramid2.PyramidResamplingMethod.ToString()
});
}
else
{
result = "缺失";
}
}
catch
{
result = "已构建";
}
return result;
}
private string GetColormapInfo(IRasterBandCollection pRasterCol)
{
string result;
try
{
for (int i = 0; i < pRasterCol.Count; i++)
{
IRasterBand rasterBand = pRasterCol.Item(i);
bool flag;
rasterBand.HasColormap(out flag);
if (flag)
{
IRasterColormap colormap = rasterBand.Colormap;
object colors = colormap.Colors;
Color color = (Color)colors;
result = string.Concat(new object[]
{
"R:",
color.R,
" G:",
color.G,
" B:",
color.B
});
return result;
}
}
result = "缺失";
}
catch (Exception)
{
result = "缺失";
}
return result;
}
private string GetPixelType(rstPixelType type)
{
switch (type)
{
case rstPixelType.PT_UNKNOWN:
return "未知";
case rstPixelType.PT_U1:
return "1 bit";
case rstPixelType.PT_U2:
return "2 bit";
case rstPixelType.PT_U4:
return "4 bit";
case rstPixelType.PT_UCHAR:
return "unsigned 8 bit";
case rstPixelType.PT_CHAR:
return "signed 8 bit";
case rstPixelType.PT_USHORT:
return "unsigned 16 bit";
case rstPixelType.PT_SHORT:
return "signed 16 bit";
case rstPixelType.PT_ULONG:
return "unsigned 32 bit";
case rstPixelType.PT_LONG:
return "signed 32 bit";
case rstPixelType.PT_FLOAT:
return "float";
case rstPixelType.PT_DOUBLE:
return "double";
case rstPixelType.PT_COMPLEX:
return "complex";
case rstPixelType.PT_DCOMPLEX:
return "double precision complex";
default:
return type.ToString();
}
}
private string GetPixelDepth(rstPixelType type)
{
switch (type)
{
case rstPixelType.PT_UNKNOWN:
return "未知";
case rstPixelType.PT_U1:
return "1 bit";
case rstPixelType.PT_U2:
return "2 bit";
case rstPixelType.PT_U4:
return "4 bit";
case rstPixelType.PT_UCHAR:
return "8 bit";
case rstPixelType.PT_CHAR:
return "8 bit";
case rstPixelType.PT_USHORT:
return "16 bit";
case rstPixelType.PT_SHORT:
return "16 bit";
case rstPixelType.PT_ULONG:
return "32 bit";
case rstPixelType.PT_LONG:
return "32 bit";
case rstPixelType.PT_FLOAT:
return "32 bit";
case rstPixelType.PT_DOUBLE:
return "32 bit";
default:
return "";
}
}
private void InitProperty(enumRasterDataType pType)
{
switch (pType)
{
case enumRasterDataType.RDTFileSystem:
case enumRasterDataType.RDTLocalDatabase:
case enumRasterDataType.RDTRemoteDatabase:
case enumRasterDataType.RDTUnknown:
return;
}
}
}
}