Ejemplo n.º 1
0
 def __init__(self, WorkingDirectory, db):
     '''
     Constructor
     '''
     self._WorkingDirectory = WorkingDirectory
     self.db = db
     self.logger = getlog()
Ejemplo n.º 2
0
    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
Ejemplo n.º 3
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
Ejemplo n.º 4
0
    def run(self):
        self.log = getlog()
        #self.log.info("DownloadThread::run")
        self.db = TileSqlLiteDB(self.DBDIR)

        while (self.stop is False):
            if len(self.tileman.joblist) is 0:
                self.stop = True
                break
            job = self.tileman.joblist[0]
            self.tileman.joblist.pop(0)
            #self.log.info("{} is working on job {} {} {} {}".format(self.name, job[0], job[1], job[2], job[3]))

            x = job[1]
            y = job[2]
            z = job[3]

            self.lock.acquire()
            tile_osm2 = self.db.GetTile(self.tileserv.name, z, x, y)
            self.lock.release()

            # skip download if tile is available
            if (tile_osm2 is not None) and (self.force_download is False):
                # print("skip update of tile z={} x={} y={} from {}".format(z, x, y, self.tileserv.name))
                self.tileman.tileskipped += 1
            # skip download if tile is newer the 7 days
            elif (tile_osm2 is not None) and (self.CheckTimespan(
                    tile_osm2, 14 * 24) is False):
                # print("skip update of tile z={} x={} y={} from {}".format(z, x, y, self.tileserv.name))
                self.tileman.tileskipped += 1
            else:
                tile_osm2 = self._HttpLoadFile(self.tileserv, z, x, y,
                                               tile_osm2)
                if tile_osm2 is None:
                    return
                if (tile_osm2.updated is True) or (tile_osm2.date_updated is
                                                   True):
                    self.lock.acquire()
                    self.db.StoreTile(self.tileserv.name, tile_osm2, z, x, y)
                    self.lock.release()
            self.tileman.tile += 1
            self.cnt += 1
        self.db.CloseDB()
Ejemplo n.º 5
0
    def __init__(self, WorkingDirectory, DBDIR):
        '''
        Constructor
        '''
        self._WorkingDirectory = WorkingDirectory

        self.DBDIR = DBDIR
        self.logger = getlog()

        self.tile = 0
        self.tiledownloaded = 0
        self.tiledownloadskipped = 0
        self.tileskipped = 0
        self.tilemerged = 0
        self.tilemergedskipped = 0
        self.downloaderror = 0
        self.Error_304 = 0
        self.Error_502 = 0
        self.Error_404 = 0
        self.Error_url = 0

        # just ensure that db UDP_TUNNEL
        db = TileSqlLiteDB(self.DBDIR)
        db.CloseDB()
Ejemplo n.º 6
0
 def __init__(self, workspace):
     ensure_dir(workspace)
     self.ws = workspace
     self.logger = getlog()
Ejemplo n.º 7
0
 def setUp(self):
     initlog('bTestConvert')
     self.logger = getlog()
Ejemplo n.º 8
0
 def setUp(self):
     initlog('bTestSQLliteDB')
     self.logger = getlog()
     RemoveDir('./../sample/tilestoresql/')
     self.sqldb = TileSqlLiteDB('./../sample/tilestoresql/')
Ejemplo n.º 9
0
def main():
    parser = argparse.ArgumentParser(description='fetch tiles')
    WDIR = os.getcwd() + '/work/'
    DBDIR = WDIR + "database/"
    parser.add_argument(
        "-i",
        help="MOBAC Project File",
        dest="ProjectFile",
        default="./sample/atlas/mobac/mobac-profile-testprj.xml")

    parser.add_argument("-d",
                        "--DatabaseDirectory",
                        help="tile store directory",
                        dest="DBDIR",
                        default=DBDIR)

    parser.add_argument("-q",
                        "--quiet",
                        action="store_false",
                        dest="quiet",
                        default=True,
                        help="set log level to info (instead debug)")

    parser.add_argument("-s",
                        "--skip",
                        action="store_true",
                        dest="skip_os",
                        help="skip odd zoom levels")

    parser.add_argument("-m",
                        "--mapsource",
                        help="map server configuration file",
                        dest="MapSrcFile",
                        default="./sample/mapsource/mp-OpenSeaMap.yaml")

    args = parser.parse_args()

    initlog('fetch', args.quiet)
    logger = getlog()

    logger.info('Start merge tiles')

    if (args.skip_os is True):
        zoom_filter = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]
    else:
        zoom_filter = []

    # get maps from mobac project file
    if args.ProjectFile is not None:
        # get list of chart areas from project file
        atlas, name = ExtractMapsFromAtlas(args.ProjectFile, zoom_filter)
        logger.info('atlas name={} number of maps={}'.format(name, len(atlas)))
    else:
        exit()

    tm = TileManager(WDIR, args.DBDIR)

    with open(args.MapSrcFile) as json_file:
        data = json.load(json_file)

    logger.info('')
    logger.info('server info:')
    logger.info('{} url={}'.format(data['basic_layer']['name'],
                                   data['basic_layer']['url']))
    logger.info('{} url={}'.format(data['seamark_layer']['name'],
                                   data['seamark_layer']['url']))
    logger.info('')
    logger.info('database info:')
    logger.info('{}'.format(args.DBDIR))
    logger.info('')
    logger.info('project info:')
    logger.info('{}'.format(args.ProjectFile))

    TSOpenStreetMap = TileServer(data['basic_layer']['name'],
                                 data['basic_layer']['url'])
    TsOpenSeaMap = TileServer(data['seamark_layer']['name'],
                              data['seamark_layer']['url'])

    logger.info('Fetch Open Sea Map tiles from {}'.format(
        TSOpenStreetMap.name))
    mapcnt = 1
    for singlemap in atlas:
        ti = ChartInfo(singlemap)
        logger.info('\n\nStart Merge Tile {} / {}:'.format(mapcnt, len(atlas)))
        mapcnt += 1
        starttime = time.time()
        logger.info(ti)
        cnt = tm.MergeTiles(TsOpenSeaMap, TSOpenStreetMap, ti)
        stoptime = time.time()
        runtime = (stoptime - starttime)
        if runtime == 0:
            runtime = 1
        logger.info('time: {} s'.format(int(stoptime - starttime)))
        logger.info('tiles merged           {}'.format(tm.tilemerged))
        logger.info('tiles mergedskipped    {}'.format(tm.tilemergedskipped))
        logger.info('processsed tiles/s     {0:.2f}'.format(cnt / runtime))

    logger.info('\n\nready')

    return
Ejemplo n.º 10
0
 def setUp(self):
     initlog('bTestMerge')
     self.logger = getlog()
Ejemplo n.º 11
0
def main():
    parser = OptionParser()
    parser.add_option("-i",
                      "--InFile",
                      type="string",
                      help="MOBAC Project File",
                      dest="ProjectFile",
                      default="./sample/atlas/mobac/mobac-profile-testprj.xml")
    parser.add_option("-d",
                      "--DatabaseDirectory",
                      type="string",
                      help="tile store directory",
                      dest="DBDIR",
                      default=DBDIR)
    parser.add_option("-q",
                      "--quiet",
                      action="store_false",
                      dest="quiet",
                      default=True,
                      help="set log level to info (instead debug)")
    parser.add_option("-s",
                      "--skip",
                      action="store_true",
                      dest="skip_os",
                      help="skip odd zoom levels")
    parser.add_option("-t",
                      "--Type",
                      type="string",
                      help="atlas type (kap or mbtile)",
                      dest="AtlasType",
                      default="kap")

    options, arguments = parser.parse_args()
    arguments = arguments

    initlog('build', options.quiet)
    logger = getlog()

    logger.info('Start build mbtiles')

    if (options.skip_os is True):
        zoom_filter = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]
    else:
        zoom_filter = []

    logger.info('')
    logger.info('database info:')
    logger.info('{}'.format(options.DBDIR))
    logger.info('')
    logger.info('project info:')
    logger.info('{}'.format(options.ProjectFile))

    # get maps from mobac project file
    if options.ProjectFile is not None:
        # get list of chart areas from project file
        atlas, name = ExtractMapsFromAtlas(options.ProjectFile, zoom_filter)
    else:
        exit()

    db = TileSqlLiteDB(options.DBDIR)
    gen = AtlasGenerator(WDIR, db)

    if options.AtlasType.find("kap") == 0:
        gen.GenerateKAP(atlas, name)
    elif options.AtlasType.find("mbtile") == 0:
        gen.generate_mbtile(atlas, name)
    else:
        assert (0)

    logger.info('ready')
    db.CloseDB()

    return