1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
| public class SheetDesignationUtils { private static char[] LatCharArray = {'A','B','C','D','E','F','G','H','I','J','K' ,'L','M','N','O','P','Q','R','S','T','U','V'}; private static char[] ScaleCharArray = { 'A', 'B', 'C', 'R', 'D', 'E', 'F', 'G', 'H' }; private static double[] LatDArray = { 14400, 7200, 3600, 2400, 1200, 600, 300, 150, 75 }; private static double[] LonDArray = { 21600, 10800, 5400, 3600, 1800, 900, 450, 225, 112.5 };
public static string GetSheetNo(int lon, int lat, SheetScale scale) { if (lat < -(88 * 60 * 60) || lat > 88 * 60 * 60) throw new Exception("纬度不正确,请检查!"); if (lon < 0 || lon > 180 * 60 * 60) throw new Exception("经度不正确,请检查!"); string numString = ""; numString += GetMillionRowID(lat); numString += GetMillionColumnID(lon); if (scale == SheetScale._1000000) return numString; numString += GetScaleID(scale); numString += GetRowID(lat, scale); numString += GetColumnID(lon, scale); return numString; }
public static char GetMillionRowID(int lat) { int a = lat / (4 * 3600); return LatCharArray[a]; }
public static int GetMillionColumnID(int lon) { int b = lon / (6 * 3600) + 31; return b; }
public static char GetScaleID(SheetScale scale) { int scaleIndex = Convert.ToInt32(scale); char scaleId = ScaleCharArray[scaleIndex]; return scaleId; }
public static string GetRowID(int lat, SheetScale scale) { int scaleIndex = Convert.ToInt32(scale); int c = Convert.ToInt32(4 * 3600 / LatDArray[scaleIndex]) - Convert.ToInt32(lat % (4 * 3600) / LatDArray[scaleIndex]); return c.ToString().PadRight(3, '0'); }
public static string GetColumnID(int lon, SheetScale scale) { int scaleIndex = Convert.ToInt32(scale); int d = Convert.ToInt32(lon % (6 * 3600) / LonDArray[scaleIndex]) + 1; return d.ToString().PadRight(3, '0'); }
public static SheetArea GetSheetArea(string frmNo) { if (frmNo.Length != 10) throw new Exception("图幅号错误,请输入标准十位图幅编号!"); int latMillionNum, lonMillionNum, latNum, lonNum, scaleNum; char latMillionChar, scaleChar;
latMillionChar = char.Parse(frmNo.Substring(0, 1)); latMillionNum = LatCharArray.ToList().IndexOf(latMillionChar); if (latMillionNum == -1) throw new Exception("图幅号错误,请检查百万比例尺纬度号!");
scaleChar = char.Parse(frmNo.Substring(3, 1)); scaleNum = ScaleCharArray.ToList().IndexOf(scaleChar); if (scaleNum == -1) throw new Exception("图符号错误,请检查比例尺代号!");
if (!int.TryParse(frmNo.Substring(1, 2), out lonMillionNum)) throw new Exception("图幅号错误,请检查百万比例尺经度号!"); if (!int.TryParse(frmNo.Substring(4, 3), out latNum)) throw new Exception("图幅号错误,请检查纬度号!"); if (!int.TryParse(frmNo.Substring(7, 3), out lonNum)) throw new Exception("图幅号错误,请检查经度号!"); SheetArea sheetArea = new SheetArea(); sheetArea.LatMin = latMillionNum * 4 * 3600 + (4 * 3600 / LatDArray[scaleNum] - latNum) * LatDArray[scaleNum]; sheetArea.LatMax = sheetArea.LatMin + LatDArray[scaleNum];
sheetArea.LonMax = (lonMillionNum - 30 - 1) * 6 * 3600 + lonNum * LonDArray[scaleNum]; sheetArea.LonMin = sheetArea.LonMax - LonDArray[scaleNum]; return sheetArea; }
} public class SheetArea { public double LonMin { get; set; } public double LatMin { get; set; } public double LonMax { get; set; } public double LatMax { get; set; } public SheetArea() { } public SheetArea(double lonMin, double latMin, double lonMax, double latMax) { LonMin = lonMin; LatMin = latMin; LonMax = lonMax; LatMax = latMax; } }
public enum SheetScale : int { _1000000 = 0, _500000 = 1, _250000 = 2, _100000 = 4, _50000 = 5, _25000 = 6, _10000 = 7, _5000 = 8 }
|