246 lines
9.1 KiB
Python
246 lines
9.1 KiB
Python
import os
|
|
#import sys
|
|
|
|
import UtilPack as util
|
|
import PoleXLS as myxl
|
|
import ExtEXIFData as exEXIF
|
|
import VWorldAPIs as vwapi
|
|
import JusoMngr
|
|
|
|
|
|
def GetPoleInfos(xls, nRow:int):
|
|
if None == xls or False == isinstance(xls, myxl.PoleXLS):
|
|
return []
|
|
|
|
retList = xls.GetAllRowValue("PoleInfo", nRow, 5)
|
|
return retList
|
|
|
|
|
|
# 필요한 이미지 정보를 모아 한 시트에 전부 넣는다.
|
|
def CollectImageData(xls, sheetTrg, listImg, pathImgDir):
|
|
if None == xls or False == isinstance(xls, myxl.PoleXLS) or True == util.IsEmptyStr(sheetTrg):
|
|
return -1
|
|
|
|
pathCurrent = os.getcwd()
|
|
pathcsv = os.path.join(pathCurrent, "JusoDB.csv")
|
|
jusomgr = JusoMngr.JusoDB(pathcsv)
|
|
|
|
nIdx = 1
|
|
for item in listImg:
|
|
# 이미지가 삽입되었는지 여부 확인
|
|
if 0 < xls.FindInsertedImgPath(pathImgDir, item):
|
|
nIdx = xls.FindLastRow(sheetTrg) + 1
|
|
continue
|
|
|
|
all_date, lat, lon = exEXIF.GetDateInfo(item)
|
|
pathRel = os.path.relpath( item, pathImgDir)
|
|
level = util.GetParentDirName(item, 1)
|
|
if level == "Thumb":
|
|
continue
|
|
|
|
print(f"DBG : {nIdx}, CollectImageData : {item}, {pathImgDir}, {pathRel}")
|
|
|
|
# 0 : 지번, 1 : 구역, 2 : 도로명, 3 : 도로명 구역
|
|
juso = vwapi.GetJusofromGPS(lat, lon)
|
|
|
|
# 주소 조회가 안되는 현상이 있다. 재시도...
|
|
if lat != 0.0 and lon != 0.0 and juso[2] == "":
|
|
juso = vwapi.GetJusofromGPS(lat, lon)
|
|
|
|
# 도로명 주소를 못 끌어오면, 저장해 둔 목록에서 한번 더 조회
|
|
if juso[0] != "" and juso[2] == "":
|
|
juso[2] = jusomgr.ConvJusoToRoad(juso[0])
|
|
juso[3] = jusomgr.GetRoadArea(juso[2])
|
|
|
|
xls.SetCellValueStr(sheetTrg, 1, nIdx, nIdx)
|
|
xls.SetCellValueStr(sheetTrg, 2, nIdx, "") # 이미지가 들어갈 시트 이름. 넣을 떄 넣자.
|
|
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[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, 12, nIdx, f"{lon_Vworld}")
|
|
xls.SetCellValueStr(sheetTrg, 13, nIdx, f"{lat_Vworld}")
|
|
|
|
nIdx += 1
|
|
|
|
return nIdx
|
|
|
|
# DB 시트에 있는 파일을 골라내서 PoleInfo 시트에 넣는다.
|
|
# PoleInfo : 번호, GPS 좌표, 구역, 주소, 사진
|
|
def CollectPoleInfoData(xls, TrgSheetName:str, DBSheetName:str, pathImgDir:str)-> int:
|
|
if None == xls:
|
|
return -1
|
|
|
|
nLastDBRow:int = xls.FindLastRow( DBSheetName )
|
|
if 0 >= nLastDBRow:
|
|
print(f"{DBSheetName} Sheet is Empty.")
|
|
return -1
|
|
|
|
# 헤더가 있는 시트는 헤더의 인덱스가 1, 그래서 2부터 시작
|
|
nTrgRow = xls.FindLastRow(TrgSheetName) + 1
|
|
for nDBRow in range(1, nLastDBRow + 1):
|
|
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
|
|
|
|
if listValues[1] == TrgSheetName:
|
|
continue
|
|
|
|
if listValues[3] != "Pole" :
|
|
continue
|
|
|
|
# GPS 좌표가 없으면 패스
|
|
if listValues[9] == "" or listValues[10] == "":
|
|
continue
|
|
|
|
xls.SetCellValueStr(TrgSheetName, 1, nTrgRow, str(nTrgRow -1))
|
|
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)
|
|
xls.SetCellValueImg(TrgSheetName, 5, nTrgRow, imgPath)
|
|
|
|
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)
|
|
|
|
nTrgRow += 1
|
|
|
|
return nTrgRow
|
|
|
|
# DB 시트와 점봇대 정보 시트로 정보를 찾고 계산한다.
|
|
# Pole : 연번, 점검일자, 구역, 가까운 전신주 번호, 가까운 전신주 거리, 심각, 양호, 등급, 비고
|
|
def CollectPoleData( xls, TrgSheetName, InfoSheetName, DBSheetName, pathImgDir ):
|
|
if None == xls:
|
|
return -1
|
|
|
|
nLastDBRow = xls.FindLastRow( DBSheetName )
|
|
if 0 >= nLastDBRow:
|
|
print(f"{DBSheetName} Sheet is Empty.")
|
|
return -1
|
|
|
|
# 헤더가 있는 시트는 헤더가 1, 그래서 2부터 시작
|
|
nTrgRow = xls.FindLastRow(TrgSheetName) + 1
|
|
for nDBRow in range(1, nLastDBRow + 1):
|
|
listValues = xls.GetAllRowValue(DBSheetName, nDBRow, 13)
|
|
|
|
# 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
|
|
|
|
if listValues[1] == TrgSheetName:
|
|
continue
|
|
|
|
if listValues[3] != "A" and listValues[3] != "B" :
|
|
continue
|
|
|
|
# GPS 좌표가 없으면 패스
|
|
if listValues[9] == "" or listValues[10] == "":
|
|
continue
|
|
|
|
# 날짜만 골라낸다.
|
|
strDate = ""
|
|
if listValues[2] != "":
|
|
strDate, strTime = listValues[2] .split(' ')
|
|
strDate = strDate.replace(':','/')
|
|
|
|
xls.SetCellValueStr(TrgSheetName, 1, nTrgRow, str(nTrgRow -1))
|
|
xls.SetCellValueStr(TrgSheetName, 2, nTrgRow, strDate)
|
|
|
|
# 가장 가까운 점봇대를 찾는다. 인덱스를 얻어서...
|
|
strLon = listValues[9]
|
|
strLat = listValues[10]
|
|
nPoleIdx, nDistance = xls.FindCloestPole(float(strLat), float(strLon))
|
|
|
|
# 배열은 0부터, Pole 인덱스는 1부터 시작하고, 셀 번호는 헤더를 포함해서 2 부터 시작한다.
|
|
# 셀 번호를 넣어서 해당하는 정보를 가져온다.
|
|
# 0:번호, 1:구역, 2:주소, 3: 도로명, 4:사진, 5: ImgIndex, 6:GPS(Lon), 7:GPS(Lat)
|
|
#print( f"{nDBRow} : {nTrgRow} : {nPoleIdx}")
|
|
retList = xls.GetAllRowValue(InfoSheetName, nPoleIdx, 5)
|
|
|
|
xls.SetCellValueStr(TrgSheetName, 3, nTrgRow, retList[2])
|
|
xls.SetCellValueStr(TrgSheetName, 4, nTrgRow, nPoleIdx)
|
|
xls.SetCellValueStr(TrgSheetName, 5, nTrgRow, nDistance)
|
|
|
|
ColIdx = 6
|
|
if listValues[3] == "B" :
|
|
ColIdx = 7
|
|
|
|
imgAbsPath = os.path.join(pathImgDir, listValues[4])
|
|
imgpath = exEXIF.ProcessImg(imgAbsPath, 0.1, 80, True)
|
|
xls.SetCellValueImg(TrgSheetName, ColIdx, nTrgRow, imgpath)
|
|
|
|
xls.SetCellValueStr(TrgSheetName, 8, nTrgRow, listValues[3])
|
|
xls.SetCellValueStr(TrgSheetName, 9, nTrgRow, nDBRow)
|
|
|
|
# 목표 시트에 넣었으니 시트 이름을 DB 시트에 적어 넣는다.
|
|
xls.SetCellValueStr(DBSheetName, 2, nDBRow, TrgSheetName)
|
|
|
|
nTrgRow += 1
|
|
|
|
return nTrgRow
|
|
|
|
|
|
def GetJPGFileLIst(pathImageDir:str) -> list[str]:
|
|
trgDirList:list[str] = util.GetSubDirectories(pathImageDir)
|
|
|
|
#print(f"DBG : GetJPGFileLIst : {pathImageDir}, {trgDirList}")
|
|
#input("Press Enter to continue...")
|
|
|
|
retImgList:list[str] = []
|
|
for dirName in trgDirList:
|
|
if dirName.lower() == "thumb":
|
|
continue
|
|
|
|
imgSubDirPath = os.path.join(pathImageDir, dirName)
|
|
contents = os.listdir(imgSubDirPath)
|
|
|
|
for item in contents:
|
|
name, ext = os.path.splitext(item)
|
|
if ext.lower() == '.jpg':
|
|
imgPath = os.path.join(imgSubDirPath, item)
|
|
retImgList.append(imgPath)
|
|
|
|
return retImgList
|
|
|
|
|
|
def Process(PathImg:str, PathXLS:str):
|
|
# 이미지 파일 목록 작성
|
|
trgImgList:list[str] = GetJPGFileLIst(PathImg)
|
|
|
|
# 엑셀을 연다.
|
|
XLSPath = os.path.join(PathXLS, "EPoleDB.xlsx")
|
|
tempxls = myxl.PoleXLS(XLSPath)
|
|
tempxls.DBXLSOpen()
|
|
|
|
# 이미지 정보를 전부 모아서 한 시트에 저장
|
|
CollectImageData(tempxls, "ImgInfo", trgImgList, PathImg)
|
|
# 모아 놓은 이미지 정보에서 점봇대 정보를 골라서 저장
|
|
CollectPoleInfoData(tempxls, "PoleInfo", "ImgInfo", PathImg)
|
|
# 점봇대 정보 시트를 바탕으로 제보받은 이미지를 판별, 계산하여 저장
|
|
CollectPoleData(tempxls, "Poles", "PoleInfo", "ImgInfo", PathImg)
|
|
|
|
tempxls.DBXLSClose() |