Last active
November 19, 2025 05:25
-
-
Save fronteer-kr/14d7f779d52a21ac2f16 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 소스출처 : http://www.kma.go.kr/weather/forecast/digital_forecast.jsp 내부에 있음 | |
| // 기상청에서 이걸 왜 공식적으로 공개하지 않을까? | |
| // | |
| // (사용 예) | |
| // var rs = dfs_xy_conv("toLL","60","127"); | |
| // console.log(rs.lat, rs.lng); | |
| // | |
| <script language="javascript"> | |
| //<!-- | |
| // | |
| // LCC DFS 좌표변환을 위한 기초 자료 | |
| // | |
| var RE = 6371.00877; // 지구 반경(km) | |
| var GRID = 5.0; // 격자 간격(km) | |
| var SLAT1 = 30.0; // 투영 위도1(degree) | |
| var SLAT2 = 60.0; // 투영 위도2(degree) | |
| var OLON = 126.0; // 기준점 경도(degree) | |
| var OLAT = 38.0; // 기준점 위도(degree) | |
| var XO = 43; // 기준점 X좌표(GRID) | |
| var YO = 136; // 기1준점 Y좌표(GRID) | |
| // | |
| // LCC DFS 좌표변환 ( code : "toXY"(위경도->좌표, v1:위도, v2:경도), "toLL"(좌표->위경도,v1:x, v2:y) ) | |
| // | |
| function dfs_xy_conv(code, v1, v2) { | |
| var DEGRAD = Math.PI / 180.0; | |
| var RADDEG = 180.0 / Math.PI; | |
| var re = RE / GRID; | |
| var slat1 = SLAT1 * DEGRAD; | |
| var slat2 = SLAT2 * DEGRAD; | |
| var olon = OLON * DEGRAD; | |
| var olat = OLAT * DEGRAD; | |
| var sn = Math.tan(Math.PI * 0.25 + slat2 * 0.5) / Math.tan(Math.PI * 0.25 + slat1 * 0.5); | |
| sn = Math.log(Math.cos(slat1) / Math.cos(slat2)) / Math.log(sn); | |
| var sf = Math.tan(Math.PI * 0.25 + slat1 * 0.5); | |
| sf = Math.pow(sf, sn) * Math.cos(slat1) / sn; | |
| var ro = Math.tan(Math.PI * 0.25 + olat * 0.5); | |
| ro = re * sf / Math.pow(ro, sn); | |
| var rs = {}; | |
| if (code == "toXY") { | |
| rs['lat'] = v1; | |
| rs['lng'] = v2; | |
| var ra = Math.tan(Math.PI * 0.25 + (v1) * DEGRAD * 0.5); | |
| ra = re * sf / Math.pow(ra, sn); | |
| var theta = v2 * DEGRAD - olon; | |
| if (theta > Math.PI) theta -= 2.0 * Math.PI; | |
| if (theta < -Math.PI) theta += 2.0 * Math.PI; | |
| theta *= sn; | |
| rs['x'] = Math.floor(ra * Math.sin(theta) + XO + 0.5); | |
| rs['y'] = Math.floor(ro - ra * Math.cos(theta) + YO + 0.5); | |
| } | |
| else { | |
| rs['x'] = v1; | |
| rs['y'] = v2; | |
| var xn = v1 - XO; | |
| var yn = ro - v2 + YO; | |
| ra = Math.sqrt(xn * xn + yn * yn); | |
| if (sn < 0.0) - ra; | |
| var alat = Math.pow((re * sf / ra), (1.0 / sn)); | |
| alat = 2.0 * Math.atan(alat) - Math.PI * 0.5; | |
| if (Math.abs(xn) <= 0.0) { | |
| theta = 0.0; | |
| } | |
| else { | |
| if (Math.abs(yn) <= 0.0) { | |
| theta = Math.PI * 0.5; | |
| if (xn < 0.0) - theta; | |
| } | |
| else theta = Math.atan2(xn, yn); | |
| } | |
| var alon = theta / sn + olon; | |
| rs['lat'] = alat * RADDEG; | |
| rs['lng'] = alon * RADDEG; | |
| } | |
| return rs; | |
| } | |
| //--> | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
기상청에서 제공한 위 경도 -> 자체 격자 변환 소스코드입니다. 혹시나 해서 같이 올립니다.
/********************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <time.h>
#include <math.h>
#define NX 149 /* X축 격자점 수 /
#define NY 253 / Y축 격자점 수 */
struct lamc_parameter {
float Re; /* 사용할 지구반경 [ km ] /
float grid; / 격자간격 [ km ] /
float slat1; / 표준위도 [degree] /
float slat2; / 표준위도 [degree] /
float olon; / 기준점의 경도 [degree] /
float olat; / 기준점의 위도 [degree] /
float xo; / 기준점의 X좌표 [격자거리] /
float yo; / 기준점의 Y좌표 [격자거리] /
int first; / 시작여부 (0 = 시작) */
};
/******************************************************************************
*
******************************************************************************/
int main (int argc, char *argv[]) {
float lon, lat, x, y;
struct lamc_parameter map;
}
/============================================================================
좌표변환
============================================================================/
int map_conv
(
float *lon, // 경도(degree)
float *lat, // 위도(degree)
float *x, // X격자 (grid)
float *y, // Y격자 (grid)
int code, // 0 (격자->위경도), 1 (위경도->격자)
struct lamc_parameter map // 지도정보
) {
float lon1, lat1, x1, y1;
//
// 위경도 -> (X,Y)
//
if (code == 0) {
lon1 = *lon;
lat1 = *lat;
lamcproj(&lon1, &lat1, &x1, &y1, 0, &map);
*x = (int)(x1 + 1.5);
*y = (int)(y1 + 1.5);
}
//
// (X,Y) -> 위경도
//
if (code == 1) {
x1 = *x - 1;
y1 = *y - 1;
lamcproj(&lon1, &lat1, &x1, &y1, 1, &map);
*lon = lon1;
*lat = lat1;
}
return 0;
}
/***************************************************************************
*
***************************************************************************/
int lamcproj(lon, lat, x, y, code, map)
float *lon, lat; / Longitude, Latitude [degree] */
float *x, y; / Coordinate in Map [grid] /
int code; / (0) lon,lat ->x,y (1) x,y ->lon,lat */
struct lamc_parameter *map;
{
static double PI, DEGRAD, RADDEG;
static double re, olon, olat, sn, sf, ro;
double slat1, slat2, alon, alat, xn, yn, ra, theta;
}