コード例 #1
0
ファイル: s3_tiles.py プロジェクト: rumicuna/3d-forge
def main():
    try:
        opts, args = getopt.getopt(sys.argv[1:], 'p:', ['p='])
    except getopt.GetoptError as err:
        error(str(err), 2, usage=usage)

    prefix = None
    for o, a in opts:
        if o in ('-p', '--prefix'):
            prefix = a

    if len(args) < 1:
        error('you must specify a command', 3, usage=usage)

    s3Keys = S3Keys(prefix)

    command = args[0]
    if command == 'delete':
        s3Keys.delete()
    elif command == 'list':
        s3Keys.listKeys()
    elif command == 'count':
        s3Keys.count()
    else:
        error("unknown command '%(command)s'" % {'command': command}, 4, usage=usage)
コード例 #2
0
ファイル: s3_tiles.py プロジェクト: andyprasetya/3d-forge
def main():
    try:
        opts, args = getopt.getopt(sys.argv[1:], 'p:', ['p='])
    except getopt.GetoptError as err:
        error(str(err), 2, usage=usage)

    prefix = None
    for o, a in opts:
        if o in ('-p', '--prefix'):
            prefix = a

    if len(args) < 1:
        error('you must specify a command', 3, usage=usage)

    bucketBasePath = tmsConfig.get('General', 'bucketpath')
    s3Keys = S3Keys(prefix, bucketBasePath)

    command = args[0]
    if command == 'delete':
        s3Keys.delete()
    elif command == 'list':
        s3Keys.listKeys()
    elif command == 'count':
        s3Keys.count()
    else:
        error("unknown command '%(command)s'" % {'command': command},
              4,
              usage=usage)
コード例 #3
0
def main():
    try:
        opts, args = getopt.getopt(sys.argv[1:], 'c:', ['config='])
    except getopt.GetoptError as err:
        error(str(err), 2, usage=usage)

    dbConfigFile = 'configs/terrain/database.cfg'
    tmsConfigFile = 'configs/terrain/tms.cfg'
    for o, a in opts:
        if o in ('-d', '--database'):
            dbConfigFile = a
        elif o in ('-c', '--config'):
            tmsConfigFile = a

    if not os.path.exists(dbConfigFile) and os.path.exists(tmsConfigFile):
        error('config file(s) does/do not exist(s)', 1, usage=usage)

    if len(args) < 1:
        error('you must specify a command', 3, usage=usage)
    tiler = TilerManager(dbConfigFile, tmsConfigFile)

    command = args[0]
    if command == 'create':
        tiler.create()
    elif command == 'metadata':
        tiler.metadata()
    elif command == 'stats':
        tiler.stats()
    elif command == 'statsnodb':
        tiler.statsNoDb()
    # aws queue specific functions
    elif command == 'createqueue':
        tiler.createQueue()
    elif command == 'createtiles':
        tiler.createTiles()
    elif command == 'deletequeue':
        tiler.deleteQueue()
    elif command == 'queuestats':
        tiler.queueStats()
    else:
        error("unknown command '%(command)s'" % {'command': command},
              4,
              usage=usage)
コード例 #4
0
ファイル: tms_writer.py プロジェクト: escribano/3d-forge
def main():
    try:
        opts, args = getopt.getopt(sys.argv[1:], 'c:', ['config='])
    except getopt.GetoptError as err:
        error(str(err), 2, usage=usage)

    dbConfigFile = 'configs/terrain/database.cfg'
    tmsConfigFile = 'configs/terrain/tms.cfg'
    for o, a in opts:
        if o in ('-d', '--database'):
            dbConfigFile = a
        elif o in ('-c', '--config'):
            tmsConfigFile = a

    if not os.path.exists(dbConfigFile) and os.path.exists(tmsConfigFile):
        error('config file(s) does/do not exist(s)', 1, usage=usage)

    if len(args) < 1:
        error('you must specify a command', 3, usage=usage)
    tiler = TilerManager(dbConfigFile, tmsConfigFile)

    command = args[0]
    if command == 'create':
        tiler.create()
    elif command == 'metadata':
        tiler.metadata()
    elif command == 'stats':
        tiler.stats()
    elif command == 'statsnodb':
        tiler.statsNoDb()
    # aws queue specific functions
    elif command == 'createqueue':
        tiler.createQueue()
    elif command == 'createtiles':
        tiler.createTiles()
    elif command == 'deletequeue':
        tiler.deleteQueue()
    elif command == 'queuestats':
        tiler.queueStats()
    else:
        error("unknown command '%(command)s'" % {
            'command': command}, 4, usage=usage
        )
コード例 #5
0
def main():
    try:
        opts, args = getopt.getopt(sys.argv[1:], 'c:', ['config='])
    except getopt.GetoptError as err:
        error(str(err), 2, usage=usage)

    dbConfigFile = 'configs/terrain/database.cfg'
    for o, a in opts:
        if o in ('-c', '--config'):
            dbConfigFile = a

    if len(args) < 1:
        error('you must specify a command', 3, usage=usage)

    db = DB(dbConfigFile)

    command = args[0]
    if command == 'console':
        db.console()
    elif command == 'create':
        db.create()
    elif command == 'createuser':
        db.createUser()
    elif command == 'createdb':
        db.createDB()
    elif command == 'setupfunctions':
        db.setupFunctions()
    elif command == 'populate':
        db.populate()
    elif command == 'populatelakes':
        db.populateLakes()
    elif command == 'dropuser':
        db.dropUser()
    elif command == 'dropdb':
        db.dropDatabase()
    elif command == 'destroy':
        db.destroy()
    else:
        error("unknown command '%(command)s'" % {'command': command},
              4,
              usage=usage)
コード例 #6
0
ファイル: db_management.py プロジェクト: escribano/3d-forge
def main():
    try:
        opts, args = getopt.getopt(sys.argv[1:], 'c:', ['config='])
    except getopt.GetoptError as err:
        error(str(err), 2, usage=usage)

    dbConfigFile = 'configs/terrain/database.cfg'
    for o, a in opts:
        if o in ('-c', '--config'):
            dbConfigFile = a

    if len(args) < 1:
        error('you must specify a command', 3, usage=usage)

    db = DB(dbConfigFile)

    command = args[0]
    if command == 'console':
        db.console()
    elif command == 'create':
        db.create()
    elif command == 'createuser':
        db.createUser()
    elif command == 'createdb':
        db.createDB()
    elif command == 'setupfunctions':
        db.setupFunctions()
    elif command == 'populate':
        db.populate()
    elif command == 'populatelakes':
        db.populateLakes()
    elif command == 'dropuser':
        db.dropUser()
    elif command == 'dropdb':
        db.dropDatabase()
    elif command == 'destroy':
        db.destroy()
    else:
        error("unknown command '%(command)s'" % {'command': command}, 4, usage=usage)
コード例 #7
0
def main():
    try:
        opts, args = getopt.getopt(sys.argv[1:], 'f:t:', ['from=', 'to='])
    except getopt.GetoptError as err:
        error(str(err), 2, usage=usage)

    ffrom = None
    to = None
    ffile = None

    for o, a in opts:
        if o in ('-f', '--from'):
            ffrom = a
        if o in ('-t', '--to'):
            to = a

    if ffrom is None or to is None:
        if len(args) != 1:
            error("Please specify a file.", 4, usage=usage)
        ffile = args[0]

    tiles = []

    # We have file, so we get the tiles from the file
    if ffile is not None:
        with open(ffile) as f:
            for line in f:
                line = line.rstrip()
                if len(line) > 2:
                    tiles.append(map(int, line.split('/')))

    # If we have from to, we catch layers.json from poc and use from to for levels
    if ffrom is not None and to is not None:
        req = urlopen(poc_base_url + 'layer.json')
        layers = {}
        for line in req:
            layers = json.loads(line)
        for zoom in range(int(ffrom), int(to) + 1):
            level = layers['available'][zoom][0]
            for x in range(int(level['startX']), int(level['endX']) + 1):
                for y in range(int(level['startY']), int(level['endY']) + 1):
                    tiles.append([zoom, x, y])

    bucket = getBucket()
    g = GlobalGeodetic(tmscompatible=True)
    if not os.path.isdir('tmp'):
        os.mkdir('tmp')
    for tile in tiles:
        req = None
        tilebounds = g.TileBounds(tile[1], tile[2], tile[0])
        tilestring = str(tile[0]) + "/" + str(tile[1]) + "/" + str(tile[2])
        try:
            url = poc_base_url + tilestring + ".terrain?v=2.0.0"
            req = urlopen(url)
            with open(gzip_file_name, 'wb') as fp:
                fp.write(req.read())
            ff = gzip.open(gzip_file_name)
            with open(temp_file_name, 'wb') as fp:
                fp.write(ff.read())

            ter = TerrainTile()
            ter.fromFile(
                temp_file_name, tilebounds[0],
                tilebounds[2], tilebounds[1], tilebounds[3]
            )
            '''
            if os.path.isfile(tms_file_name):
                os.remove(tms_file_name)

            if os.path.isfile(shape_file_name):
                os.remove(shape_file_name)

            if os.path.isfile(tms_from_shape_file_name):
                os.remove(tms_from_shape_file_name)

            ter.toFile(tms_file_name)
            ter.toShapefile(shape_file_name)

            shapefile = ShpToGDALFeatures(shpFilePath=shape_file_name)
            features = shapefile.__read__()
            topology = TerrainTopology(features=features)
            topology.fromGDALFeatures()

            terFromPoc = TerrainTile()
            terFromPoc.fromFile(
                tms_file_name, tilebounds[0], tilebounds[2], tilebounds[1], tilebounds[3]
            )

            terFromShape = TerrainTile()
            terFromShape.fromTerrainTopology(topology)
            terFromShape.toFile(tms_from_shape_file_name)

            # Use this to select what is written to s3
            ter2 = terFromShape
            '''
            ter2 = ter

            fileObject = ter2.toStringIO()
            compressedFile = gzipFileObject(fileObject)

            bucketKey = tilestring + '.terrain'
            print 'Uploading %s to S3' % bucketKey
            writeToS3(bucket, bucketKey, compressedFile, 'POC Tiles copy',
                contentType=ter.getContentType())

        except Exception as e:
            print "error with " + line + " " + str(e)
        finally:
            if req:
                req.close()
    return 0