图号(图幅号):地图图号是指为便于使用和管理,按照一定方法将各分幅地图进行的编号。
经常用到图号,但是在网上一直没有找到一个完整的图号转换程序,因此自己写了一个图号处理的库,分享出来。如有错误请指正。
新图号标准:GB/T 13989-2012.国家基本比例尺地形图分幅和编号
旧图号标准:无。历史遗留问题。从最初的苏联坐标系开始,旧图号分别采用了俄文编号/中文编号/数字编号/英文编号等等各个版本,使用起来很不方便。此次将旧图号统一了一下,全部采用“-”分割,百万图号标准同步新图号标准,子比例尺分幅时,共有4幅的用大写ABCD表示,如50万比例尺:H-45-A。大于4幅时使用数字,不足位补零,如10万比例尺:H-45-001。特殊情况,2.5万比例尺,最后一位用1234,倒数第二位用大写ABCD,如:H45-090-C-2。
编程语言:C#。库类包含的方法:新/旧图号互转,新/旧图号检查,新/旧图号非标准格式转标准格式,新/旧图号转图幅东南西北坐标,坐标点所在图幅 等。鉴于篇幅,完整代码可以到我的GitHub上下载。地址:https://github.com/tanghaojie/Mapnumber
1 using System;
2 using System. Linq;
3
4 namespace Mapnumber {
5
6 ///
19 public class Mapnumber {
20
21 #region Defins about mapnumber 图号定义
22
23 #region 1 million mapnumber defines,same in newmapnumber and oldmapnumber 百万图号定义,新旧图号相同
24
25 ///
29 public static readonly string[] _100W_RowNum = { "A" , "B" , "C" , "D" , "E" , "F" , "G" , "H" , "I" , "J" , "K" , "L" , "M" , "N" , "O" , "P" , "Q" , "R" , "S" , "T" , "U" , "V" };
30 ///
34 public static readonly string[] _100W_ColumnNum = { "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20"
35 , "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40"
36 , "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "60"};
37
38 ///
42 ///
43 public bool Check100W_RowNum( string _100W_RowNum ) {
44 if ( _100W_RowNum. Contains( _100W_RowNum ) ) {
45 return true;
46 }
47 return false;
48 }
49
50 ///
54 ///
55 public bool Check100W_ColumnNum( string _100W_ColumnNum ) {
56 if ( _100W_ColumnNum. Contains( _100W_ColumnNum ) ) {
57 return true;
58 }
59 return false;
60 }
61
62 ///
65 ///
66 public string Change100W_RowDigitalToString( int _100W_RowDigital ) {
67 switch ( _100W_RowDigital ) {
68 case 1:
69 return "A";
70 case 2:
71 return "B";
72 case 3:
73 return "C";
74 case 4:
75 return "D";
76 case 5:
77 return "E";
78 case 6:
79 return "F";
80 case 7:
81 return "G";
82 case 8:
83 return "H";
84 case 9:
85 return "I";
86 case 10:
87 return "J";
88 case 11:
89 return "K";
90 case 12:
91 return "L";
92 case 13:
93 return "M";
94 case 14:
95 return "N";
96 case 15:
97 return "O";
98 case 16:
99 return "P";
100 case 17:
101 return "Q";
102 case 18:
103 return "R";
104 case 19:
105 return "S";
106 case 20:
107 return "T";
108 case 21:
109 return "U";
110 case 22:
111 return "V";
112 default:
113 return "";
114 }
115 }
116
117 ///
120 ///
121 public int Change100W_RowStringToDigital( string _100W_RowString ) {
122 switch ( _100W_RowString ) {
123 case "A":
124 return 1;
125 case "B":
126 return 2;
127 case "C":
128 return 3;
129 case "D":
130 return 4;
131 case "E":
132 return 5;
133 case "F":
134 return 6;
135 case "G":
136 return 7;
137 case "H":
138 return 8;
139 case "I":
140 return 9;
141 case "J":
142 return 10;
143 case "K":
144 return 11;
145 case "L":
146 return 12;
147 case "M":
148 return 13;
149 case "N":
150 return 14;
151 case "O":
152 return 15;
153 case "P":
154 return 16;
155 case "Q":
156 return 17;
157 case "R":
158 return 18;
159 case "S":
160 return 19;
161 case "T":
162 return 20;
163 case "U":
164 return 21;
165 case "V":
166 return 22;
167 default:
168 return -1;
169 }
170 }
171
172 #endregion
173
174 #region Longitude Difference/Latitude Difference 经差、纬差
175
176 ///
180 public const decimal _100W_LongitudeDifference = 6M;
181 ///
185 public const decimal _100W_LatitudeDifference = 4M;
186
187 ///
191 public const decimal _50W_LongitudeDifference = 3M;
192 ///
196 public const decimal _50W_LatitudeDifference = 2M;
197
198 ///
202 public const decimal _25W_LongitudeDifference = 3 / 2M;
203 ///
207 public const decimal _25W_LatitudeDifference = 1M;
208
209 ///
213 public const decimal _20W_LongitudeDifference = 1M;
214 ///
218 public const decimal _20W_LatitudeDifference = 2 / 3M;
219
220 ///
224 public const decimal _10W_LongitudeDifference = 1 / 2M;
225 ///
229 public const decimal _10W_LatitudeDifference = 1 / 3M;
230
231 ///
235 public const decimal _5W_LongitudeDifference = 1 / 4M;
236 ///
240 public const decimal _5W_LatitudeDifference = 1 / 6M;
241
242 ///
246 public const decimal _2_5W_LongitudeDifference = 1 / 8M;
247 ///
251 public const decimal _2_5W_LatitudeDifference = 1 / 12M;
252
253 ///
257 public const decimal _1W_LongitudeDifference = 1 / 16M;
258 ///
262 public const decimal _1W_LatitudeDifference = 1 / 24M;
263
264 ///
268 public const decimal _0_5W_LongitudeDifference = 1 / 32M;
269 ///
273 public const decimal _0_5W_LatitudeDifference = 1 / 48M;
274
275 ///
279 public const decimal _0_2W_LongitudeDifference = 1 / 96M;
280 ///
284 public const decimal _0_2W_LatitudeDifference = 1 / 144M;
285
286 ///
290 public const decimal _0_1W_LongitudeDifference = 1 / 192M;
291 ///
295 public const decimal _0_1W_LatitudeDifference = 1 / 288M;
296
297 ///
301 public const decimal _500_LongitudeDifference = 1 / 384M;
302 ///
306 public const decimal _500_LatitudeDifference = 1 / 576M;
307
308 #endregion
309
310 #region New mapnumber defines 新图幅号定义
311
312 ///
316 public static readonly string[] newMapnumber_ScaleString = { "B" , "C" , "D" , "E" , "F" , "G" , "H" , "I" , "J" , "K" };
317
318 #region New mapnumber max row and column number
319
320 ///
325 private const int newMapnumber_50W_MaxNum = 2;
326
327 ///
331 private const int newMapnumber_25W_MaxNum = 4;
332
333 ///
337 private const int newMapnumber_10W_MaxNum = 12;
338
339 ///
343 private const int newMapnumber_5W_MaxNum = 24;
344
345 ///
349 private const int newMapnumber_2_5W_MaxNum = 48;
350
351 ///
355 private const int newMapnumber_1W_MaxNum = 96;
356
357 ///
361 private const int newMapnumber_0_5W_MaxNum = 192;
362
363 ///
367 private const int newMapnumber_0_2W_MaxNum = 576;
368
369 ///
373 private const int newMapnumber_0_1W_MaxNum = 1152;
374
375 ///
379 private const int newMapnumber_500_MaxNum = 2304;
380
381 #endregion
382
383 ///
386 private string[] NewMapnumber_GetAllRCNumStrsByMaxNum( int maxNum ) {
387 string[] numStr = new string[maxNum];
388 if ( maxNum < 999 ) {
389 for ( int q = 1 ; q <= maxNum ; q++ ) {
390 numStr[q - 1] = q. ToString( "000" );
391 }
392 } else {
393 for ( int q = 1 ; q <= maxNum ; q++ ) {
394 numStr[q - 1] = q. ToString( "0000" );
395 }
396 }
397 return numStr;
398 }
399
400 ///
1204 return false;
1205 }
1206 return true;
1207 }
1208
1209 #endregion
1210
1211 #endregion
1212
1213
1214 #region Exchange new/old mapnumber 新旧图幅号转换
1215
1216 #region Old mapnumber to new mapnumber 旧图号转新图号
1217
1218 ///
1222 ///
1223 ///
1224 public string OldMapnumberToNewMapnumber( string oldMapnumber ) {
1225 if ( !OldMapnumber_Check( oldMapnumber ) ) {
1226 return "";
1227 }
1228 string result = "";
1229 result = OldMapnumberToNewMapnumber_100W( oldMapnumber );
1230 if ( !string. IsNullOrEmpty( result ) ) {
1231 return result;
1232 }
1233 result = OldMapnumberToNewMapnumber_50W( oldMapnumber );
1234 if ( !string. IsNullOrEmpty( result ) ) {
1235 return result;
1236 }
1237 result = OldMapnumberToNewMapnumber_25W( oldMapnumber );
1238 if ( !string. IsNullOrEmpty( result ) ) {
1239 return result;
1240 }
1241 result = OldMapnumberToNewMapnumber_10W( oldMapnumber );
1242 if ( !string. IsNullOrEmpty( result ) ) {
1243 return result;
1244 }
1245 result = OldMapnumberToNewMapnumber_5W( oldMapnumber );
1246 if ( !string. IsNullOrEmpty( result ) ) {
1247 return result;
1248 }
1249 result = OldMapnumberToNewMapnumber_2_5W( oldMapnumber );
1250 if ( !string. IsNullOrEmpty( result ) ) {
1251 return result;
1252 }
1253 result = OldMapnumberToNewMapnumber_1W( oldMapnumber );
1254 if ( !string. IsNullOrEmpty( result ) ) {
1255 return result;
1256 }
1257 result = OldMapnumberToNewMapnumber_0_5W( oldMapnumber );
1258 if ( !string. IsNullOrEmpty( result ) ) {
1259 return result;
1260 }
1261 return result;
1262 }
1263
1264 ///
1268 ///
1269 ///
1270 public string OldMapnumberToNewMapnumber_100W( string oldMapnumber100W ) {
1271 try {
1272 if ( !OldMapnumber_Check100W( oldMapnumber100W ) ) {
1273 return "";
1274 }
1275 string[] temp = oldMapnumber100W. Split( '-' );
1276 string new100 = temp[0] + temp[1]. PadLeft( 2 , '0' );
1277 return new100;
1278 } catch {
1279 throw;
1280 }
1281 }
1282
1283 ///
1287 ///
1288 ///
1289 public string OldMapnumberToNewMapnumber_50W( string oldMapnumber50W ) {
1290 try {
1291 if ( !OldMapnumber_Check50W( oldMapnumber50W ) ) {
1292 return "";
1293 }
1294 string[] temp = oldMapnumber50W. Split( '-' );
1295 string new100 = temp[0] + temp[1]. PadLeft( 2 , '0' );
1296 int x = OldMapnumber_ChangeABCDTo1234( temp[2] );
1297 if ( x <= 0 ) {
1298 return "";
1299 }
1300 int new50R = OldToNew50W_R( x );
1301 int new50C = OldToNew50W_C( x );
1302 return new100 + "B" + new50R. ToString(). PadLeft( 3 , '0' ) + new50C. ToString(). PadLeft( 3 , '0' );
1303 } catch {
1304 throw;
1305 }
1306 }
1307
1308 ///
1615 return "";
1616 }
1617 return o100W + "-[" + o25W. ToString( "00" ) + "]";
1618 }
1619 #endregion
1620 #region 10万
1621 else if ( scaleNumber == 100000 ) {
1622 string o100W = NewMapnumberToOldMapnumber_100W( n100WR , n100WC );
1623 int o10W = NewToOld10WNum( nR , nC );
1624 if ( o10W <= 0 || o10W > 144 ) {
1625 return "";
1626 }
1627 return o100W + "-" + o10W. ToString( "000" );
1628 }
1629 #endregion
1630 #region 5万
1631 else if ( scaleNumber == 50000 ) {
1632 string o100W = NewMapnumberToOldMapnumber_100W( n100WR , n100WC );
1633 int o5W = NewToOld5WNum( nR , nC );
1634 string o5WStr = OldMapnumber_Change1234ToABCD( o5W );
1635 if ( string. IsNullOrEmpty( o5WStr ) ) {
1636 return "";
1637 }
1638 int n10WR = New5WRCToNew10WRC( int. Parse( nR ) );
1639 int n10WC = New5WRCToNew10WRC( int. Parse( nC ) );
1640 int o10W = NewToOld10WNum( n10WR. ToString() , n10WC. ToString() );
1641 if ( o10W <= 0 || o10W > 144 ) {
1642 return "";
1643 }
1644 return o100W + "-" + o10W. ToString( "000" ) + "-" + o5WStr;
1645 }
1646 #endregion
1647 #region 2.5万
1648 else if ( scaleNumber == 25000 ) {
1649 string o100W = NewMapnumberToOldMapnumber_100W( n100WR , n100WC );
1650 int o2_5W = NewToOld2_5WNum( nR , nC );
1651 if ( o2_5W <= 0 || o2_5W > 4 ) {
1652 return "";
1653 }
1654 int n5WR = New2_5WRCToNew5WRC( int. Parse( nR ) );
1655 int n5WC = New2_5WRCToNew5WRC( int. Parse( nC ) );
1656 int o5W = NewToOld5WNum( n5WR. ToString() , n5WC. ToString() );
1657 string o5WStr = OldMapnumber_Change1234ToABCD( o5W );
1658 if ( string. IsNullOrEmpty( o5WStr ) ) {
1659 return "";
1660 }
1661 int n10WR = New5WRCToNew10WRC( n5WR );
1662 int n10WC = New5WRCToNew10WRC( n5WC );
1663 int o10W = NewToOld10WNum( n10WR. ToString() , n10WC. ToString() );
1664 if ( o10W <= 0 || o10W > 144 ) {
1665 return "";
1666 }
1667
1668 return o100W + "-" + o10W. ToString( "000" ) + "-" + o5WStr + "-" + o2_5W. ToString();
1669 }
1670 #endregion
1671 #region 1万
1672 else if ( scaleNumber == 10000 ) {
1673 string o100W = NewMapnumberToOldMapnumber_100W( n100WR , n100WC );
1674 int o1W = NewToOld1WNum( nR , nC );
1675 if ( o1W <= 0 || o1W > 64 ) {
1676 return "";
1677 }
1678 int n10WR = New1WRCToNew10WRC( int. Parse( nR ) );
1679 int n10WC = New1WRCToNew10WRC( int. Parse( nC ) );
1680 int o10W = NewToOld10WNum( n10WR. ToString() , n10WC. ToString() );
1681 if ( o10W <= 0 || o10W > 144 ) {
1682 return "";
1683 }
1684 return o100W + "-" + o10W. ToString( "000" ) + "-(" + o1W. ToString( "00" ) + ")";
1685 }
1686 #endregion
1687 #region 5000
1688 else if ( scaleNumber == 5000 ) {
1689 string o100W = NewMapnumberToOldMapnumber_100W( n100WR , n100WC );
1690 int o0_5W = NewToOld0_5WNum( nR , nC );
1691 string o0_5WStr = OldMapnumber_Change1234Toabcd( o0_5W );
1692 if ( string. IsNullOrEmpty( o0_5WStr ) ) {
1693 return "";
1694 }
1695 int n1WR = New0_5WRCToNew1WRC( int. Parse( nR ) );
1696 int n1WC = New0_5WRCToNew1WRC( int. Parse( nC ) );
1697 int o1W = NewToOld1WNum( n1WR. ToString() , n1WC. ToString() );
1698 if ( o1W <= 0 || o1W > 64 ) {
1699 return "";
1700 }
1701 int n10WR = New1WRCToNew10WRC( n1WR );
1702 int n10WC = New1WRCToNew10WRC( n1WC );
1703 int o10W = NewToOld10WNum( n10WR. ToString() , n10WC. ToString() );
1704 if ( o10W <= 0 || o10W > 144 ) {
1705 return "";
1706 }
1707 return o100W + "-" + o10W. ToString( "000" ) + "-(" + o1W. ToString( "00" ) + ")-" + o0_5WStr;
1708 }
1709 #endregion
1710 else {
1711 return null;
1712 }
1713 } catch {
1714 throw;
1715 }
1716 }
1717
1718 ///
1721 ///
1722 ///
1723 ///
1724 private string NewMapnumberToOldMapnumber_100W( string newMapnumber100WR , string newMapnumber100WC ) {
1725 return newMapnumber100WR + "-" + newMapnumber100WC;
1726 }
1727
1728 #region New mapnumber to old mapnumber calculate row column num 新转旧计算行列号
1729
1730 ///
1733 private int NewToOld50WNum( string newMapnumber50WR , string newMapnumber50WC ) {
1734 int n50WR = int. Parse( newMapnumber50WR );
1735 int n50WC = int. Parse( newMapnumber50WC );
1736 return 2 * ( n50WR - 1 ) + n50WC;
1737 }
1738
1739 ///
1742 private int NewToOld25WNum( string newMapnumber25WR , string newMapnumber25WC ) {
1743 int n25WR = int. Parse( newMapnumber25WR );
1744 int n25WC = int. Parse( newMapnumber25WC );
1745 return 4 * ( n25WR - 1 ) + n25WC;
1746 }
1747
1748 ///
1751 private int NewToOld10WNum( string newMapnumber10WR , string newMapnumber10WC ) {
1752 int n10WR = int. Parse( newMapnumber10WR );
1753 int n10WC = int. Parse( newMapnumber10WC );
1754 return 12 * ( n10WR - 1 ) + n10WC;
1755 }
1756
1757 ///
1760 private int NewToOld5WNum( string newMapnumber5WR , string newMapnumber5WC ) {
1761 int n5WR = int. Parse( newMapnumber5WR );
1762 int n5WC = int. Parse( newMapnumber5WC );
1763 return 2 * n5WR + n5WC - ( 4 * ( (int) ( n5WR - 1 ) / 2 ) ) - ( 2 * ( (int) ( n5WC - 1 ) / 2 ) ) - 2;
1764 }
1765
1766 ///
1769 private int NewToOld2_5WNum( string newMapnumber2_5WR , string newMapnumber2_5WC ) {
1770 int n2_5WR = int. Parse( newMapnumber2_5WR );
1771 int n2_5WC = int. Parse( newMapnumber2_5WC );
1772 return 2 * n2_5WR + n2_5WC - ( 4 * ( (int) ( n2_5WR - 1 ) / 2 ) ) - ( 2 * ( (int) ( n2_5WC - 1 ) / 2 ) ) - 2;
1773 }
1774
1775 ///
1778 private int NewToOld1WNum( string newMapnumber1WR , string newMapnumber1WC ) {
1779 int n1WR = int. Parse( newMapnumber1WR );
1780 int n1WC = int. Parse( newMapnumber1WC );
1781 return 8 * n1WR + n1WC - ( 64 * ( (int) ( n1WR - 1 ) / 8 ) ) - ( 8 * ( (int) ( n1WC - 1 ) / 8 ) ) - 8;
1782 }
1783
1784 ///
1787 private int NewToOld0_5WNum( string newMapnumber0_5WR , string newMapnumber0_5WC ) {
1788 int n0_5WR = int. Parse( newMapnumber0_5WR );
1789 int n0_5WC = int. Parse( newMapnumber0_5WC );
1790 return 2 * n0_5WR + n0_5WC - ( 4 * ( (int) ( n0_5WR - 1 ) / 2 ) ) - ( 2 * ( (int) ( n0_5WC - 1 ) / 2 ) ) - 2;
1791 }
1792
1793 ///
1796 ///
1797 ///
1798 private int New5WRCToNew10WRC( int newMapnumber5WRC ) {
1799 return (int) ( ( newMapnumber5WRC - 1 ) / 2 ) + 1;
1800 }
1801
1802 private int New2_5WRCToNew5WRC( int newMapnumber2_5WRC ) {
1803 return (int) ( ( newMapnumber2_5WRC - 1 ) / 2 ) + 1;
1804 }
1805
1806 private int New1WRCToNew10WRC( int newMapnumber1WRC ) {
1807 return (int) ( ( newMapnumber1WRC - 1 ) / 8 ) + 1;
1808 }
1809
1810 private int New0_5WRCToNew1WRC( int newMapnumber0_5WRC ) {
1811 return (int) ( ( newMapnumber0_5WRC - 1 ) / 2 ) + 1;
1812 }
1813
1814 #endregion
1815
1816 #endregion
1817
1818 #region New mapnumber to new mapnumber 新图号转新图号
1819
1820 ///
1824 ///
1825 ///
1826 public string NewMapnumberToNewMapnumber( string newMapnumber ) {
1827 if ( NewMapnumber_Check( newMapnumber ) ) {
1828 return newMapnumber;
1829 }
1830
1831 newMapnumber = newMapnumber. ToUpper();
1832 if ( NewMapnumber_Check( newMapnumber ) ) {
1833 return newMapnumber;
1834 }
1835
1836 return "";
1837 }
1838
1839 #endregion
1840
1841 #region Old mapnumber to old mapnumber 旧图号转旧图号
1842
1843 ///
1847 ///
1848 ///
1849 ///
1850 public string OldMapnumberToOldMapnumber( string oldMapnumber , int scaleDenominator ) {
1851 if ( scaleDenominator == 1000000 ) {
1852 return OldMapnumberToOldMapnumber100W( oldMapnumber );
1853 } else if ( scaleDenominator == 500000 ) {
1854 return OldMapnumberToOldMapnumber50W( oldMapnumber );
1855 } else if ( scaleDenominator == 250000 ) {
1856 return OldMapnumberToOldMapnumber25W( oldMapnumber );
1857 } else if ( scaleDenominator == 100000 ) {
1858 return OldMapnumberToOldMapnumber10W( oldMapnumber );
1859 } else if ( scaleDenominator == 50000 ) {
1860 return OldMapnumberToOldMapnumber5W( oldMapnumber );
1861 } else if ( scaleDenominator == 25000 ) {
1862 return OldMapnumberToOldMapnumber2_5W( oldMapnumber );
1863 } else if ( scaleDenominator == 10000 ) {
1864 return OldMapnumberToOldMapnumber1W( oldMapnumber );
1865 } else if ( scaleDenominator == 5000 ) {
1866 return OldMapnumberToOldMapnumber0_5W( oldMapnumber );
1867 } else {
1868 return "";
1869 }
1870 }
1871
1872 ///
1875 ///
1876 ///
1877 private string ChangeOldMapnumberChar( string oldMapnumber ) {
1878 oldMapnumber = oldMapnumber. Replace( "(" , "" );
1879 oldMapnumber = oldMapnumber. Replace( ")" , "" );
1880 oldMapnumber = oldMapnumber. Replace( "(" , "" );
1881 oldMapnumber = oldMapnumber. Replace( ")" , "" );
1882 oldMapnumber = oldMapnumber. Replace( "【" , "" );
1883 oldMapnumber = oldMapnumber. Replace( "】" , "" );
1884 oldMapnumber = oldMapnumber. Replace( "甲" , "1" );
1885 oldMapnumber = oldMapnumber. Replace( "乙" , "2" );
1886 oldMapnumber = oldMapnumber. Replace( "丙" , "3" );
1887 oldMapnumber = oldMapnumber. Replace( "丁" , "4" );
1888 oldMapnumber = oldMapnumber. Replace( "A" , "1" );
1889 oldMapnumber = oldMapnumber. Replace( "B" , "2" );
1890 oldMapnumber = oldMapnumber. Replace( "C" , "3" );
1891 oldMapnumber = oldMapnumber. Replace( "D" , "4" );
1892 oldMapnumber = oldMapnumber. Replace( "a" , "1" );
1893 oldMapnumber = oldMapnumber. Replace( "b" , "2" );
1894 oldMapnumber = oldMapnumber. Replace( "c" , "3" );
1895 oldMapnumber = oldMapnumber. Replace( "d" , "4" );
1896
1897 oldMapnumber = oldMapnumber. ToUpper();
1898 foreach ( string m100WR in _100W_RowNum ) {
1899 oldMapnumber = oldMapnumber. Replace( m100WR , Change100W_RowStringToDigital( m100WR ). ToString() );
1900 }
1901 return oldMapnumber;
1902 }
1903
1904 ///
1907 private string OldMapnumberToOldMapnumber100W( string oldMapnumber100W ) {
1908 if ( string. IsNullOrEmpty( oldMapnumber100W ) ) {
1909 return "";
1910 }
1911 if ( OldMapnumber_Check100W( oldMapnumber100W ) ) {
1912 return oldMapnumber100W;
1913 }
1914
1915 oldMapnumber100W = ChangeOldMapnumberChar( oldMapnumber100W );
1916 if ( !oldMapnumber100W. Contains( '-' ) ) {
1917 return "";
1918 }
1919 string[] split = oldMapnumber100W. Split( new char[] { '-' } , StringSplitOptions. RemoveEmptyEntries );
1920 int length = split. Length;
1921 if ( length != 2 ) {
1922 return "";
1923 }
1924
1925 int x100R = -1;
1926 if ( !int. TryParse( split[0] , out x100R ) ) {
1927 return "";
1928 }
1929 int x100C = -1;
1930 if ( !int. TryParse( split[1] , out x100C ) ) {
1931 return "";
1932 }
1933
1934 string s100R = Change100W_RowDigitalToString( x100R );
1935 string s100C = x100C. ToString( "00" );
1936 oldMapnumber100W = s100R + "-" + s100C;
1937 if ( OldMapnumber_Check100W( oldMapnumber100W ) ) {
1938 return oldMapnumber100W;
1939 }
1940 return "";
1941 }
1942
1943 ///
1946 private string OldMapnumberToOldMapnumber50W( string oldMapnumber50W ) {
1947 if ( string. IsNullOrEmpty( oldMapnumber50W ) ) {
1948 return "";
1949 }
1950 if ( OldMapnumber_Check50W( oldMapnumber50W ) ) {
1951 return oldMapnumber50W;
1952 }
1953
1954 oldMapnumber50W = ChangeOldMapnumberChar( oldMapnumber50W );
1955 if ( !oldMapnumber50W. Contains( '-' ) ) {
1956 return "";
1957 }
1958 string[] split = oldMapnumber50W. Split( new char[] { '-' } , StringSplitOptions. RemoveEmptyEntries );
1959 int length = split. Length;
1960 if ( length != 3 ) {
1961 return "";
1962 }
1963 string x100 = split[0] + "-" + split[1];
1964 string s100 = OldMapnumberToOldMapnumber100W( x100 );
1965 if ( string. IsNullOrEmpty( s100 ) ) {
1966 return "";
1967 }
1968
1969 int x50 = -1;
1970 if ( !int. TryParse( split[2] , out x50 ) ) {
1971 return "";
1972 }
1973 string s50 = OldMapnumber_Change1234ToABCD( x50 );
1974 oldMapnumber50W = s100 + "-" + s50;
1975 if ( OldMapnumber_Check50W( oldMapnumber50W ) ) {
1976 return oldMapnumber50W;
1977 }
1978 return "";
1979 }
1980
1981 ///
1984 private string OldMapnumberToOldMapnumber25W( string oldMapnumber25W ) {
1985 if ( string. IsNullOrEmpty( oldMapnumber25W ) ) {
1986 return "";
1987 }
1988 if ( OldMapnumber_Check25W( oldMapnumber25W ) ) {
1989 return oldMapnumber25W;
1990 }
1991
1992 oldMapnumber25W = ChangeOldMapnumberChar( oldMapnumber25W );
1993 if ( !oldMapnumber25W. Contains( '-' ) ) {
1994 return "";
1995 }
1996 string[] split = oldMapnumber25W. Split( new char[] { '-' } , StringSplitOptions. RemoveEmptyEntries );
1997 int length = split. Length;
1998 if ( length != 3 ) {
1999 return "";
2000 }
2001 string x100 = split[0] + "-" + split[1];
2002 string s100 = OldMapnumberToOldMapnumber100W( x100 );
2003 if ( string. IsNullOrEmpty( s100 ) ) {
2004 return "";
2005 }
2006
2007 int x25 = -1;
2008 if ( !int. TryParse( split[2] , out x25 ) ) {
2009 return "";
2010 }
2011 string s25 = x25. ToString( "00" );
2012 oldMapnumber25W = s100 + "-[" + s25 + "]";
2013 if ( OldMapnumber_Check25W( oldMapnumber25W ) ) {
2014 return oldMapnumber25W;
2015 }
2016 return "";
2017 }
2018
2019 ///
2022 private string OldMapnumberToOldMapnumber10W( string oldMapnumber10W ) {
2023 if ( string. IsNullOrEmpty( oldMapnumber10W ) ) {
2024 return "";
2025 }
2026 if ( OldMapnumber_Check10W( oldMapnumber10W ) ) {
2027 return oldMapnumber10W;
2028 }
2029
2030 oldMapnumber10W = ChangeOldMapnumberChar( oldMapnumber10W );
2031 if ( !oldMapnumber10W. Contains( '-' ) ) {
2032 return "";
2033 }
2034 string[] split = oldMapnumber10W. Split( new char[] { '-' } , StringSplitOptions. RemoveEmptyEntries );
2035 int length = split. Length;
2036 if ( length != 3 ) {
2037 return "";
2038 }
2039 string x100 = split[0] + "-" + split[1];
2040 string s100 = OldMapnumberToOldMapnumber100W( x100 );
2041 if ( string. IsNullOrEmpty( s100 ) ) {
2042 return "";
2043 }
2044
2045 int x10 = -1;
2046 if ( !int. TryParse( split[2] , out x10 ) ) {
2047 return "";
2048 }
2049 string s10 = x10. ToString( "000" );
2050 oldMapnumber10W = s100 + "-" + s10;
2051 if ( OldMapnumber_Check10W( oldMapnumber10W ) ) {
2052 return oldMapnumber10W;
2053 }
2054 return "";
2055 }
2056
2057 ///
2060 private string OldMapnumberToOldMapnumber5W( string oldMapnumber5W ) {
2061 if ( string. IsNullOrEmpty( oldMapnumber5W ) ) {
2062 return "";
2063 }
2064 if ( OldMapnumber_Check5W( oldMapnumber5W ) ) {
2065 return oldMapnumber5W;
2066 }
2067
2068 oldMapnumber5W = ChangeOldMapnumberChar( oldMapnumber5W );
2069 if ( !oldMapnumber5W. Contains( '-' ) ) {
2070 return "";
2071 }
2072 string[] split = oldMapnumber5W. Split( new char[] { '-' } , StringSplitOptions. RemoveEmptyEntries );
2073 int length = split. Length;
2074 if ( length != 4 ) {
2075 return "";
2076 }
2077 string x10 = split[0] + "-" + split[1] + "-" + split[2];
2078 string s10 = OldMapnumberToOldMapnumber10W( x10 );
2079 if ( string. IsNullOrEmpty( s10 ) ) {
2080 return "";
2081 }
2082
2083 int x5 = -1;
2084 if ( !int. TryParse( split[3] , out x5 ) ) {
2085 return "";
2086 }
2087 string s5 = OldMapnumber_Change1234ToABCD( x5 );
2088 oldMapnumber5W = s10 + "-" + s5;
2089 if ( OldMapnumber_Check5W( oldMapnumber5W ) ) {
2090 return oldMapnumber5W;
2091 }
2092 return "";
2093 }
2094
2095 ///
2098 private string OldMapnumberToOldMapnumber2_5W( string oldMapnumber2_5W ) {
2099 if ( string. IsNullOrEmpty( oldMapnumber2_5W ) ) {
2100 return "";
2101 }
2102 if ( OldMapnumber_Check2_5W( oldMapnumber2_5W ) ) {
2103 return oldMapnumber2_5W;
2104 }
2105
2106 oldMapnumber2_5W = ChangeOldMapnumberChar( oldMapnumber2_5W );
2107 if ( !oldMapnumber2_5W. Contains( '-' ) ) {
2108 return "";
2109 }
2110 string[] split = oldMapnumber2_5W. Split( new char[] { '-' } , StringSplitOptions. RemoveEmptyEntries );
2111 int length = split. Length;
2112 if ( length != 5 ) {
2113 return "";
2114 }
2115 string x5 = split[0] + "-" + split[1] + "-" + split[2] + "-" + split[3];
2116 string s5 = OldMapnumberToOldMapnumber5W( x5 );
2117 if ( string. IsNullOrEmpty( s5 ) ) {
2118 return "";
2119 }
2120
2121 int x2_5 = -1;
2122 if ( !int. TryParse( split[4] , out x2_5 ) ) {
2123 return "";
2124 }
2125 string s2_5 = x2_5. ToString();
2126 oldMapnumber2_5W = s5 + "-" + s2_5;
2127 if ( OldMapnumber_Check2_5W( oldMapnumber2_5W ) ) {
2128 return oldMapnumber2_5W;
2129 }
2130 return "";
2131 }
2132
2133 ///
2136 private string OldMapnumberToOldMapnumber1W( string oldMapnumber1W ) {
2137 if ( string. IsNullOrEmpty( oldMapnumber1W ) ) {
2138 return "";
2139 }
2140 if ( OldMapnumber_Check1W( oldMapnumber1W ) ) {
2141 return oldMapnumber1W;
2142 }
2143
2144 oldMapnumber1W = ChangeOldMapnumberChar( oldMapnumber1W );
2145 if ( !oldMapnumber1W. Contains( '-' ) ) {
2146 return "";
2147 }
2148 string[] split = oldMapnumber1W. Split( new char[] { '-' } , StringSplitOptions. RemoveEmptyEntries );
2149 int length = split. Length;
2150 if ( length != 4 ) {
2151 return "";
2152 }
2153 string x10 = split[0] + "-" + split[1] + "-" + split[2];
2154 string s10 = OldMapnumberToOldMapnumber10W( x10 );
2155 if ( string. IsNullOrEmpty( s10 ) ) {
2156 return "";
2157 }
2158
2159 int x1 = -1;
2160 if ( !int. TryParse( split[3] , out x1 ) ) {
2161 return "";
2162 }
2163 string s1 = x1. ToString( "00" );
2164 oldMapnumber1W = s10 + "-(" + s1 + ")";
2165 if ( OldMapnumber_Check1W( oldMapnumber1W ) ) {
2166 return oldMapnumber1W;
2167 }
2168 return "";
2169 }
2170
2171 ///
2174 private string OldMapnumberToOldMapnumber0_5W( string oldMapnumber0_5W ) {
2175 if ( string. IsNullOrEmpty( oldMapnumber0_5W ) ) {
2176 return "";
2177 }
2178 if ( OldMapnumber_Check0_5W( oldMapnumber0_5W ) ) {
2179 return oldMapnumber0_5W;
2180 }
2181
2182 oldMapnumber0_5W = ChangeOldMapnumberChar( oldMapnumber0_5W );
2183 if ( !oldMapnumber0_5W. Contains( '-' ) ) {
2184 return "";
2185 }
2186 string[] split = oldMapnumber0_5W. Split( new char[] { '-' } , StringSplitOptions. RemoveEmptyEntries );
2187 int length = split. Length;
2188 if ( length != 5 ) {
2189 return "";
2190 }
2191 string x1 = split[0] + "-" + split[1] + "-" + split[2] + "-(" + split[3] + ")";
2192 string s1 = OldMapnumberToOldMapnumber1W( x1 );
2193 if ( string. IsNullOrEmpty( s1 ) ) {
2194 return "";
2195 }
2196
2197 int x0_5 = -1;
2198 if ( !int. TryParse( split[4] , out x0_5 ) ) {
2199 return "";
2200 }
2201 string s0_5 = OldMapnumber_Change1234Toabcd( x0_5 );
2202 oldMapnumber0_5W = s1 + "-" + s0_5;
2203 if ( OldMapnumber_Check0_5W( oldMapnumber0_5W ) ) {
2204 return oldMapnumber0_5W;
2205 }
2206 return "";
2207 }
2208
2209 #endregion
2210
2211
2212 #endregion
2213
2214
2215 #region Exchange between mapnumber and coordinate 图幅号和坐标的转换
2216
2217 #region Mapnumber to coordinate 图号转坐标
2218
2219 #region New mapnumber to coordinate 新图号转坐标
2220
2221 ///
2225 ///
2226 ///
2227 public decimal[] CalculateLongitudeLatitudeFromNewMapnumber( string newMapnumber ) {
2228 try {
2229 decimal[] WNES = new decimal[4];
2230 string[] newMapnumberInfo = GetInfoFromNewMapnumber( newMapnumber );
2231 if ( newMapnumberInfo == null ) {
2232 return null;
2233 }
2234 string n100WR = newMapnumberInfo[0];
2235 string n100WC = newMapnumberInfo[1];
2236 string nScaleStr = newMapnumberInfo[2];
2237 string nR = newMapnumberInfo[3];
2238 string nC = newMapnumberInfo[4];
2239 int scaleNumber = NewMapnumber_GetScaleDenominatorNumberByScaleStr( nScaleStr );
2240 if ( scaleNumber == -1 ) {
2241 return null;
2242 }
2243 #region 100万
2244 else if ( scaleNumber == 1000000 ) {
2245 decimal W = CalculateLongitudeLatitudeFromNewMapnumberWest( n100WC , _100W_LatitudeDifference , "0" , 0 );
2246 decimal S = CalculateLongitudeLatitudeFromNewMapnumberSouth( n100WR , _100W_LongitudeDifference , "0" , 0 );
2247 decimal N = S + _100W_LongitudeDifference;
2248 decimal E = W + _100W_LatitudeDifference;
2249 WNES[0] = W;
2250 WNES[1] = N;
2251 WNES[2] = E;
2252 WNES[3] = S;
2253 return WNES;
2254 }
2255 #endregion
2256 #region 50万
2257 else if ( scaleNumber == 500000 ) {
2258 decimal W = CalculateLongitudeLatitudeFromNewMapnumberWest( n100WC , _100W_LatitudeDifference , nC , _50W_LongitudeDifference );
2259 decimal S = CalculateLongitudeLatitudeFromNewMapnumberSouth( n100WR , _100W_LongitudeDifference , nR , _50W_LatitudeDifference );
2260 decimal N = S + _50W_LatitudeDifference;
2261 decimal E = W + _50W_LongitudeDifference;
2262 WNES[0] = W;
2263 WNES[1] = N;
2264 WNES[2] = E;
2265 WNES[3] = S;
2266 return WNES;
2267 }
2268 #endregion
2269 #region 25万
2270 else if ( scaleNumber == 250000 ) {
2271 decimal W = CalculateLongitudeLatitudeFromNewMapnumberWest( n100WC , _100W_LatitudeDifference , nC , _25W_LongitudeDifference );
2272 decimal S = CalculateLongitudeLatitudeFromNewMapnumberSouth( n100WR , _100W_LongitudeDifference , nR , _25W_LatitudeDifference );
2273 decimal N = S + _25W_LatitudeDifference;
2274 decimal E = W + _25W_LongitudeDifference;
2275 WNES[0] = W;
2276 WNES[1] = N;
2277 WNES[2] = E;
2278 WNES[3] = S;
2279 return WNES;
2280 }
2281 #endregion
2282 #region 10万
2283 else if ( scaleNumber == 100000 ) {
2284 decimal W = CalculateLongitudeLatitudeFromNewMapnumberWest( n100WC , _100W_LatitudeDifference , nC , _10W_LongitudeDifference );
2285 decimal S = CalculateLongitudeLatitudeFromNewMapnumberSouth( n100WR , _100W_LongitudeDifference , nR , _10W_LatitudeDifference );
2286 decimal N = S + _10W_LatitudeDifference;
2287 decimal E = W + _10W_LongitudeDifference;
2288 WNES[0] = W;
2289 WNES[1] = N;
2290 WNES[2] = E;
2291 WNES[3] = S;
2292 return WNES;
2293 }
2294 #endregion
2295 #region 5万
2296 else if ( scaleNumber == 50000 ) {
2297 decimal W = CalculateLongitudeLatitudeFromNewMapnumberWest( n100WC , _100W_LatitudeDifference , nC , _5W_LongitudeDifference );
2298 decimal S = CalculateLongitudeLatitudeFromNewMapnumberSouth( n100WR , _100W_LongitudeDifference , nR , _5W_LatitudeDifference );
2299 decimal N = S + _5W_LatitudeDifference;
2300 decimal E = W + _5W_LongitudeDifference;
2301 WNES[0] = W;
2302 WNES[1] = N;
2303 WNES[2] = E;
2304 WNES[3] = S;
2305 return WNES;
2306 }
2307 #endregion
2308 #region 2.5万
2309 else if ( scaleNumber == 25000 ) {
2310 decimal W = CalculateLongitudeLatitudeFromNewMapnumberWest( n100WC , _100W_LatitudeDifference , nC , _2_5W_LongitudeDifference );
2311 decimal S = CalculateLongitudeLatitudeFromNewMapnumberSouth( n100WR , _100W_LongitudeDifference , nR , _2_5W_LatitudeDifference );
2312 decimal N = S + _2_5W_LatitudeDifference;
2313 decimal E = W + _2_5W_LongitudeDifference;
2314 WNES[0] = W;
2315 WNES[1] = N;
2316 WNES[2] = E;
2317 WNES[3] = S;
2318 return WNES;
2319 }
2320 #endregion
2321 #region 1万
2322 else if ( scaleNumber == 10000 ) {
2323 decimal W = CalculateLongitudeLatitudeFromNewMapnumberWest( n100WC , _100W_LatitudeDifference , nC , _1W_LongitudeDifference );
2324 decimal S = CalculateLongitudeLatitudeFromNewMapnumberSouth( n100WR , _100W_LongitudeDifference , nR , _1W_LatitudeDifference );
2325 decimal N = S + _1W_LatitudeDifference;
2326 decimal E = W + _1W_LongitudeDifference;
2327 WNES[0] = W;
2328 WNES[1] = N;
2329 WNES[2] = E;
2330 WNES[3] = S;
2331 return WNES;
2332 }
2333 #endregion
2334 #region 5000
2335 else if ( scaleNumber == 5000 ) {
2336 decimal W = CalculateLongitudeLatitudeFromNewMapnumberWest( n100WC , _100W_LatitudeDifference , nC , _0_5W_LongitudeDifference );
2337 decimal S = CalculateLongitudeLatitudeFromNewMapnumberSouth( n100WR , _100W_LongitudeDifference , nR , _0_5W_LatitudeDifference );
2338 decimal N = S + _0_5W_LatitudeDifference;
2339 decimal E = W + _0_5W_LongitudeDifference;
2340 WNES[0] = W;
2341 WNES[1] = N;
2342 WNES[2] = E;
2343 WNES[3] = S;
2344 return WNES;
2345 }
2346 #endregion
2347 #region 2000
2348 else if ( scaleNumber == 2000 ) {
2349 decimal W = CalculateLongitudeLatitudeFromNewMapnumberWest( n100WC , _100W_LatitudeDifference , nC , _0_2W_LongitudeDifference );
2350 decimal S = CalculateLongitudeLatitudeFromNewMapnumberSouth( n100WR , _100W_LongitudeDifference , nR , _0_2W_LatitudeDifference );
2351 decimal N = S + _0_2W_LatitudeDifference;
2352 decimal E = W + _0_2W_LongitudeDifference;
2353 WNES[0] = W;
2354 WNES[1] = N;
2355 WNES[2] = E;
2356 WNES[3] = S;
2357 return WNES;
2358 }
2359 #endregion
2360 #region 1000
2361 else if ( scaleNumber == 1000 ) {
2362 decimal W = CalculateLongitudeLatitudeFromNewMapnumberWest( n100WC , _100W_LatitudeDifference , nC , _0_1W_LongitudeDifference );
2363 decimal S = CalculateLongitudeLatitudeFromNewMapnumberSouth( n100WR , _100W_LongitudeDifference , nR , _0_1W_LatitudeDifference );
2364 decimal N = S + _0_1W_LatitudeDifference;
2365 decimal E = W + _0_1W_LongitudeDifference;
2366 WNES[0] = W;
2367 WNES[1] = N;
2368 WNES[2] = E;
2369 WNES[3] = S;
2370 return WNES;
2371 }
2372 #endregion
2373 #region 500
2374 else if ( scaleNumber == 500 ) {
2375 decimal W = CalculateLongitudeLatitudeFromNewMapnumberWest( n100WC , _100W_LatitudeDifference , nC , _500_LongitudeDifference );
2376 decimal S = CalculateLongitudeLatitudeFromNewMapnumberSouth( n100WR , _100W_LongitudeDifference , nR , _500_LatitudeDifference );
2377 decimal N = S + _500_LatitudeDifference;
2378 decimal E = W + _500_LongitudeDifference;
2379 WNES[0] = W;
2380 WNES[1] = N;
2381 WNES[2] = E;
2382 WNES[3] = S;
2383 return WNES;
2384 }
2385 #endregion
2386 else {
2387 return null;
2388 }
2389 } catch {
2390 throw;
2391 }
2392 }
2393
2394 ///
2397 private decimal CalculateLongitudeLatitudeFromNewMapnumberWest( string newMapnumber_100W_Column , decimal newMapnumber_100W_LongitudeDifference ,
2398 string subColumn , decimal subLongitudeDifference ) {
2399 try {
2400 if ( string. IsNullOrEmpty( newMapnumber_100W_Column ) ) {
2401 return 0;
2402 }
2403 if ( string. IsNullOrEmpty( subColumn ) ) {
2404 subColumn = "0";
2405 }
2406 decimal n100WC_d = decimal. Parse( newMapnumber_100W_Column );
2407 decimal subC_d = decimal. Parse( subColumn );
2408 decimal x = ( n100WC_d - 31 ) * newMapnumber_100W_LongitudeDifference + ( subC_d - 1 ) * subLongitudeDifference;
2409 return x;
2410 } catch {
2411 throw;
2412 }
2413 }
2414
2415 ///
2418 private decimal CalculateLongitudeLatitudeFromNewMapnumberSouth( string newMapnumber_100W_Row , decimal newMapnumber_100W_LatitudeDifference ,
2419 string subRow , decimal subLatitudeDifference ) {
2420 try {
2421 if ( string. IsNullOrEmpty( newMapnumber_100W_Row ) ) {
2422 return 0;
2423 }
2424 if ( string. IsNullOrEmpty( subRow ) ) {
2425 subRow = "0";
2426 }
2427 int n100WRInt = Change100W_RowStringToDigital( newMapnumber_100W_Row );
2428 if ( n100WRInt == -1 ) {
2429 return 0;
2430 }
2431 decimal n100WR_d = decimal. Parse( n100WRInt. ToString() );
2432 decimal subR_d = decimal. Parse( subRow );
2433 if ( subLatitudeDifference == 0M ) {
2434 decimal x = ( n100WR_d - 1 ) * newMapnumber_100W_LatitudeDifference;
2435 return x;
2436 } else {
2437 decimal x = ( n100WR_d - 1 ) * newMapnumber_100W_LatitudeDifference + ( newMapnumber_100W_LatitudeDifference / subLatitudeDifference - subR_d ) * subLatitudeDifference;
2438 return x;
2439 }
2440 } catch {
2441 throw;
2442 }
2443 }
2444
2445 #endregion
2446
2447 #region Old mapnumber to coordinate 旧图号转坐标
2448
2449 ///
2453 ///
2454 ///
2455 public decimal[] CalculateLongitudeLatitudeFromOldMapnumber( string oldMapnumber ) {
2456 try {
2457 string newMapnumber = OldMapnumberToNewMapnumber( oldMapnumber );
2458 if ( string. IsNullOrEmpty( newMapnumber ) ) {
2459 return CalculateLongitudeLatitudeFromNewMapnumber( newMapnumber );
2460 } else {
2461 return CalculateLongitudeLatitudeFromOldMapnumber20W( oldMapnumber );
2462 }
2463 } catch {
2464 throw;
2465 }
2466 }
2467
2468 ///
2472 ///
2473 ///
2474 public decimal[] CalculateLongitudeLatitudeFromOldMapnumber20W( string oldMapnumber20W ) {
2475 try {
2476 if ( !OldMapnumber_Check20W( oldMapnumber20W ) ) {
2477 return null;
2478 }
2479 decimal[] WNES = new decimal[4];
2480 string[] split = oldMapnumber20W. Split( new char[] { '-' } , StringSplitOptions. RemoveEmptyEntries );
2481 string o100WR = split[0];
2482 string o100WC = split[1];
2483 string o20W = split[2];
2484 string[] subSplit = o20W. Split( new char[] { '(' , ')' } , StringSplitOptions. RemoveEmptyEntries );
2485 string o20WNum = subSplit[0];
2486 decimal o100WW = CalculateLongitudeLatitudeFromNewMapnumberWest( o100WC , _100W_LatitudeDifference , "0" , 0 );
2487 decimal o100WS = CalculateLongitudeLatitudeFromNewMapnumberSouth( o100WR , _100W_LongitudeDifference , "0" , 0 );
2488 int i20WNum = int. Parse( o20WNum );
2489 int o20WR = Old20WR( i20WNum );
2490 int o20WC = Old20WC( i20WNum );
2491 decimal W = o100WW + ( o20WC - 1 ) * _20W_LongitudeDifference;
2492 decimal S = o100WS + ( oldMapnumber_20W_RCNum - o20WR ) * _20W_LatitudeDifference;
2493 decimal N = S + _20W_LatitudeDifference;
2494 decimal E = W + _20W_LongitudeDifference;
2495 WNES[0] = W;
2496 WNES[1] = N;
2497 WNES[2] = E;
2498 WNES[3] = S;
2499 return WNES;
2500 } catch {
2501 throw;
2502 }
2503 }
2504
2505 private int Old20WR( int o20WNum ) {
2506 return ( ( o20WNum - 1 ) / oldMapnumber_20W_RCNum ) + 1;
2507 }
2508 private int Old20WC( int o20WNum ) {
2509 return ( ( o20WNum - 1 ) % oldMapnumber_20W_RCNum ) + 1;
2510 }
2511
2512 #endregion
2513
2514 #endregion
2515
2516 #region Coordinate to mapnumber 坐标转图号
2517
2518 #region Coordinate to new mapnumber 坐标转新图号
2519
2520 ///
2524 /// longitude/经度
2525 /// latitude/纬度
2526 /// scaleDenominator/比例尺分母
2527 ///
2528 public string CalculateNewMapnumberFromLongitudeLatitude( decimal longitude , decimal latitude , int scaleDenominator ) {
2529 try {
2530 string newMapnumber_100W = CalculateNewMapnumberFromLongitudeLatitude100W( longitude , latitude );
2531 if ( string. IsNullOrEmpty( newMapnumber_100W ) ) {
2532 return "";
2533 }
2534 decimal[] longitudeLatitudeDifference = GetLongitudeLatitudeDifference( scaleDenominator );
2535 decimal longitudeDifference = longitudeLatitudeDifference[0];
2536 decimal latitudeDifference = longitudeLatitudeDifference[1];
2537
2538 int[] subRC = CalculateNewMapnumberRowColumnIn100WFromLongitudeLatitude( longitude , latitude , longitudeDifference , latitudeDifference );
2539 string scaleStr = GetNewMapnumberScaleString( scaleDenominator );
2540 string r = "";
2541 string c = "";
2542 if ( scaleStr == "J" || scaleStr == "K" ) {
2543 r = subRC[0]. ToString( "0000" );
2544 c = subRC[1]. ToString( "0000" );
2545 } else {
2546 r = subRC[0]. ToString( "000" );
2547 c = subRC[1]. ToString( "000" );
2548 }
2549 if ( string. IsNullOrEmpty( scaleStr ) ) {
2550 scaleStr = "";
2551 r = "";
2552 c = "";
2553 }
2554 string newMapnumber = newMapnumber_100W + scaleStr + r + c;
2555 if ( NewMapnumber_Check( newMapnumber ) ) {
2556 return newMapnumber;
2557 } else {
2558 return "";
2559 }
2560 } catch {
2561 throw;
2562 }
2563 }
2564
2565 ///
2569 ///
2570 ///
2571 ///
2572 public string CalculateNewMapnumberFromLongitudeLatitude100W( decimal longitude , decimal latitude ) {
2573 try {
2574 int rNum = (int) ( latitude / _100W_LongitudeDifference ) + 1;
2575 int cNum = (int) ( longitude / _100W_LatitudeDifference ) + 31;
2576 string rStr = Change100W_RowDigitalToString( rNum );
2577 string n100W = rStr + cNum. ToString( "00" );
2578 if ( NewMapnumber_Check( n100W ) ) {
2579 return n100W;
2580 } else {
2581 return "";
2582 }
2583 } catch {
2584 throw;
2585 }
2586 }
2587
2588 ///
2592 ///
2593 ///
2594 ///
2595 public string CalculateNewMapnumberFromLongitudeLatitude50W( decimal longitude , decimal latitude ) {
2596 try {
2597 string n100W = CalculateNewMapnumberFromLongitudeLatitude100W( longitude , latitude );
2598 if ( string. IsNullOrEmpty( n100W ) ) {
2599 return "";
2600 }
2601 int[] subRC = CalculateNewMapnumberRowColumnIn100WFromLongitudeLatitude( longitude , latitude , _50W_LongitudeDifference , _50W_LatitudeDifference );
2602 string r = subRC[0]. ToString( "000" );
2603 string c = subRC[1]. ToString( "000" );
2604 string n50W = n100W + "B" + r + c;
2605 if ( NewMapnumber_Check( n50W ) ) {
2606 return n50W;
2607 } else {
2608 return "";
2609 }
2610 } catch {
2611 throw;
2612 }
2613 }
2614
2615 ///
2619 ///
2620 ///
2621 ///
2622 public string CalculateNewMapnumberFromLongitudeLatitude25W( decimal longitude , decimal latitude ) {
2623 try {
2624 string n100W = CalculateNewMapnumberFromLongitudeLatitude100W( longitude , latitude );
2625 if ( string. IsNullOrEmpty( n100W ) ) {
2626 return "";
2627 }
2628 int[] subRC = CalculateNewMapnumberRowColumnIn100WFromLongitudeLatitude( longitude , latitude , _25W_LongitudeDifference , _25W_LatitudeDifference );
2629 string r = subRC[0]. ToString( "000" );
2630 string c = subRC[1]. ToString( "000" );
2631 string n25W = n100W + "C" + r + c;
2632 if ( NewMapnumber_Check( n25W ) ) {
2633 return n25W;
2634 } else {
2635 return "";
2636 }
2637 } catch {
2638 throw;
2639 }
2640 }
2641
2642 ///
2646 ///
2647 ///
2648 ///
2649 public string CalculateNewMapnumberFromLongitudeLatitude10W( decimal longitude , decimal latitude ) {
2650 try {
2651 string n100W = CalculateNewMapnumberFromLongitudeLatitude100W( longitude , latitude );
2652 if ( string. IsNullOrEmpty( n100W ) ) {
2653 return "";
2654 }
2655 int[] subRC = CalculateNewMapnumberRowColumnIn100WFromLongitudeLatitude( longitude , latitude , _10W_LongitudeDifference , _10W_LatitudeDifference );
2656 string r = subRC[0]. ToString( "000" );
2657 string c = subRC[1]. ToString( "000" );
2658 string n10W = n100W + "D" + r + c;
2659 if ( NewMapnumber_Check( n10W ) ) {
2660 return n10W;
2661 } else {
2662 return "";
2663 }
2664 } catch {
2665 throw;
2666 }
2667 }
2668
2669 ///
2673 ///
2674 ///
2675 ///
2676 public string CalculateNewMapnumberFromLongitudeLatitude5W( decimal longitude , decimal latitude ) {
2677 try {
2678 string n100W = CalculateNewMapnumberFromLongitudeLatitude100W( longitude , latitude );
2679 if ( string. IsNullOrEmpty( n100W ) ) {
2680 return "";
2681 }
2682 int[] subRC = CalculateNewMapnumberRowColumnIn100WFromLongitudeLatitude( longitude , latitude , _5W_LongitudeDifference , _5W_LatitudeDifference );
2683 string r = subRC[0]. ToString( "000" );
2684 string c = subRC[1]. ToString( "000" );
2685 string n5W = n100W + "E" + r + c;
2686 if ( NewMapnumber_Check( n5W ) ) {
2687 return n5W;
2688 } else {
2689 return "";
2690 }
2691 } catch {
2692 throw;
2693 }
2694 }
2695
2696 ///
2700 ///
2701 ///
2702 ///
2703 public string CalculateNewMapnumberFromLongitudeLatitude2_5W( decimal longitude , decimal latitude ) {
2704 try {
2705 string n100W = CalculateNewMapnumberFromLongitudeLatitude100W( longitude , latitude );
2706 if ( string. IsNullOrEmpty( n100W ) ) {
2707 return "";
2708 }
2709 int[] subRC = CalculateNewMapnumberRowColumnIn100WFromLongitudeLatitude( longitude , latitude , _2_5W_LongitudeDifference , _2_5W_LatitudeDifference );
2710 string r = subRC[0]. ToString( "000" );
2711 string c = subRC[1]. ToString( "000" );
2712 string n2_5W = n100W + "F" + r + c;
2713 if ( NewMapnumber_Check( n2_5W ) ) {
2714 return n2_5W;
2715 } else {
2716 return "";
2717 }
2718 } catch {
2719 throw;
2720 }
2721 }
2722
2723 ///
2727 ///
2728 ///
2729 ///
2730 public string CalculateNewMapnumberFromLongitudeLatitude1W( decimal longitude , decimal latitude ) {
2731 try {
2732 string n100W = CalculateNewMapnumberFromLongitudeLatitude100W( longitude , latitude );
2733 if ( string. IsNullOrEmpty( n100W ) ) {
2734 return "";
2735 }
2736 int[] subRC = CalculateNewMapnumberRowColumnIn100WFromLongitudeLatitude( longitude , latitude , _1W_LongitudeDifference , _1W_LatitudeDifference );
2737 string r = subRC[0]. ToString( "000" );
2738 string c = subRC[1]. ToString( "000" );
2739 string n1W = n100W + "G" + r + c;
2740 if ( NewMapnumber_Check( n1W ) ) {
2741 return n1W;
2742 } else {
2743 return "";
2744 }
2745 } catch {
2746 throw;
2747 }
2748 }
2749
2750 ///
2754 ///
2755 ///
2756 ///
2757 public string CalculateNewMapnumberFromLongitudeLatitude0_5W( decimal longitude , decimal latitude ) {
2758 try {
2759 string n100W = CalculateNewMapnumberFromLongitudeLatitude100W( longitude , latitude );
2760 if ( string. IsNullOrEmpty( n100W ) ) {
2761 return "";
2762 }
2763 int[] subRC = CalculateNewMapnumberRowColumnIn100WFromLongitudeLatitude( longitude , latitude , _0_5W_LongitudeDifference , _0_5W_LatitudeDifference );
2764 string r = subRC[0]. ToString( "000" );
2765 string c = subRC[1]. ToString( "000" );
2766 string n0_5W = n100W + "H" + r + c;
2767 if ( NewMapnumber_Check( n0_5W ) ) {
2768 return n0_5W;
2769 } else {
2770 return "";
2771 }
2772 } catch {
2773 throw;
2774 }
2775 }
2776
2777 ///
2781 ///
2782 ///
2783 ///
2784 public string CalculateNewMapnumberFromLongitudeLatitude0_2W( decimal longitude , decimal latitude ) {
2785 try {
2786 string n100W = CalculateNewMapnumberFromLongitudeLatitude100W( longitude , latitude );
2787 if ( string. IsNullOrEmpty( n100W ) ) {
2788 return "";
2789 }
2790 int[] subRC = CalculateNewMapnumberRowColumnIn100WFromLongitudeLatitude( longitude , latitude , _0_2W_LongitudeDifference , _0_2W_LatitudeDifference );
2791 string r = subRC[0]. ToString( "000" );
2792 string c = subRC[1]. ToString( "000" );
2793 string n0_2W = n100W + "I" + r + c;
2794 if ( NewMapnumber_Check( n0_2W ) ) {
2795 return n0_2W;
2796 } else {
2797 return "";
2798 }
2799 } catch {
2800 throw;
2801 }
2802 }
2803
2804 ///
2808 ///
2809 ///
2810 ///
2811 public string CalculateNewMapnumberFromLongitudeLatitude0_1W( decimal longitude , decimal latitude ) {
2812 try {
2813 string n100W = CalculateNewMapnumberFromLongitudeLatitude100W( longitude , latitude );
2814 if ( string. IsNullOrEmpty( n100W ) ) {
2815 return "";
2816 }
2817 int[] subRC = CalculateNewMapnumberRowColumnIn100WFromLongitudeLatitude( longitude , latitude , _0_1W_LongitudeDifference , _0_1W_LatitudeDifference );
2818 string r = subRC[0]. ToString( "0000" );
2819 string c = subRC[1]. ToString( "0000" );
2820 string n0_1W = n100W + "J" + r + c;
2821 if ( NewMapnumber_Check( n0_1W ) ) {
2822 return n0_1W;
2823 } else {
2824 return "";
2825 }
2826 } catch {
2827 throw;
2828 }
2829 }
2830
2831 ///
2835 ///
2836 ///
2837 ///
2838 public string CalculateNewMapnumberFromLongitudeLatitude500( decimal longitude , decimal latitude ) {
2839 try {
2840 string n100W = CalculateNewMapnumberFromLongitudeLatitude100W( longitude , latitude );
2841 if ( string. IsNullOrEmpty( n100W ) ) {
2842 return "";
2843 }
2844 int[] subRC = CalculateNewMapnumberRowColumnIn100WFromLongitudeLatitude( longitude , latitude , _500_LongitudeDifference , _500_LatitudeDifference );
2845 string r = subRC[0]. ToString( "0000" );
2846 string c = subRC[1]. ToString( "0000" );
2847 string n500 = n100W + "K" + r + c;
2848 if ( NewMapnumber_Check( n500 ) ) {
2849 return n500;
2850 } else {
2851 return "";
2852 }
2853 } catch {
2854 throw;
2855 }
2856 }
2857
2858 private int[] CalculateNewMapnumberRowColumnIn100WFromLongitudeLatitude( decimal longitude , decimal latitude , decimal JC , decimal WC ) {
2859 int rNum = (int) ( Math. Round( ( _100W_LongitudeDifference / WC ) , MidpointRounding. AwayFromZero ) ) - (int) ( ( latitude % _100W_LongitudeDifference ) / WC );
2860 int cNum = (int) ( (int) ( ( longitude % _100W_LatitudeDifference ) / JC ) ) + 1;
2861
2862 return new int[] { rNum , cNum };
2863 }
2864
2865 #endregion
2866
2867 #region Coordinate to old mapnumber 坐标转旧图号
2868
2869 ///
2873 /// 经度
2874 /// 纬度
2875 /// 比例尺分母
2876 ///
2877 public string CalculateOldMapnumberFromLongitudeLatitude( decimal longitude , decimal latitude , int scaleDenominator ) {
2878 try {
2879 string n100W = CalculateNewMapnumberFromLongitudeLatitude100W( longitude , latitude );
2880 if ( string. IsNullOrEmpty( n100W ) ) {
2881 return "";
2882 }
2883 decimal[] jwc = GetLongitudeLatitudeDifference( scaleDenominator );
2884 decimal JC = jwc[0];
2885 decimal WC = jwc[1];
2886 int[] subRC = CalculateNewMapnumberRowColumnIn100WFromLongitudeLatitude( longitude , latitude , JC , WC );
2887 string scaleStr = GetNewMapnumberScaleString( scaleDenominator );
2888 #region 20万
2889 if ( scaleDenominator == 200000 ) {
2890 return CalculateOldMapnumberFromLongitudeLatitude20W( longitude , latitude );
2891 }
2892 #endregion
2893 #region
2894 else {
2895 string r = "";
2896 string c = "";
2897 if ( scaleStr == "J" || scaleStr == "K" ) {
2898 r = subRC[0]. ToString( "0000" );
2899 c = subRC[1]. ToString( "0000" );
2900 } else {
2901 r = subRC[0]. ToString( "000" );
2902 c = subRC[1]. ToString( "000" );
2903 }
2904 if ( string. IsNullOrEmpty( scaleStr ) ) {
2905 scaleStr = "";
2906 r = "";
2907 c = "";
2908 }
2909 string newMapnumber = n100W + scaleStr + r + c;
2910 if ( NewMapnumber_Check( newMapnumber ) ) {
2911 string oldMapnumber = NewMapnumberToOldMapnumber( newMapnumber );
2912 if ( OldMapnumber_Check( oldMapnumber ) ) {
2913 return oldMapnumber;
2914 } else {
2915 return "";
2916 }
2917 } else {
2918 return "";
2919 }
2920 }
2921 #endregion
2922 } catch {
2923 throw;
2924 }
2925 }
2926
2927 ///
2931 ///
2932 ///
2933 ///
2934 public string CalculateOldMapnumberFromLongitudeLatitude100W( decimal longitude , decimal latitude ) {
2935 try {
2936 int rNum = (int) ( latitude / _100W_LongitudeDifference ) + 1;
2937 int cNum = (int) ( longitude / _100W_LatitudeDifference ) + 31;
2938 string rStr = Change100W_RowDigitalToString( rNum );
2939 string o100W = rStr + "-" + cNum. ToString( "00" );
2940 if ( OldMapnumber_Check100W( o100W ) ) {
2941 return o100W;
2942 } else {
2943 return "";
2944 }
2945 } catch {
2946 throw;
2947 }
2948 }
2949
2950 ///
2954 ///
2955 ///
2956 ///
2957 public string CalculateOldMapnumberFromLongitudeLatitude20W( decimal longitude , decimal latitude ) {
2958 try {
2959 string o100W = CalculateOldMapnumberFromLongitudeLatitude100W( longitude , latitude );
2960 if ( string. IsNullOrEmpty( o100W ) ) {
2961 return "";
2962 }
2963 int[] subRC = CalculateNewMapnumberRowColumnIn100WFromLongitudeLatitude( longitude , latitude , _20W_LongitudeDifference , _20W_LatitudeDifference );
2964 int o20WNum = O20WNum( subRC[0] , subRC[1] );
2965 string o20W = o100W + "-(" + o20WNum. ToString( "00" ) + ")";
2966 if ( OldMapnumber_Check20W( o20W ) ) {
2967 return o20W;
2968 } else {
2969 return "";
2970 }
2971 } catch {
2972 throw;
2973 }
2974 }
2975
2976 private int O20WNum( int n20WR , int n20WC ) {
2977 return oldMapnumber_20W_RCNum * ( n20WR - 1 ) + n20WC;
2978 }
2979
2980 #endregion
2981
2982 #endregion
2983
2984 #endregion
2985
2986
2987 #region Other 其他
2988
2989 ///
2993 ///
2994 ///
2995 public string[] GetInfoFromNewMapnumber( string newMapnumber ) {
2996 try {
2997 string[] strs = new string[5];
2998 if ( !NewMapnumber_Check( newMapnumber ) ) {
2999 return null;
3000 }
3001 int length = newMapnumber. Length;
3002 string n100WR = "";
3003 string n100WC = "";
3004 string nScaleStr = "";
3005 string nR = "";
3006 string nC = "";
3007 if ( length == 3 ) {
3008 n100WR = newMapnumber. Substring( 0 , 1 );
3009 n100WC = newMapnumber. Substring( 1 , 2 );
3010 } else {
3011 n100WR = newMapnumber. Substring( 0 , 1 );
3012 n100WC = newMapnumber. Substring( 1 , 2 );
3013 nScaleStr = newMapnumber. Substring( 3 , 1 );
3014 if ( length == 10 ) {
3015 nR = newMapnumber. Substring( 4 , 3 );
3016 nC = newMapnumber. Substring( 7 , 3 );
3017 } else {
3018 nR = newMapnumber. Substring( 4 , 4 );
3019 nC = newMapnumber. Substring( 8 , 4 );
3020 }
3021 }
3022 if ( !string. IsNullOrEmpty( n100WR ) && !string. IsNullOrEmpty( n100WC ) ) {
3023 strs[0] = n100WR;
3024 strs[1] = n100WC;
3025 strs[2] = nScaleStr;
3026 strs[3] = nR;
3027 strs[4] = nC;
3028 return strs;
3029 }
3030 return null;
3031 } catch {
3032 throw;
3033 }
3034 }
3035
3036 ///
3040 ///
3041 ///
3042 public decimal[] GetLongitudeLatitudeDifference( int scaleDenominator ) {
3043 switch ( scaleDenominator ) {
3044 case 1000000:
3045 return new decimal[] { _100W_LatitudeDifference , _100W_LongitudeDifference };
3046 case 500000:
3047 return new decimal[] { _50W_LongitudeDifference , _50W_LatitudeDifference };
3048 case 250000:
3049 return new decimal[] { _25W_LongitudeDifference , _25W_LatitudeDifference };
3050 case 200000:
3051 return new decimal[] { _20W_LongitudeDifference , _20W_LatitudeDifference };
3052 case 100000:
3053 return new decimal[] { _10W_LongitudeDifference , _10W_LatitudeDifference };
3054 case 50000:
3055 return new decimal[] { _5W_LongitudeDifference , _5W_LatitudeDifference };
3056 case 25000:
3057 return new decimal[] { _2_5W_LongitudeDifference , _2_5W_LatitudeDifference };
3058 case 10000:
3059 return new decimal[] { _1W_LongitudeDifference , _1W_LatitudeDifference };
3060 case 5000:
3061 return new decimal[] { _0_5W_LongitudeDifference , _0_5W_LatitudeDifference };
3062 case 2000:
3063 return new decimal[] { _0_2W_LongitudeDifference , _0_2W_LatitudeDifference };
3064 case 1000:
3065 return new decimal[] { _0_1W_LongitudeDifference , _0_1W_LatitudeDifference };
3066 case 500:
3067 return new decimal[] { _500_LongitudeDifference , _500_LatitudeDifference };
3068 default:
3069 return null;
3070 }
3071 }
3072
3073 ///
3077 ///
3078 ///
3079 public string GetNewMapnumberScaleString( int scaleDenominator ) {
3080 switch ( scaleDenominator ) {
3081 case 1000000:
3082 return "";
3083 case 500000:
3084 return "B";
3085 case 250000:
3086 return "C";
3087 case 100000:
3088 return "D";
3089 case 50000:
3090 return "E";
3091 case 25000:
3092 return "F";
3093 case 10000:
3094 return "G";
3095 case 5000:
3096 return "H";
3097 case 2000:
3098 return "I";
3099 case 1000:
3100 return "J";
3101 case 500:
3102 return "K";
3103 default:
3104 return null;
3105 }
3106 }
3107
3108 ///
3112 ///
3113 ///
3114 //public ESRI.ArcGIS.Geometry.IGeometry GetPolygonGeometryFromNewMapnumber( string newMapnumber ) {
3115 // if ( NewMapnumber_Check( newMapnumber ) ) {
3116 // decimal[] coor = CalculateLongitudeLatitudeFromNewMapnumber( newMapnumber );
3117 // if ( coor != null ) {
3118 // ESRI.ArcGIS.Geometry.Ring ring = new ESRI.ArcGIS.Geometry.RingClass();
3119
3120 // ESRI.ArcGIS.Geometry.Point p1 = new ESRI.ArcGIS.Geometry.PointClass();
3121 // p1. PutCoords( decimal. ToDouble( coor[0] ) , decimal. ToDouble( coor[1] ) );
3122 // ring. AddPoint( p1 );
3123
3124 // ESRI. ArcGIS. Geometry. Point p2 = new ESRI. ArcGIS. Geometry. PointClass();
3125 // p2. PutCoords( decimal. ToDouble( coor[0] ) , decimal. ToDouble( coor[3] ) );
3126 // ring. AddPoint( p2 );
3127
3128 // ESRI. ArcGIS. Geometry. Point p3 = new ESRI. ArcGIS. Geometry. PointClass();
3129 // p3. PutCoords( decimal. ToDouble( coor[2] ) , decimal. ToDouble( coor[3] ) );
3130 // ring. AddPoint( p3 );
3131
3132 // ESRI. ArcGIS. Geometry. Point p4 = new ESRI. ArcGIS. Geometry. PointClass();
3133 // p4. PutCoords( decimal. ToDouble( coor[2] ) , decimal. ToDouble( coor[1] ) );
3134 // ring. AddPoint( p4 );
3135
3136 // ring. AddPoint( p1 );
3137
3138 // ESRI.ArcGIS.Geometry.IGeometryCollection pointPolygon = new ESRI.ArcGIS.Geometry.PolygonClass();
3139 // pointPolygon. AddGeometry( ring as ESRI.ArcGIS.Geometry.IGeometry );
3140 // ESRI.ArcGIS.Geometry.IPolygon pPolygon = pointPolygon as ESRI.ArcGIS.Geometry.IPolygon;
3141 // ESRI.ArcGIS.Geometry.IGeometry pGeometry = pPolygon as ESRI.ArcGIS.Geometry.IGeometry;
3142 // return pGeometry;
3143 // }
3144 // }
3145 // return null;
3146 //}
3147
3148
3149 #endregion
3150
3151 }
3152 }
Mapnumber
手机扫一扫
移动阅读更方便
你可能感兴趣的文章