public static string OldMapnumberFromLongitudeLatitude(decimal longitude, decimal latitude, int scaleDenominator) { string n100W = NewMapnumber100WFromLongitudeLatitude(longitude, latitude); if (string.IsNullOrEmpty(n100W)) { return(null); } LongitudeLatitudeDifferent.LongitudeLatitudeDifferenceByScaleDenominator(scaleDenominator, out bool success, out decimal JC, out decimal WC); NewMapnumberRowColumnNumIn100WFromLongitudeLatitude(longitude, latitude, JC, WC, out int row, out int column); string scaleStr = NewMapnumber.ScaleString(scaleDenominator); if (scaleDenominator == 200000) { return(OldMapnumber20WFromLongitudeLatitude(longitude, latitude)); } else { string r = ""; string c = ""; if (scaleStr == "J" || scaleStr == "K") { r = row.ToString("0000"); c = column.ToString("0000"); } else { r = row.ToString("000"); c = column.ToString("000"); } if (string.IsNullOrEmpty(scaleStr)) { scaleStr = ""; r = ""; c = ""; } string newMapnumber = n100W + scaleStr + r + c; if (NewMapnumberCheck.Check(newMapnumber)) { string oldMapnumber = NewMapnumberToMapnumber.ToOldMapnumber(newMapnumber); if (OldMapnumberCheck.Check(oldMapnumber)) { return(oldMapnumber); } } return(null); } }
public static string NewMapnumberFromLongitudeLatitude(decimal longitude, decimal latitude, int scaleDenominator) { var newMapnumber_100W = NewMapnumber100WFromLongitudeLatitude(longitude, latitude); if (string.IsNullOrEmpty(newMapnumber_100W)) { return(null); } LongitudeLatitudeDifferent.LongitudeLatitudeDifferenceByScaleDenominator(scaleDenominator, out bool success, out decimal longitudeDifference, out decimal latitudeDifference); if (!success) { throw new Exception(); } NewMapnumberRowColumnNumIn100WFromLongitudeLatitude(longitude, latitude, longitudeDifference, latitudeDifference, out int row, out int column); string scaleStr = NewMapnumber.ScaleString(scaleDenominator); string r = ""; string c = ""; if (scaleStr == "J" || scaleStr == "K") { r = row.ToString("0000"); c = column.ToString("0000"); } else { r = row.ToString("000"); c = column.ToString("000"); } if (string.IsNullOrEmpty(scaleStr)) { scaleStr = ""; r = ""; c = ""; } string newMapnumber = newMapnumber_100W + scaleStr + r + c; if (!NewMapnumberCheck.Check(newMapnumber)) { return(null); } return(newMapnumber); }
public static string ToOldMapnumber(string mapnumber) { if (!NewMapnumberCheck.Check(mapnumber)) { return(""); } NewMapnumber.GetInfo(mapnumber, out bool success, out string m100WRow, out string m100WColumn, out string scale, out string row, out string column); if (!success) { return(""); } if (scale.Length != 1) { throw new Exception(); } var scaleChr = scale[0]; var scaleNumber = NewMapnumber.NewMapnumberGetScaleDenominatorNumberByScaleStr(scaleChr); switch (scaleNumber) { case 1000000: { return(ToOldMapnumber100W(m100WRow, m100WColumn)); } case 500000: { var o100W = ToOldMapnumber100W(m100WRow, m100WColumn); var o50W = ToOld50WNum(row, column); var o50WStr = OldMapnumber.Change1234ToABCD(o50W); if (string.IsNullOrEmpty(o50WStr)) { return(""); } return(o100W + "-" + o50WStr); } case 250000: { var o100W = ToOldMapnumber100W(m100WRow, m100WColumn); var o25W = ToOld25WNum(row, column); if (o25W <= 0 || o25W > 16) { return(""); } return(o100W + "-[" + o25W.ToString("00") + "]"); } case 100000: { var o100W = ToOldMapnumber100W(m100WRow, m100WColumn); var o10W = ToOld10WNum(row, column); if (o10W <= 0 || o10W > 144) { return(""); } return(o100W + "-" + o10W.ToString("000")); } case 50000: { var o100W = ToOldMapnumber100W(m100WRow, m100WColumn); var o5W = ToOld5WNum(row, column); var o5WStr = OldMapnumber.Change1234ToABCD(o5W); if (string.IsNullOrEmpty(o5WStr)) { return(""); } var n10WR = New5WRCToNew10WRC(int.Parse(row)); var n10WC = New5WRCToNew10WRC(int.Parse(column)); var o10W = ToOld10WNum(n10WR.ToString(), n10WC.ToString()); if (o10W <= 0 || o10W > 144) { return(""); } return(o100W + "-" + o10W.ToString("000") + "-" + o5WStr); } case 25000: { var o100W = ToOldMapnumber100W(m100WRow, m100WColumn); var o2_5W = ToOld2_5WNum(row, column); if (o2_5W <= 0 || o2_5W > 4) { return(""); } var n5WR = New2_5WRCToNew5WRC(int.Parse(row)); var n5WC = New2_5WRCToNew5WRC(int.Parse(column)); var o5W = ToOld5WNum(n5WR.ToString(), n5WC.ToString()); var o5WStr = OldMapnumber.Change1234ToABCD(o5W); if (string.IsNullOrEmpty(o5WStr)) { return(""); } var n10WR = New5WRCToNew10WRC(n5WR); var n10WC = New5WRCToNew10WRC(n5WC); var o10W = ToOld10WNum(n10WR.ToString(), n10WC.ToString()); if (o10W <= 0 || o10W > 144) { return(""); } return(o100W + "-" + o10W.ToString("000") + "-" + o5WStr + "-" + o2_5W.ToString()); } case 10000: { var o100W = ToOldMapnumber100W(m100WRow, m100WColumn); var o1W = ToOld1WNum(row, column); if (o1W <= 0 || o1W > 64) { return(""); } var n10WR = New1WRCToNew10WRC(int.Parse(row)); var n10WC = New1WRCToNew10WRC(int.Parse(column)); var o10W = ToOld10WNum(n10WR.ToString(), n10WC.ToString()); if (o10W <= 0 || o10W > 144) { return(""); } return(o100W + "-" + o10W.ToString("000") + "-(" + o1W.ToString("00") + ")"); } case 5000: { var o100W = ToOldMapnumber100W(m100WRow, m100WColumn); var o0_5W = ToOld5KNum(row, column); var o0_5WStr = OldMapnumber.Change1234Toabcd(o0_5W); if (string.IsNullOrEmpty(o0_5WStr)) { return(""); } var n1WR = New5KRCToNew1WRC(int.Parse(row)); var n1WC = New5KRCToNew1WRC(int.Parse(column)); var o1W = ToOld1WNum(n1WR.ToString(), n1WC.ToString()); if (o1W <= 0 || o1W > 64) { return(""); } var n10WR = New1WRCToNew10WRC(n1WR); var n10WC = New1WRCToNew10WRC(n1WC); var o10W = ToOld10WNum(n10WR.ToString(), n10WC.ToString()); if (o10W <= 0 || o10W > 144) { return(""); } return(o100W + "-" + o10W.ToString("000") + "-(" + o1W.ToString("00") + ")-" + o0_5WStr); } default: { return(null); } } }
public static void NewMapnumberCornerCoordinates(string newMapnumber, out bool success, out decimal west, out decimal north, out decimal east, out decimal south) { success = false; west = decimal.Zero; north = decimal.Zero; east = decimal.Zero; south = decimal.Zero; NewMapnumber.GetInfo(newMapnumber, out bool infoSuccess, out string m100WRow, out string m100WColumn, out string scale, out string row, out string column); if (!infoSuccess) { success = false; return; } if (scale.Length != 1) { throw new Exception(); } var scaleNumber = NewMapnumber.NewMapnumberGetScaleDenominatorNumberByScaleStr(scale[0]); if (scaleNumber <= 0) { success = false; return; } var longitudeDiff = decimal.Zero; var latitudeDiff = decimal.Zero; var r = decimal.Zero; var c = decimal.Zero; switch (scaleNumber) { case 1000000: { west = NewMapnumberWest(m100WColumn); south = NewMapnumberSouth(m100WRow); north = south + LongitudeLatitudeDifferent.MAPNUMBER_100W_LATITUDE_DIFFERENT; east = west + LongitudeLatitudeDifferent.MAPNUMBER_100W_LONGITUDE_DIFFERENT; success = true; return; } case 500000: { if (!decimal.TryParse(column, out c) || !decimal.TryParse(row, out r)) { success = false; return; } longitudeDiff = LongitudeLatitudeDifferent.MAPNUMBER_50W_LONGITUDE_DIFFERENT; latitudeDiff = LongitudeLatitudeDifferent.MAPNUMBER_50W_LATITUDE_DIFFERENT; break; } case 250000: { if (!decimal.TryParse(column, out c) || !decimal.TryParse(row, out r)) { success = false; return; } longitudeDiff = LongitudeLatitudeDifferent.MAPNUMBER_25W_LONGITUDE_DIFFERENT; latitudeDiff = LongitudeLatitudeDifferent.MAPNUMBER_25W_LATITUDE_DIFFERENT; break; } case 100000: { if (!decimal.TryParse(column, out c) || !decimal.TryParse(row, out r)) { success = false; return; } longitudeDiff = LongitudeLatitudeDifferent.MAPNUMBER_10W_LONGITUDE_DIFFERENT; latitudeDiff = LongitudeLatitudeDifferent.MAPNUMBER_10W_LATITUDE_DIFFERENT; break; } case 50000: { if (!decimal.TryParse(column, out c) || !decimal.TryParse(row, out r)) { success = false; return; } longitudeDiff = LongitudeLatitudeDifferent.MAPNUMBER_5W_LONGITUDE_DIFFERENT; latitudeDiff = LongitudeLatitudeDifferent.MAPNUMBER_5W_LATITUDE_DIFFERENT; break; } case 25000: { if (!decimal.TryParse(column, out c) || !decimal.TryParse(row, out r)) { success = false; return; } longitudeDiff = LongitudeLatitudeDifferent.MAPNUMBER_2_5W_LONGITUDE_DIFFERENT; latitudeDiff = LongitudeLatitudeDifferent.MAPNUMBER_2_5W_LATITUDE_DIFFERENT; break; } case 10000: { if (!decimal.TryParse(column, out c) || !decimal.TryParse(row, out r)) { success = false; return; } longitudeDiff = LongitudeLatitudeDifferent.MAPNUMBER_1W_LONGITUDE_DIFFERENT; latitudeDiff = LongitudeLatitudeDifferent.MAPNUMBER_1W_LATITUDE_DIFFERENT; break; } case 5000: { if (!decimal.TryParse(column, out c) || !decimal.TryParse(row, out r)) { success = false; return; } longitudeDiff = LongitudeLatitudeDifferent.MAPNUMBER_5K_LONGITUDE_DIFFERENT; latitudeDiff = LongitudeLatitudeDifferent.MAPNUMBER_5K_LATITUDE_DIFFERENT; break; } case 2000: { if (!decimal.TryParse(column, out c) || !decimal.TryParse(row, out r)) { success = false; return; } longitudeDiff = LongitudeLatitudeDifferent.MAPNUMBER_2K_LONGITUDE_DIFFERENT; latitudeDiff = LongitudeLatitudeDifferent.MAPNUMBER_2K_LATITUDE_DIFFERENT; break; } case 1000: { if (!decimal.TryParse(column, out c) || !decimal.TryParse(row, out r)) { success = false; return; } longitudeDiff = LongitudeLatitudeDifferent.MAPNUMBER_1K_LONGITUDE_DIFFERENT; latitudeDiff = LongitudeLatitudeDifferent.MAPNUMBER_1K_LATITUDE_DIFFERENT; break; } case 500: { if (!decimal.TryParse(column, out c) || !decimal.TryParse(row, out r)) { success = false; return; } longitudeDiff = LongitudeLatitudeDifferent.MAPNUMBER_500_LONGITUDE_DIFFERENT; latitudeDiff = LongitudeLatitudeDifferent.MAPNUMBER_500_LATITUDE_DIFFERENT; break; } default: { success = false; return; } } west = NewMapnumberWest(m100WColumn, c, longitudeDiff); south = NewMapnumberSouth(m100WRow, r, latitudeDiff); north = south + latitudeDiff; east = west + longitudeDiff; success = true; }