Skip to content

Commit c8d02f2

Browse files
committed
네이버 스태틱맵에서 브이월드로 변경함
1 parent ab899a9 commit c8d02f2

5 files changed

Lines changed: 35 additions & 71 deletions

File tree

consts.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@
7272
# ENUM_TABLEVIEW_HVFUNC.PASTE
7373
]
7474

75+
ENUM_STATICMAP_BASEMAP = DotMap(
76+
PHOTO_HYBRID="PHOTO_HYBRID",
77+
GRAPHIC="GRAPHIC",
78+
GRAPHIC_WHITE="GRAPHIC_WHITE",
79+
GRAPHIC_NIGHT="GRAPHIC_NIGHT",
80+
PHOTO="PHOTO",
81+
)
82+
7583
ERRORCODE_LOAD = DotMap(
7684
SUCCESS=0,
7785
CANCEL=1,
@@ -84,8 +92,6 @@
8492
SAVE_KEY_MAP = DotMap(
8593
PARQUET_FILE_ORIGINAL_SIZE="PFOS_",
8694
OPTION_APIKEY="OPTION_APIKEY",
87-
OPTION_CLIENTID="OPTION_CLIENTID",
88-
OPTION_CLIENTSECRET="OPTION_CLIENTSECRET",
8995
OPTION_FONTSIZE="OPTION_FONTSIZE", # 9
9096
OPTION_TABLEPAGESIZE="OPTION_TABLEPAGESIZE", # 20
9197
OPTION_LOWSPECMODE="OPTION_LOWSPECMODE"

gui.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -263,21 +263,18 @@ def open_img(self, info_dict={}):
263263
addr = info_dict["addr"]
264264

265265
# 2. id / secret 체크
266-
client_id = self.settings.value(SAVE_KEY_MAP.OPTION_CLIENTID, "")
267-
client_secret = self.settings.value(
268-
SAVE_KEY_MAP.OPTION_CLIENTSECRET, "")
269-
if not client_id or not client_secret:
266+
api_key = self.settings.value(SAVE_KEY_MAP.OPTION_APIKEY, "")
267+
if not api_key:
270268
QMessageBox.information(
271-
self, '경고', "Naver Cloud Client 값을 설정해주세요.")
269+
self, '경고', "옵션에서 브이월드 API Key를 설정해주세요.")
272270
return
273271

274272
# 3. 이미지 얻어오기, content로 뱉어줌.
275-
is_success, content = get_map_img(
276-
client_id, client_secret,
277-
self.mapinfo_table.epsg if not info_dict else info_dict['epsg'])
273+
epsg = self.mapinfo_table.epsg if not info_dict else info_dict['epsg']
274+
is_success, content = get_map_img(api_key, epsg)
278275
if not is_success:
279276
QMessageBox.information(
280-
self, '경고', "Naver Cloud에 접속하는데 실패했습니다.\n\n" + str(content))
277+
self, '경고', "브이월드에 접속하는데 실패했습니다.\n\n" + str(content))
281278
return
282279

283280
# 4. image_data -> pixmap 전환

gui_dialog.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -587,22 +587,3 @@ def closeEvent(self, e):
587587
lambda: pd.read_csv("original.csv", encoding="euc-kr", sep="|", dtype=object))
588588
if loading_dialog.exec_() == QDialog.Accepted:
589589
print(loading_dialog.result)
590-
591-
if DEBUG_MODE == ImageViewerDialog:
592-
from PyQt5.QtWidgets import QMainWindow
593-
from PyQt5.QtGui import QPixmap
594-
from network import get_mapinfo_from_pnu, get_map_img
595-
apikey = "A65F7069-061D-378F-B2D1-5E635A17BA43"
596-
pnu = "4377034032102800000"
597-
598-
client_id = "287jnrkvrn"
599-
client_secret = "KVny3P6P59caY0Cs2AEp8HW6EYxIB8nVm9UEhsbA"
600-
601-
l, b = get_mapinfo_from_pnu(apikey, pnu)
602-
iss, content = get_map_img(client_id, client_secret, b)
603-
pixmap = QPixmap()
604-
pixmap.loadFromData(content)
605-
qw = QMainWindow()
606-
ImageViewerDialog(qw, title=l[0], pixmap=pixmap).show()
607-
608-
sys.exit(app.exec_())

gui_tableview.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,12 +382,12 @@ def set_data(self, data, mode):
382382
0, ENUM_TABLEVIEW_SORTMODE.ORIGINAL)
383383
self.now_sort = []
384384

385-
# EDITNEEDED : EDIT 모드를 위해 저장함
385+
# NEEDTOEDIT : EDIT 모드를 위해 저장함
386386
before_page = self.get_page()
387387

388388
self.init_page()
389389

390-
# EDITNEEDED : page init 하면 1페이지로 돌아가기 때문에, 다시 기존에 있었던 page로 이동한다.
390+
# NEEDTOEDIT : page init 하면 1페이지로 돌아가기 때문에, 다시 기존에 있었던 page로 이동한다.
391391
if mode == ENUM_TABLEVIEW_INITMODE.EDIT:
392392
max_page = self.table_view.get_maxpage()
393393
page = before_page if before_page <= max_page else max_page

network.py

Lines changed: 19 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
URL_ADDR = "https://api.vworld.kr/req/address"
55
URL_PNU = "https://api.vworld.kr/req/data?service=data&request=GetFeature&attrFilter=pnu:=:{pnu}&data=LP_PA_CBND_BUBUN&key={apikey}"
6-
URL_MAP = "https://naveropenapi.apigw.ntruss.com/map-static/v2/raster"
6+
URL_MAP = "https://api.vworld.kr/req/image"
77

88
MAPLINK_SEED1 = "https://map.kakao.com/link/search/{addr}"
99
MAPLINK_SEED2 = "https://map.kakao.com/link/roadview/{y},{x}"
@@ -71,42 +71,25 @@ def get_mapinfo_from_pnu(apikey, pnu):
7171
return [addr, maplink1, maplink2, maplink3], [str(x), str(y)]
7272

7373

74-
###
75-
# 로그인 ::: https://www.ncloud.com/product/applicationService/maps
76-
# API ::: https://api.ncloud-docs.com/docs/ai-naver-mapsstaticmap-raster
77-
###
78-
def get_map_img(c_id, c_sec, epsg):
79-
lon, lat = epsg[0], epsg[1]
74+
def get_map_img(api_key, epsg, zoom=18, width=1024, height=1024, basemap="PHOTO_HYBRID"):
75+
x = epsg[0]
76+
y = epsg[1]
8077

81-
# 좌표 (경도, 위도)
82-
headers = {
83-
"X-NCP-APIGW-API-KEY-ID": c_id,
84-
"X-NCP-APIGW-API-KEY": c_sec,
78+
zoom = min(max(zoom, 6), 18)
79+
80+
params = {
81+
"service": "image",
82+
"request": "getmap",
83+
"key": api_key,
84+
"format": "png",
85+
"basemap": basemap,
86+
"center": f"{x},{y}",
87+
"zoom": zoom,
88+
"size": f"{width},{height}",
89+
"marker": f"point:{x} {y}|image:img09"
8590
}
86-
# 중심 좌표
87-
_center = f"{lon},{lat}"
88-
# 줌 레벨 - 0 ~ 20
89-
_level = 16
90-
# 가로 세로 크기 (픽셀)
91-
_w, _h = 700, 500
92-
# 지도 유형 - basic, traffic, satellite, satellite_base, terrain
93-
_maptype = "satellite"
94-
# 반환 이미지 형식 - jpg, jpeg, png8, png
95-
_format = "png"
96-
# 고해상도 디스펠레이 지원을 위한 옵션 - 1, 2
97-
_scale = 1
98-
# 마커
99-
_markers = f"""type:d|size:small|pos:{lon} {lat}|color:yellow"""
100-
# 라벨 언어 설정 - ko, en, ja, zh
101-
_lang = "ko"
102-
# 대중교통 정보 노출 - Boolean
103-
_public_transit = True
104-
# 서비스에서 사용할 데이터 버전 파라미터 전달 CDN 캐시 무효화
105-
_dataversion = ""
106-
107-
# URL
108-
url = f"{URL_MAP}?center={_center}&level={_level}&w={_w}&h={_h}&maptype={_maptype}&format={_format}&scale={_scale}&markers={_markers}&lang={_lang}&public_transit={_public_transit}&dataversion={_dataversion}"
109-
res = requests.get(url, headers=headers)
91+
92+
res = requests.get(URL_MAP, params=params)
11093

11194
return res.status_code == 200, res.content
11295

@@ -115,14 +98,11 @@ def get_map_img(c_id, c_sec, epsg):
11598
apikey = ""
11699
pnu = "4377034032102800000"
117100

118-
client_id = ""
119-
client_secret = ""
120-
121101
l, b = get_mapinfo_from_pnu(apikey, pnu)
122102
if not b:
123103
print("error")
124104
else:
125-
iss, pm = get_map_img(client_id, client_secret, b)
105+
iss, pm = get_static_map(apikey, b)
126106

127107
print(l, b)
128108
print(iss)

0 commit comments

Comments
 (0)