Refactor: typing cleanup, 경로 하드코딩 제거, GPS 데이터 Lon/Lat 분리, 불필요 모듈 삭제
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import os
|
||||
import sys
|
||||
#import sys
|
||||
|
||||
import UtilPack as util
|
||||
import PoleXLS as myxl
|
||||
@@ -7,38 +7,8 @@ import ExtEXIFData as exEXIF
|
||||
import VWorldAPIs as vwapi
|
||||
import JusoMngr
|
||||
|
||||
mCurPath = "" # 스크립트가 실행되는 경로
|
||||
mXlsPath = "" # 엑셀 파일이 있는 경로, 틀리면 안됨.
|
||||
|
||||
# "/Volumes/ExSSD/Working/Images" # 이미지가 들어있는 폴더, 이 아래에 A,B,Pole 등이 있어야 한다.
|
||||
mImgPath = ""
|
||||
|
||||
|
||||
def WorkingFolderCheck(path, xlsPath):
|
||||
if False == os.path.exists(path):
|
||||
print(f"Error: Working Folder is not exist. {path}")
|
||||
return False
|
||||
|
||||
pathList = ["A", "B", "Pole"]
|
||||
|
||||
for folder in pathList:
|
||||
fullPath = os.path.join(path, folder)
|
||||
if False == os.path.isdir(fullPath):
|
||||
print(f"Error: {folder} Folder is not exist. {fullPath}")
|
||||
return False
|
||||
|
||||
mImgPath = path
|
||||
mCurPath = os.getcwd()
|
||||
|
||||
if False == os.path.exists(xlsPath):
|
||||
mXlsPath = os.getcwd()
|
||||
else:
|
||||
mXlsPath = xlsPath
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def GetPoleInfos(xls, nRow):
|
||||
def GetPoleInfos(xls, nRow:int):
|
||||
if None == xls or False == isinstance(xls, myxl.PoleXLS):
|
||||
return []
|
||||
|
||||
@@ -51,7 +21,8 @@ def CollectImageData(xls, sheetTrg, listImg, pathImgDir):
|
||||
if None == xls or False == isinstance(xls, myxl.PoleXLS) or True == util.IsEmptyStr(sheetTrg):
|
||||
return -1
|
||||
|
||||
pathcsv = os.path.join(mCurPath, "JusoDB.csv")
|
||||
pathCurrent = os.getcwd()
|
||||
pathcsv = os.path.join(pathCurrent, "JusoDB.csv")
|
||||
jusomgr = JusoMngr.JusoDB(pathcsv)
|
||||
|
||||
nIdx = 1
|
||||
@@ -86,18 +57,20 @@ def CollectImageData(xls, sheetTrg, listImg, pathImgDir):
|
||||
xls.SetCellValueStr(sheetTrg, 3, nIdx, all_date)
|
||||
xls.SetCellValueStr(sheetTrg, 4, nIdx, level)
|
||||
xls.SetCellValueStr(sheetTrg, 5, nIdx, pathRel)
|
||||
xls.SetCellValueStr(sheetTrg, 6, nIdx, juso[3])
|
||||
xls.SetCellValueStr(sheetTrg, 7, nIdx, juso[2])
|
||||
xls.SetCellValueStr(sheetTrg, 8, nIdx, f"{lat},{lon}")
|
||||
xls.SetCellValueStr(sheetTrg, 9, nIdx, juso[1])
|
||||
xls.SetCellValueStr(sheetTrg, 10, nIdx, juso[0])
|
||||
xls.SetCellValueStr(sheetTrg, 6, nIdx, juso[1])
|
||||
xls.SetCellValueStr(sheetTrg, 7, nIdx, juso[0])
|
||||
xls.SetCellValueStr(sheetTrg, 8, nIdx, juso[3])
|
||||
xls.SetCellValueStr(sheetTrg, 9, nIdx, juso[2])
|
||||
xls.SetCellValueStr(sheetTrg, 10, nIdx, f"{lon}")
|
||||
xls.SetCellValueStr(sheetTrg, 11, nIdx, f"{lat}")
|
||||
|
||||
# VWorld 좌표로 변환하여 저장
|
||||
lat_Vworld, lon_Vworld = 0.0, 0.0
|
||||
if lat != 0.0 and lon != 0.0 :
|
||||
lat_Vworld, lon_Vworld = vwapi.Transform4326to3857(lat, lon)
|
||||
|
||||
xls.SetCellValueStr(sheetTrg, 11, nIdx, f"{lat_Vworld},{lon_Vworld}")
|
||||
xls.SetCellValueStr(sheetTrg, 12, nIdx, f"{lon_Vworld}")
|
||||
xls.SetCellValueStr(sheetTrg, 13, nIdx, f"{lat_Vworld}")
|
||||
|
||||
nIdx += 1
|
||||
|
||||
@@ -105,20 +78,23 @@ def CollectImageData(xls, sheetTrg, listImg, pathImgDir):
|
||||
|
||||
# DB 시트에 있는 파일을 골라내서 PoleInfo 시트에 넣는다.
|
||||
# PoleInfo : 번호, GPS 좌표, 구역, 주소, 사진
|
||||
def CollectPoleInfoData(xls, TrgSheetName, DBSheetName, pathImgDir):
|
||||
def CollectPoleInfoData(xls, TrgSheetName:str, DBSheetName:str, pathImgDir:str)-> int:
|
||||
if None == xls:
|
||||
return -1
|
||||
|
||||
nLastDBRow = xls.FindLastRow( DBSheetName )
|
||||
nLastDBRow:int = xls.FindLastRow( DBSheetName )
|
||||
if 0 >= nLastDBRow:
|
||||
print(f"{DBSheetName} Sheet is Empty.")
|
||||
return -1
|
||||
|
||||
# 헤더가 있는 시트는 헤더가 1, 그래서 2부터 시작
|
||||
# 헤더가 있는 시트는 헤더의 인덱스가 1, 그래서 2부터 시작
|
||||
nTrgRow = xls.FindLastRow(TrgSheetName) + 1
|
||||
for nDBRow in range(1, nLastDBRow + 1):
|
||||
listValues = xls.GetAllRowValue(DBSheetName, nDBRow, 8)
|
||||
# 0: Index, 1: Sheetname, 2:Date, 3:Level, 4:Rel Path, 5:Area, 6:Juso, 7:GPS(Lat,Lon)
|
||||
listValues = xls.GetAllRowValue(DBSheetName, nDBRow, 11)
|
||||
|
||||
# 0: Index, 1: Sheetname, 2: Date, 3: Level, 4: Rel Path,
|
||||
# 5: Area, 6: Juso, 7: Area_Road, 8: Juso_Road,
|
||||
# 9: GPS(Lon), 10: GPS(Lat), 11: VWorld(Lon), 12: VWorld(Lat)
|
||||
if None == listValues:
|
||||
continue
|
||||
|
||||
@@ -128,13 +104,14 @@ def CollectPoleInfoData(xls, TrgSheetName, DBSheetName, pathImgDir):
|
||||
if listValues[3] != "Pole" :
|
||||
continue
|
||||
|
||||
if listValues[7] == "" or listValues[7] == "0.0,0.0":
|
||||
# GPS 좌표가 없으면 패스
|
||||
if listValues[9] == "" or listValues[10] == "":
|
||||
continue
|
||||
|
||||
xls.SetCellValueStr(TrgSheetName, 1, nTrgRow, str(nTrgRow -1))
|
||||
xls.SetCellValueStr(TrgSheetName, 2, nTrgRow, listValues[7])
|
||||
xls.SetCellValueStr(TrgSheetName, 3, nTrgRow, listValues[5])
|
||||
xls.SetCellValueStr(TrgSheetName, 4, nTrgRow, listValues[6])
|
||||
xls.SetCellValueStr(TrgSheetName, 2, nTrgRow, listValues[5])
|
||||
xls.SetCellValueStr(TrgSheetName, 3, nTrgRow, listValues[6])
|
||||
xls.SetCellValueStr(TrgSheetName, 4, nTrgRow, listValues[7])
|
||||
|
||||
imgPath = os.path.join(pathImgDir, listValues[4])
|
||||
imgPath = exEXIF.ProcessImg(imgPath, 0.1, 80, True)
|
||||
@@ -142,6 +119,9 @@ def CollectPoleInfoData(xls, TrgSheetName, DBSheetName, pathImgDir):
|
||||
|
||||
xls.SetCellValueStr(TrgSheetName, 6, nTrgRow, listValues[0])
|
||||
|
||||
xls.SetCellValueStr(TrgSheetName, 7, nTrgRow, listValues[9])
|
||||
xls.SetCellValueStr(TrgSheetName, 8, nTrgRow, listValues[10])
|
||||
|
||||
# 목표 시트에 넣었으니 시트 이름을 DB 시트에 적어 넣는다.
|
||||
xls.SetCellValueStr(DBSheetName, 2, nDBRow, TrgSheetName)
|
||||
|
||||
@@ -163,9 +143,11 @@ def CollectPoleData( xls, TrgSheetName, InfoSheetName, DBSheetName, pathImgDir )
|
||||
# 헤더가 있는 시트는 헤더가 1, 그래서 2부터 시작
|
||||
nTrgRow = xls.FindLastRow(TrgSheetName) + 1
|
||||
for nDBRow in range(1, nLastDBRow + 1):
|
||||
listValues = xls.GetAllRowValue(DBSheetName, nDBRow, 8)
|
||||
listValues = xls.GetAllRowValue(DBSheetName, nDBRow, 13)
|
||||
|
||||
# 0: Index, 1: Sheetname, 2:Date, 3:Level, 4:Rel Path, 5:Area, 6:Juso, 7:GPS(Lat,Lon)
|
||||
# 0: Index, 1: Sheetname, 2: Date, 3: Level, 4: Rel Path,
|
||||
# 5: Area, 6: Juso, 7: Area_Road, 8: Juso_Road,
|
||||
# 9: GPS(Lon), 10: GPS(Lat), 11: VWorld(Lon), 12: VWorld(Lat)
|
||||
if None == listValues:
|
||||
continue
|
||||
|
||||
@@ -175,7 +157,8 @@ def CollectPoleData( xls, TrgSheetName, InfoSheetName, DBSheetName, pathImgDir )
|
||||
if listValues[3] != "A" and listValues[3] != "B" :
|
||||
continue
|
||||
|
||||
if listValues[7] == "" or listValues[7] == "0.0,0.0":
|
||||
# GPS 좌표가 없으면 패스
|
||||
if listValues[9] == "" or listValues[10] == "":
|
||||
continue
|
||||
|
||||
# 날짜만 골라낸다.
|
||||
@@ -188,12 +171,13 @@ def CollectPoleData( xls, TrgSheetName, InfoSheetName, DBSheetName, pathImgDir )
|
||||
xls.SetCellValueStr(TrgSheetName, 2, nTrgRow, strDate)
|
||||
|
||||
# 가장 가까운 점봇대를 찾는다. 인덱스를 얻어서...
|
||||
strLat, strLon = listValues[7] .split(',')
|
||||
strLon = listValues[9]
|
||||
strLat = listValues[10]
|
||||
nPoleIdx, nDistance = xls.FindCloestPole(float(strLat), float(strLon))
|
||||
|
||||
# 배열은 0부터, Pole 인덱스는 1부터 시작하고, 셀 번호는 헤더를 포함해서 2 부터 시작한다.
|
||||
# 셀 번호를 넣어서 해당하는 정보를 가져온다.
|
||||
# 0:번호, 1:GPS 좌표, 2:구역, 3:주소, 4:사진
|
||||
# 0:번호, 1:구역, 2:주소, 3: 도로명, 4:사진, 5: ImgIndex, 6:GPS(Lon), 7:GPS(Lat)
|
||||
#print( f"{nDBRow} : {nTrgRow} : {nPoleIdx}")
|
||||
retList = xls.GetAllRowValue(InfoSheetName, nPoleIdx, 5)
|
||||
|
||||
@@ -220,13 +204,13 @@ def CollectPoleData( xls, TrgSheetName, InfoSheetName, DBSheetName, pathImgDir )
|
||||
return nTrgRow
|
||||
|
||||
|
||||
def GetJPGFileLIst(pathImageDir):
|
||||
trgDirList = util.GetSubDirectories(pathImageDir)
|
||||
def GetJPGFileLIst(pathImageDir:str) -> list[str]:
|
||||
trgDirList:list[str] = util.GetSubDirectories(pathImageDir)
|
||||
|
||||
#print(f"DBG : GetJPGFileLIst : {pathImageDir}, {trgDirList}")
|
||||
#input("Press Enter to continue...")
|
||||
|
||||
retImgList = []
|
||||
retImgList:list[str] = []
|
||||
for dirName in trgDirList:
|
||||
if dirName.lower() == "thumb":
|
||||
continue
|
||||
@@ -243,9 +227,9 @@ def GetJPGFileLIst(pathImageDir):
|
||||
return retImgList
|
||||
|
||||
|
||||
def Process(PathImg, PathXLS):
|
||||
def Process(PathImg:str, PathXLS:str):
|
||||
# 이미지 파일 목록 작성
|
||||
trgImgList = GetJPGFileLIst(PathImg)
|
||||
trgImgList:list[str] = GetJPGFileLIst(PathImg)
|
||||
|
||||
# 엑셀을 연다.
|
||||
XLSPath = os.path.join(PathXLS, "EPoleDB.xlsx")
|
||||
|
||||
Reference in New Issue
Block a user