def GenerateKAP(self, atlas, atlasname): self.atlas = atlas now = datetime.datetime.now() creationtimestamp = now.strftime("%Y%m%d-%H%M") self.logger.info("Cleanup Kap Directory") kapdirname = "{}kap/OSM-OpenCPN2-KAP-{}-{}/".format(self._WorkingDirectory, atlasname, creationtimestamp) RemoveDir(kapdirname) cnt = 0 for singlemap in atlas: cnt = cnt + 1 ci = ChartInfo(singlemap) self.logger.info("################################################################################") self.logger.info("Process Chart {}, {}/{}".format(ci.name, cnt, len(atlas))) kapfilename = "{}/{}_{}.kap".format(kapdirname, ci.name, ci.zoom) # Stitch tiles to single map file tempfilename_street = self.StichTiles(ci, atlasname, OpenStreetMap) tempfilename_sea = self.StichTiles(ci, atlasname, OpenSeaMap) PathTempTiles = self._WorkingDirectory + "{}/{}/{}/{}/{}/".format(STICHDIR, OpenSeaMapMerged, atlasname, ci.name, ci.zoom) RemoveDir(PathTempTiles) ensure_dir(PathTempTiles) tempfilename = "{}{}_{}.png".format(PathTempTiles, ci.name, ci.zoom) # merge files _MergePictures(tempfilename_street, tempfilename_sea, tempfilename) # MergePictures(tempfilename_sea, tempfilename_street, tempfilename+".2.png") tempfilereduced = tempfilename # generate kap file self.logger.info("generate kap file {}".format(kapfilename)) GenerateKapFile(tempfilereduced, kapfilename, ci) # copy info.txt shutil.copyfile("documents/info.txt", kapdirname + "info.txt") atlasfilename = "{}history/kap/OSM-OpenCPN2-KAP-{}-{}.7z".format(self._WorkingDirectory, atlasname, creationtimestamp) ZipFiles(kapdirname, atlasfilename) atlasfilename_latest = "./work/kap/OSM-OpenCPN2-KAP-{}.7z".format(atlasname) ratlasfilename = "../history/kap/OSM-OpenCPN2-KAP-{}-{}.7z".format(atlasname, creationtimestamp) os.symlink(ratlasfilename, atlasfilename_latest)
def __init__(self, FilenameDB): ensure_dir(FilenameDB) self.logger = getlog() self.FilenameDB = FilenameDB # check if db excists if os.path.isfile(FilenameDB) is False: self.InitDB() else: self.con = sqlite3.connect(self.FilenameDB) self.cur = self.con.cursor() self.writecnt = 0
def __init__(self, workspace): ensure_dir(workspace) self.ws = workspace self.logger = getlog() self.FilenameDB = workspace + FILENAMESQLLITEDB # check if db excists if os.path.isfile(self.FilenameDB) is False: self.InitDB() else: self.con = sqlite3.connect(self.FilenameDB) self.cur = self.con.cursor() self.cur.execute("""PRAGMA journal_mode = WAL""") self.cur.execute("""PRAGMA synchronous = NORMAL""") self.writecnt = 0
def StoreTile(self, tsname, tile, z, x, y): filenametile = "{}{}/{}/{}/{}.png".format(self.ws, tsname, z, x, y) ensure_dir(filenametile) with open(filenametile, 'wb') as f: self.logger.debug("Store Tile {} bytes".format(len(tile.data))) f.write(tile.data) filenameinfo = filenametile + ".yaml" m = hashlib.md5() m.update(tile.data) data = { "date": tile.date, "lastmodified": tile.lastmodified, "etag": tile.etag, "updated": tile.updated, "md5": m.hexdigest() } with io.open(filenameinfo, 'w', encoding='utf8') as outfile: yaml.dump(data, outfile, default_flow_style=False, allow_unicode=True)
def __init__(self, workspace): ensure_dir(workspace) self.ws = workspace self.logger = getlog()
options, arguments = parser.parse_args() maps = list() # get a list of kap files for a given path kapfilelist = _GetFileList(options.InDir, '.kap') zoom = 16 print("KapAnalyser: {} kap files found".format(len(kapfilelist))) # create a list with for kfile in kapfilelist: kap = kapfile(kfile) ti = kap.GetTileInfo(zoom) print(ti) maps.append(ti) # write mobac project file if options.MobacPrjFilename: print("WriteMobacProject {}".format(options.MobacPrjFilename)) ensure_dir(options.MobacPrjFilename) WriteMobacProject(options.name, options.MobacPrjFilename, maps) # write chart designer project file if options.ChartDesignerPrjFilename: print("ChartDesignerPrject {}".format(options.ChartDesignerPrjFilename)) ensure_dir(options.ChartDesignerPrjFilename) WriteChartDesignerProject(options.name, options.ChartDesignerPrjFilename, maps) print("ready")
def generate_mbtile(self, atlas, atlasname): ''' generate atlas in mbtile format ''' self.atlas = atlas now = datetime.datetime.now() creationtimestamp = now.strftime("%Y%m%d-%H%M") atlasdirname = "{}mbtiles/OSM-mbtile-{}-{}/".format(self._WorkingDirectory, atlasname, creationtimestamp) mbtilefilename = "{}/{}.mbtiles".format(atlasdirname, atlasname) self.logger.info("Cleanup tilestore Directory") RemoveDir(atlasdirname) tilestore = MBTileStore(mbtilefilename) minlon = None maxlon = None minlat = None maxlat = None cnt = 0 for singlemap in atlas: cnt = cnt + 1 ci = ChartInfo(singlemap) self.logger.info("################################################################################") self.logger.info("Process Chart {}, {}/{}".format(ci.name, cnt, len(atlas))) # export tiles self.logger.info("Export {} Tiles".format(ci.nr_of_tiles)) for y in range(ci.ytile_nw, ci.ytile_se + 1): for x in range(ci.xtile_nw, ci.xtile_se + 1): # get tiles from db tile = self.db.GetTile(OpenSeaMapMerged, ci.zoom, x, y) # check if tile exists if tile is None: self.logger.error("tile with z={} x={} y={} not available in store\n".format(ci.zoom, x, y)) assert(0) sys.exit(1) tilestore.StoreTile(tile, ci.zoom, x, y) # determine min lon if minlon is None: minlon = ci.NW_lon else: if minlon > ci. NW_lon: minlon = ci.NW_lon # determine max lon if maxlon is None: maxlon = ci.SE_lon else: if maxlon < ci. SE_lon: maxlon = ci.SE_lon if minlat is None: minlat = ci.SE_lat else: if minlat > ci. SE_lat: minlat = ci.SE_lat if maxlat is None: maxlat = ci.NW_lat else: if maxlat < ci. NW_lat: maxlat = ci.NW_lat # set mandatory attributes tilestore.SetMetadata("name", atlasname) tilestore.SetMetadata("format", "png") # set optional attributes tilestore.SetMetadata("type", "baselayer") # left, bottom, right, top tilestore.SetMetadata("bounds", "{}, {}, {}, {}".format(minlon, minlat, maxlon, maxlat)) tilestore.SetMetadata("date", creationtimestamp) # copy info.txt # shutil.copyfile("documents/info.txt", atlasdirname + "info.txt") tilestore.CloseDB() atlasfilename = "{}history/mbtiles/OSM-OpenCPN2-{}-{}.mbtiles".format(self._WorkingDirectory, atlasname, creationtimestamp) ensure_dir(atlasfilename) shutil.copyfile(mbtilefilename, atlasfilename) RemoveFile(mbtilefilename) RemoveDir(atlasdirname) atlasfilename_latest = "./work/mbtiles/OSM-OpenCPN2-{}.mbtiles".format(atlasname) ratlasfilename = "../history/mbtiles/OSM-OpenCPN2-{}-{}.mbtiles".format(atlasname, creationtimestamp) print("remove file {}".format(atlasfilename_latest)) RemoveFile(atlasfilename_latest) print("create link src {} <- dst {}".format(ratlasfilename, atlasfilename_latest)) os.symlink(ratlasfilename, atlasfilename_latest)
def StoreFile(self, filename): ensure_dir(filename) with open(filename, 'wb') as f: f.write(self.data)