#region 根据GDAL获取信息 private void Get_InforFromGDAL(string S_File)//根据GDAL获取信息,S_File为影像路径 { Dataset ds = Gdal.Open(S_File, Access.GA_ReadOnly); DataManager_listBox.Items.Clear();//DataManager_listBox为一ListBox DataManager_listBox.Items.Add(“文件: “ + S_File); DataManager_listBox.Items.Add(“驱动: “ + ds.GetDriver().GetDescription()); DataManager_listBox.Items.Add(“波段数: “ + ds.RasterCount); DataManager_listBox.Items.Add(“X分辨率: “ + ds.RasterXSize); DataManager_listBox.Items.Add(“Y分辨率: “ + ds.RasterYSize); string S_projectInfor = ds.GetProjectionRef();//投影信息里包含许多子信息(实例如下),需要逐个提取 /* 某个图像所包含的投影信息 PROJCS[“UTM_Zone_46N”,GEOGCS[“GCS_WGS_1984”,DATUM[“WGS_1984”,SPHEROID[“WGS_84”,6378137.0,298.257223563]],PRIMEM[“Greenwich”,0.0],UNIT[“Degree”,0.0174532925199433]],PROJECTION[“Transverse_Mercator”],PARAMETER[“False_Easting”,500000.0],PARAMETER[“False_Northing”,0.0],PARAMETER[“Central_Meridian”,93.0],PARAMETER[“Scale_Factor”,0.9996],PARAMETER[“Latitude_Of_Origin”,0.0],UNIT[“Meter”,1]] */ DataManager_listBox.Items.Add(“投影空间参考系: “ + Get_InforFromGDAL_AttriInfor(S_projectInfor, “PROJCS”)); DataManager_listBox.Items.Add(“地理参考系: “ + Get_InforFromGDAL_AttriInfor(S_projectInfor, “GEOGCS”)); DataManager_listBox.Items.Add(“水平基准面: “ + Get_InforFromGDAL_AttriInfor(S_projectInfor, “DATUM”)); DataManager_listBox.Items.Add(“椭球体: “ + Get_InforFromGDAL_AttriInfor(S_projectInfor, “SPHEROID”)); DataManager_listBox.Items.Add(“本初子午线: “ + Get_InforFromGDAL_AttriInfor(S_projectInfor, “PRIMEM”)); DataManager_listBox.Items.Add(“投影方式: “ + Get_InforFromGDAL_AttriInfor(S_projectInfor, “PROJECTION”)); double[] adfGeoTransform = new double[6]; ds.GetGeoTransform(adfGeoTransform); DataManager_listBox.Items.Add(“起始坐标 = (“ + adfGeoTransform[0] + “,” + adfGeoTransform[3] + “)”); DataManager_listBox.Items.Add(“像素大小 = (“ + adfGeoTransform[1] + “,” + adfGeoTransform[5] + “)”); }
private string Get_InforFromGDAL_AttriInfor(string S_InPut, string S_AttriName)//获取输入值某个参数的信息 { string S_OutPut; string S_AllInfor = Get_InforFromGDAL_AttriInfor_AttriSubInfor(S_InPut, S_AttriName);//获取该类下所有信息 int I_FirstKeyWord = S_InPut.IndexOf(S_AttriName);//获取该属性在其中的位置 if (S_AllInfor != “” && I_FirstKeyWord != –1)//如果找到该属性字段 { if (S_AllInfor.IndexOf(“[“) != –1)//若有下级信息 { int I_FirstQuota = I_FirstKeyWord + S_AttriName.Length + 1; int I_LastQuota = S_InPut.IndexOf(“\””, I_FirstQuota + 1); S_OutPut = S_InPut.Substring(I_FirstQuota, I_LastQuota – I_FirstQuota + 1);//提取其中的属性值 } else { S_OutPut = S_AllInfor;//否则整个信息段都为属性值 } } else S_OutPut = “未知“; return S_OutPut; }
private string Get_InforFromGDAL_AttriInfor_AttriSubInfor(string S_InPut, string S_AttriName)//获取下级信息 { string S_OutPut = “”; int I_FirstKeyWord = S_InPut.IndexOf(S_AttriName); int I_FirstBracket = I_FirstKeyWord + S_AttriName.Length + 1; if (I_FirstKeyWord != –1) { int I_LastBracket = S_InPut.IndexOf(“]”, I_FirstKeyWord); S_OutPut = S_InPut.Substring(I_FirstBracket, I_LastBracket – I_FirstBracket); } return S_OutPut; }
#endregion 根据GDAL获取信息
|