Exemplo n.º 1
0
def warpElevation(datasetDir):
    "Warp elevation file to match landcover file."
    layerIDs = [ name for name in os.listdir(datasetDir) if os.path.isdir(os.path.join(datasetDir, name)) ]
    for layerID in layerIDs:
        (pType, iType, mType, cType) = decodeLayerID(layerID)
        dataname = os.path.join(datasetDir, layerID, "%s.%s" % (layerID, iType))
        if (pType == "elevation"):
            elevationimage = dataname
        elif (pType == "landcover"):
            landcoverimage = dataname
        else:
            print "Product type %s not yet supported!" % pType
            return -1
    if (elevationimage == ""):
        print "Elevation image not found!"
        return -1
    if (landcoverimage == ""):
        print "Landcover image not found!"
        return -1

    elevationimageorig = "%s-orig" % elevationimage
    os.rename(elevationimage, elevationimageorig)
    warpFile(elevationimageorig, elevationimage, landcoverimage)
Exemplo n.º 2
0
def extractFiles(datasetDir):
    "Extracts image files and merges as necessary."

    layerIDs = [ name for name in os.listdir(datasetDir) if os.path.isdir(os.path.join(datasetDir, name)) ]
    for layerID in layerIDs:
        (pType, iType, mType, cType) = decodeLayerID(layerID)
        filesuffix = cType.lower()
        layersubdir = os.path.join(datasetDir, layerID)
        compfiles = [ name for name in os.listdir(layersubdir) if (os.path.isfile(os.path.join(layersubdir, name)) and name.endswith(filesuffix)) ]
        for compfile in compfiles:
            (compbase, compext) = os.path.splitext(compfile)
            fullfile = os.path.join(layersubdir, compfile)
            datasubdir = os.path.join(layersubdir, compbase)
            compimage = os.path.join(compbase, "%s.%s" % (compbase, iType))
            if os.path.exists(datasubdir):
                shutil.rmtree(datasubdir)
            os.makedirs(datasubdir)
            if (zipfileBroken == False):
                if (cType == "TGZ"):
                    cFile = tarfile.open(fullfile)
                elif (cType == "ZIP"):
                    cFile = zipfile.ZipFile(fullfile)
                cFile.extract(compimage, layersubdir)
                cFile.close()
            else:
                if (cType == "TGZ"):
                    cFile = tarfile.open(fullfile)
                    cFile.extract(compimage, layersubdir)
                elif (cType == "ZIP"):
                    omfgcompimage = "\\".join([compbase, "%s.%s" % (compbase, iType)])
                    os.mkdir(os.path.dirname(os.path.join(datasubdir,compimage)))
                    cFile = zipfile.ZipFile(fullfile)
                    cFile.extract(omfgcompimage, datasubdir)
                    os.rename(os.path.join(datasubdir,omfgcompimage),os.path.join(layersubdir,compimage))
                cFile.close()
        os.system("cd %s && gdalbuildvrt -resolution highest %s.vrt */*.%s && gdal_translate %s.vrt %s.%s" % (layersubdir, layerID, iType, layerID, layerID, iType))