| | |
| | | ColorTable ct = ds.GetRasterBand(1).GetRasterColorTable(); |
| | | vd.Meta.ct = null == ct ? null : ct.ToString(); // 数据颜色表 |
| | | vd.Meta.h_datum = null; // 高程基准 |
| | | setMinAndMax(ds, vd.Meta); // 设置最值 |
| | | |
| | | double[] tr = new double[6]; |
| | | ds.GetGeoTransform(tr); |
| | | vd.Meta.resolution = string.Format("{0},{1}", tr[1], tr[5]); // 分辨率 |
| | | vd.Meta.resolution = string.Format("{0},{1}", tr[1], Math.Abs(tr[5])); // 分辨率 |
| | | |
| | | 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; |
| | | |
| | |
| | | double[] transform = new double[6]; |
| | | ds.GetGeoTransform(transform); |
| | | |
| | | string epsg = ds.GetSpatialRef().GetAuthorityCode(null); |
| | | double xMin = transform[0]; |
| | | double yMin = transform[3] - ds.RasterYSize * transform[1]; |
| | | |
| | | Geometry point = new Geometry(wkbGeometryType.wkbPoint); |
| | | point.AddPoint(xMin, yMin, 0); |
| | | |
| | | return Transform(ds, point, epsg); |
| | | return Transform(ds, point); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | double[] transform = new double[6]; |
| | | ds.GetGeoTransform(transform); |
| | | |
| | | string epsg = ds.GetSpatialRef().GetAuthorityCode(null); |
| | | double xMax = transform[0] + (ds.RasterXSize * transform[1]); |
| | | double yMax = transform[3]; |
| | | |
| | | Geometry point = new Geometry(wkbGeometryType.wkbPoint); |
| | | point.AddPoint(xMax, yMax, 0); |
| | | |
| | | return Transform(ds, point, epsg); |
| | | return Transform(ds, point); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 坐标转换 |
| | | /// </summary> |
| | | private Geometry Transform(Dataset ds, Geometry point, string epsg) |
| | | private Geometry Transform(Dataset ds, Geometry point) |
| | | { |
| | | point.AssignSpatialReference(ds.GetSpatialRef()); |
| | | if (ds.GetSpatialRef().IsGeographic() > 0) |
| | |
| | | |
| | | return geo; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 设置最值 |
| | | /// GDALRasterBand::GetHistogram 统计直方图 |
| | | /// </summary> |
| | | private void setMinAndMax(Dataset ds, SysMeta meta) |
| | | { |
| | | List<double> minList = new List<double>(); |
| | | List<double> maxList = new List<double>(); |
| | | |
| | | for (int i = 1; i <= ds.RasterCount; i++) |
| | | { |
| | | int hasval; |
| | | double min, max; |
| | | ds.GetRasterBand(i).GetMinimum(out min, out hasval); |
| | | ds.GetRasterBand(i).GetMaximum(out max, out hasval); |
| | | |
| | | minList.Add(min); |
| | | maxList.Add(max); |
| | | } |
| | | |
| | | meta.min = string.Join(",", minList.ToArray()); |
| | | meta.max = string.Join(",", maxList.ToArray()); |
| | | } |
| | | #endregion |
| | | |
| | | public void CsTransform(double x, double y, int epsg) |
| | | { |
| | | SpatialReference srs = new SpatialReference(null); |
| | | srs.ImportFromEPSG(epsg); |
| | | |
| | | Geometry point = new Geometry(wkbGeometryType.wkbPoint); |
| | | point.AddPoint(x, y, 0); |
| | | point.AssignSpatialReference(srs); |
| | | |
| | | if (srs.GetName().Contains("CGCS2000")) |
| | | { |
| | | point.TransformTo(sr4490); |
| | | } |
| | | else |
| | | { |
| | | point.TransformTo(sr4326); |
| | | } |
| | | point.SwapXY(); |
| | | |
| | | double[] xy = new double[] { point.GetX(0), point.GetY(0) }; |
| | | } |
| | | } |
| | | } |