환경 설정
$ pip install requests
$ pip install openpyxl
추가로 아래 파이썬 코드가 작성된 폴더에 엑셀 파일을 위치시킨다.
첫번째 열에 주소 정보를 입력
API
공간정보 오픈플랫폼 오픈API
Geocoder API 2.0 레퍼런스 Geocoder API 2.0 레퍼런스입니다. API 버전 : Geocoder API 2.0 레퍼런스 Geocoder API 1.0 레퍼런스 소개 주소를 좌표로 변환하는 서비스를 제공합니다. 요청URL을 전송하면 지오코딩 서
www.vworld.kr
사이트 회원가입 후 API를 발급받고, Geocoder API 1.0 레퍼런스를 활용
geo.py
#-*-coding: utf-8 -*-
import requests
import openpyxl
import json
## 엑셀 파일 오픈
filename = "address.xlsx"
exelFile = openpyxl.load_workbook(filename)
## 시트 설정
sheet = exelFile.worksheets[0]
## 데이터 가져오기
rowCount = 1
for row in sheet.rows:
try:
## geocoder 호출
r = requests.get("http://apis.vworld.kr/new2coord.do?q="+row[0].value+"&output=json&epsg=epsg:4326&apiKey=INPUT_YOUR_API_KEY")
## cell 설정 [ (10)J1 ~ J* : 위도 / (11)K1 ~ K* : 경도]
lat_cell = sheet.cell(row = rowCount, column = 2)
lng_cell = sheet.cell(row = rowCount, column = 3)
## 데이터 추가
lat_cell.value = r.json()["EPSG_4326_Y"]
lng_cell.value = r.json()["EPSG_4326_X"]
except KeyError as ke:
lat_cell.value = 0
lng_cell.value = 0
except TypeError as te:
lat_cell.value = 0
lng_cell.value = 0
rowCount = rowCount + 1
## 데이터 저장
exelFile.save("address.xlsx")
'프로그래밍(공통)' 카테고리의 다른 글
Software의 방어적인 프로그래밍 (0) | 2023.09.10 |
---|---|
[도메인] OAuth의 개념과 OAuth 2.0? (0) | 2021.05.30 |
[Linux] Vim 에디터를 Vundle로 커스터마이징 (0) | 2021.04.24 |
서버 구성 관련 명령어(Ubuntu 18.04, Node.js, MongoDB) (0) | 2020.09.22 |
vscode에서 git 사용 (0) | 2020.04.22 |