目的
緯度経度をGEOREFコードに変換したい。
コード
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 |
private string lat_georef_Convert(double d_lat, double d_long) { //GEOREF用文字 string digraphLettersE = "ABCDEFGHJKLMNPQRSTUVWXYZ", digraphLettersN = "ABCDEFGHJKLMNPQ"; string s_georef = ""; int i_MQlat, i_MQlong,i_MRlat,i_MRlong,i_NRlat,i_NRlong; float f_NQlat, f_NQlong; if(d_long >= 180 || d_long < -180 || d_lat >= 90 || d_lat <= -90) { s_georef = "NULL"; return s_georef; } i_MQlong = (int)(d_long + 180) / 15; i_MQlat = (int)(d_lat + 90) / 15; i_MRlong = (int)(d_long + 180) % 15; i_MRlat = (int)(d_lat + 90) % 15; s_georef += digraphLettersE[i_MQlong]; s_georef += digraphLettersN[i_MQlat]; s_georef += digraphLettersN[i_MRlong]; s_georef += digraphLettersN[i_MRlat]; f_NQlong = (float)((d_long + 180) % 1.0f); f_NQlat = (float)((d_lat + 90) % 1.0f); i_NRlong = (int)(f_NQlong * 60); i_NRlat = (int)(f_NQlat * 60); s_georef += string.Format("{0:00}", i_NRlong); s_georef += string.Format("{0:00}", i_NRlat); return s_georef; } |
使用例
1 2 3 |
string georef = new string(); georef = lat_georef_Convert(35.0,139.0); Console.WriteLine(georef); //XJEF0000 |