| | |
| | | try |
| | | { |
| | | ds = Gdal.Open(vd.FilePath, Access.GA_ReadOnly); |
| | | if (null == ds || ds.RasterCount == 0) return; |
| | | if (null == ds || ds.RasterCount == 0 || null == ds.GetSpatialRef()) return; |
| | | |
| | | vd.Meta.gridsize = string.Format("{0},{1}", ds.RasterXSize, ds.RasterYSize); // 行列数 |
| | | |
| | | SpatialReference sr = ds.GetSpatialRef(); |
| | | if (sr != null) |
| | | vd.Meta.coor_sys = sr.GetName(); // 坐标系统 |
| | | if (MOON200 == vd.Meta.coor_sys) |
| | | { |
| | | vd.Meta.coor_sys = sr.GetName(); // 坐标系统 |
| | | if (MOON200 == vd.Meta.coor_sys) |
| | | { |
| | | vd.Meta.epsg = "ESRI:104903"; // EPSG编码 |
| | | } |
| | | else |
| | | { |
| | | string code = sr.GetAuthorityCode(null); |
| | | vd.Meta.epsg = string.IsNullOrEmpty(code) ? null : "EPSG:" + code; // EPSG编码 |
| | | } |
| | | vd.Meta.epsg = "ESRI:104903"; // EPSG编码 |
| | | } |
| | | else |
| | | { |
| | | string code = sr.GetAuthorityCode(null); // PROJCS、GEOGCS、GEOGCS|UNIT 或 NULL |
| | | vd.Meta.epsg = string.IsNullOrEmpty(code) ? null : "EPSG:" + code; // EPSG编码 |
| | | } |
| | | |
| | | vd.Meta.bands = ds.RasterCount.ToString(); // 波段数 |
| | |
| | | vd.Meta.ct = null == ct ? null : ct.ToString(); // 数据颜色表 |
| | | vd.Meta.h_datum = null; // 高程基准 |
| | | |
| | | double[] transform = new double[6]; |
| | | ds.GetGeoTransform(transform); |
| | | vd.Meta.resolution = string.Format("{0},{1}", transform[1], transform[5]); // 分辨率 |
| | | double[] tr = new double[6]; |
| | | ds.GetGeoTransform(tr); |
| | | vd.Meta.resolution = string.Format("{0},{1}", tr[1], tr[5]); // 分辨率 |
| | | |
| | | if (!EPSGS.Contains(vd.Meta.epsg)) return; |
| | | if (tr[0] == 0.0 && tr[1] == 1.0 && tr[2] == 0.0 && tr[3] == 0.0 && tr[4] == 0.0 && tr[5] == 1.0) return; |
| | | |
| | | Geometry minPoint = GetMinPoint(ds); |
| | | Geometry maxPoint = GetMaxPoint(ds); |
| | |
| | | /// </summary> |
| | | private Geometry GetMaxPoint(Dataset ds) |
| | | { |
| | | /** |
| | | * transform[0] 左上角x坐标 |
| | | * transform[1] 东西方向分辨率 |
| | | * transform[2] 旋转角度, 0表示图像 "北方朝上" |
| | | * |
| | | * transform[3] 左上角y坐标 |
| | | * transform[4] 旋转角度, 0表示图像 "北方朝上" |
| | | * transform[5] 南北方向分辨率 |
| | | */ |
| | | double[] transform = new double[6]; |
| | | ds.GetGeoTransform(transform); |
| | | |
| | |
| | | /// </summary> |
| | | private Geometry Transform(Dataset ds, Geometry point, string epsg) |
| | | { |
| | | if (string.IsNullOrEmpty(epsg)) |
| | | point.AssignSpatialReference(ds.GetSpatialRef()); |
| | | if (ds.GetSpatialRef().IsGeographic() > 0) |
| | | { |
| | | point.AssignSpatialReference(sr104903); |
| | | return point; |
| | | } |
| | | if ("4326" == epsg) |
| | | { |
| | | point.AssignSpatialReference(sr4326); |
| | | return point; |
| | | } |
| | | if ("4490" == epsg) |
| | | { |
| | | point.AssignSpatialReference(sr4490); |
| | | return point; |
| | | } |
| | | |
| | | point.AssignSpatialReference(ds.GetSpatialRef()); |
| | | if (ds.GetSpatialRef().GetName().Contains("CGCS2000")) |
| | | string srsName = ds.GetSpatialRef().GetName(); |
| | | if (srsName.Contains("CGCS2000")) |
| | | { |
| | | point.TransformTo(sr4490); |
| | | } |
| | |
| | | { |
| | | point.TransformTo(sr4326); |
| | | } |
| | | point.SwapXY(); |
| | | |
| | | return point; |
| | | } |