Person Project
위도 경도를 TM좌표로 변환하기
클라인STR
2019. 1. 18. 00:17
이전 포스팅에서 위도 , 경도를 구한 값을 TM좌표로 변환해보기로한다.
TM좌표로 변환하기위해서는 통계청 SGIS API를 이용한다.
API를 사용하기위해서는 인증단계를 먼저 거쳐야한다. 응답정보 값인 accessToken 값이 필요하다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | const API_AUTH = "https://sgisapi.kostat.go.kr/OpenAPI3/auth/authentication.json"; const CONSUMER_KEY = ""; //Service ID const CONSUMER_SECRET = ""; //서비스 Secret function fetchAuth(latitude, longitude) { let url = `${API_AUTH}?consumer_key=${CONSUMER_KEY}&consumer_secret=${CONSUMER_SECRET}`; console.log(url); fetch(url) .then(response => response.json()) .then(data => { console.log("fetchAuth Result"); console.log(data); fetchCrdTms(data.result.accessToken, latitude, longitude); }) .catch(error => { console.log("error"); console.log(error); }); } | cs |
fetchAuth 함수를 하나 생성하여 인증 accessToken을 요청한다.
인증 요청결과 Json Data 형식
좌표변환 API는 위와 같은요청형식을 사용한다.
src는 현재 좌표체계 값이고 dst는 변경하고자하는 좌표 체계의 값이다.
위도 경도를 구한 좌표값은 WGS84(World Geodetic System) 형식이다. 좌표계코드표를 참고를 선택하면 아래와 같이 팝업이 호출된다.
공공데이터 포털 API중 환국환경공단에서 사용하는 좌표계는 중부원점이다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | const API_TRAD = "https://sgisapi.kostat.go.kr/OpenAPI3/transformation/transcoord.json"; const WGS84 = 4326; //WGS84 경/위도 const GRS80 = 5181; //GRS80 중부원점 function fetchCrdTms(accessToken, latitude, longitude) { //x축이 longtitude 경도 y축이 latitude 위도 let url = `${API_TRAD}?accessToken=${accessToken}&src=${WGS84}&dst=${GRS80}&posX=${longitude}&posY=${latitude}`; console.log(url); fetch(url) .then(response => response.json()) .then(data => { console.log("fetchCrdTms Result"); console.log(data); }) .catch(error => { console.log("error"); console.log(error); }); } | cs |