def makeArrowDat(self, srcDir, destDir): if os.path.isdir(srcDir) == False: print "input directory not exist! " + srcDir return if(os.path.exists(destDir) == True): shutil.rmtree(destDir) os.mkdir(destDir) strSqlCmd = ''' select arrow1 from org_jv_location where arrow1 is not null union (select arrow2 from org_jv_location where arrow2 is not null) union (select arrow3 from org_jv_location where arrow3 is not null) union (select arrow4 from org_jv_location where arrow4 is not null) ''' self.pgcur2.execute(strSqlCmd) rows = self.pgcur2.fetchall() for row in rows: arrowPngName = row[0] arrowPngPath = os.path.join(srcDir, arrowPngName) if os.path.isfile(arrowPngPath) == False: continue oneFile = common_functions.datSegmentInfo() oneFile.datInfo = common_functions.DAY_AND_NIGHT_COMMON # 这是一张不区分白天黑夜的箭头图 oneFile.imgPath = arrowPngPath common_functions.ComposePicsToDat([oneFile], destDir, arrowPngName[:-4:]) return
def make_sign_as_real_csv(self, sarSrcDir, allJvCsv, destDir, outputCSV='sign_as_real.csv'): if os.path.isdir(sarSrcDir) == False: print "source directory not found: " + sarSrcDir return if os.path.isfile(allJvCsv) == False: print "source csv file not found: " + allJvCsv return if (os.path.exists(destDir) == True): shutil.rmtree(destDir) os.mkdir(destDir) ejvRecordList = common_functions.analyse_csv(allJvCsv) signpostList = [] for ejvRecord in ejvRecordList: if ejvRecord['filename'] != '': continue if ejvRecord['ejv_filename'] != '': continue if ejvRecord['sar_filename'] == '': continue signpostList.append(ejvRecord['sar_filename']) signpostList = list(set(signpostList)) sarPngList = [] for curDir, dirNames, fileNames in os.walk(sarSrcDir): for oneFile in fileNames: sarPngList.append(os.path.join(curDir, oneFile)) oFStream = open(outputCSV, "w") for signpost in signpostList: for sarPng in sarPngList: if sarPng.lower().find( os.path.splitext(signpost)[0].lower()) != -1: oneFile = common_functions.datSegmentInfo() oneFile.datInfo = common_functions.DAY_AND_NIGHT_COMMON # 这是一张不区分白天黑夜的signpost图 oneFile.imgPath = sarPng common_functions.ComposePicsToDat( [oneFile], destDir, ) oFStream.close() return
def makePatternDat(self, srcDir, destDir): if os.path.isdir(srcDir) == False: print "can not find directory: %s." % srcDir return if(os.path.exists(destDir) == True): shutil.rmtree(destDir) os.mkdir(destDir) self.pgcur2.execute(''' select distinct fm_edge, to_edge1, to_edge2, to_edge3, to_edge4, array_agg(road_lyr) as road_lyr_list, array_agg(sign_lyr) as sign_lyr_list from org_jv_location group by fm_edge, to_edge1, to_edge2, to_edge3, to_edge4''') rows = self.pgcur2.fetchall() for row in rows: print "-----------------------------------------------------------------------------------------" # day and night illust road_lyr_list = row[5] # road_lyr列表,正常情况下,此列表中不应有空值。 sign_lyr_list = row[6] # sign_lyr列表,此列表可能有None值,对应情况是此点没有sar图。 fileList = [] assert len(road_lyr_list) == len(sign_lyr_list) for onePattern, oneSar in zip(road_lyr_list, sign_lyr_list): if onePattern is None: # road图名字为空,出错,pass。 continue outputDatName = '' if oneSar is None: outputDatName = onePattern else: outputDatName = onePattern[:-4] + '_' + oneSar patternPngPath = os.path.join(srcDir, outputDatName) if os.path.isfile(patternPngPath): oneFile = common_functions.datSegmentInfo() oneFile.datInfo = common_functions.DAY_AND_NIGHT_COMMON # 这是一张不区分白天黑夜的箭头图 oneFile.imgPath = patternPngPath fileList.append(oneFile) # 已与数据表数据制作时约定:使用第0个pattern图名字和第0个sar图名字拼成dat名字。 # guideinfo_spotguide_mmi.py: 144 destDatName = road_lyr_list[0][:-4:] + sp_splitter + sign_lyr_list[1][:-4:] common_functions.ComposePicsToDat(fileList, destDir, destDatName)
def makeJunctionViewIllust(self, srcDir, destDir): if os.path.isdir(srcDir) == False: print "input directory not exist! " + srcDir return if(os.path.exists(destDir) == True): shutil.rmtree(destDir) os.mkdir(destDir) # 遍历元数据文件夹,列出四维提供的所有.png图片 totalPngInDisk = [] for curDir,dirNames,fileNames in os.walk(srcDir): for oneFile in fileNames: if(os.path.splitext(oneFile)[1].lower() == '.png'): totalPngInDisk.append(os.path.join(curDir, oneFile)) for onePng in totalPngInDisk: oneFile = common_functions.datSegmentInfo() oneFile.datInfo = common_functions.DAY_AND_NIGHT_COMMON # 中国仕向地的图片不区分白天黑夜 oneFile.imgPath = onePng common_functions.ComposePicsToDat([oneFile], destDir, os.path.splitext(os.path.split(onePng)[1])[0])
def makeGjvDat(self, srcDir, destDir): if os.path.isdir(srcDir) == False: print "source directory not found: " + srcDir return if (os.path.exists(destDir) == True): shutil.rmtree(destDir) os.mkdir(destDir) # 列出所有pattern图。 # 由svg tool解压出来的图片文件夹结构最后一层应为DAY或NIGHT(在svg tool中选中制作黑白图)。 # DAY包含白天的所有pattern图和arrow图。 # NIGHT包含黑夜的所有pattern图和arrow图。 # pattern图一般为.jpg(在svg tool中所设置),arrow图一般为.png(在svg tool中设置)。 # 黑白pattern图有区别,黑白arrow图无区别。 # 合并时将黑白pattern图合并成一个dat。 # arrow图仅取白天的合并。 # 完。 dayPatternDict = {} # 白天pattern图列表。 dayArrowDict = {} # 白天arrow图列表。 nightPatternDict = {} # 黑夜pattern图列表。 for curDir, dirNames, fileNames in os.walk(srcDir): if curDir.lower().find('day') != -1: # 白天图 for oneFile in fileNames: if oneFile[-4:] == ".jpg": # pattern图 dayPatternDict[oneFile] = os.path.join( curDir, oneFile).lower() if oneFile[-4:] == ".png": # arrow图 dayArrowDict[oneFile] = os.path.join(curDir, oneFile).lower() if curDir.lower().find('night') != -1: # 黑夜图 for oneFile in fileNames: if oneFile[-4:] == ".jpg": # pattern图 nightPatternDict[oneFile] = os.path.join( curDir, oneFile).lower() # 合并pattern图 for dayPatternKey in dayPatternDict: if dayPatternKey in nightPatternDict: fileList = [] oneFile = common_functions.datSegmentInfo() oneFile.datInfo = common_functions.DAY_PATTERN # 这是一张白天图 oneFile.imgPath = dayPatternDict[dayPatternKey] fileList.append(oneFile) oneFile = common_functions.datSegmentInfo() oneFile.datInfo = common_functions.NIGHT_PATTERN # 这是一张黑夜图 oneFile.imgPath = nightPatternDict[dayPatternKey] fileList.append(oneFile) dayPatternName = os.path.splitext( os.path.split(dayPatternDict[dayPatternKey])[1])[0] common_functions.ComposePicsToDat( fileList, destDir, dayPatternName) # 将这两张图合并成dat,并以白天图名字命名 # 合并arrow图 for dayArrowKey in dayArrowDict: oneFile = common_functions.datSegmentInfo() oneFile.datInfo = common_functions.DAY_AND_NIGHT_COMMON # 这是一张不区分白天黑夜的箭头图 oneFile.imgPath = dayArrowDict[dayArrowKey] dayArrowName = os.path.splitext( os.path.split(dayArrowDict[dayArrowKey])[1])[0] # dat命名式样:直接使用白天arrow图名字命名dat common_functions.ComposePicsToDat([oneFile], destDir, dayArrowName) return