⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 workspacetorasterdataset_mrsid.py

📁 实现大量栅格数据的加载操作,其中效率很快!
💻 PY
字号:
##""********************************************************************************************************************
##TOOL NAME: WorkspaceToRasterDataset_MrSid
##SOURCE NAME: WorkspaceToRasterDataset_MrSid.py
##VERSION: ArcGIS 9.0
##AUTHOR: Environmental Systems Research Institute Inc.
##REQUIRED ARGUMENTS: Input workspace
##                    Output raster dataset
##                    Include subdirectories
##OPTIONAL ARGUMENTS: Mosaic method (defaults to LAST)
##                    Color map mode
##                    Ignore background value
##                    Nodata value
##                    Convert one bit data to 8 bit data during mosaic?
##                    Tolerance    
##TOOL DESCRIPTION: Mosaic all MrSid rasters in the input workspace and subdirectories to the output raster dataset
##
##DATE: 01/05/2004
##Updated: 4/8/2005
##
##Usage: WorkspaceToRasterDataset_MrSid <Input_Directory> <Output_RasterDataset><Include_SubDirectories>[Mosaic_Method]
##                             [Color_Map_Mode][Ignore_Background_Value][Nodata_Value][Convert_1_to_8_bit][Tolerance]
##*********************************************************************************************************************"""

#Importing ScriptUtils which imports required librarys and creates the geoprocssing object
import  win32com.client, os, string
msgNonExist="does not exist: "
msgSuccess="Successfully mosaicked: "
msgFail="Failed to mosaic: "
msgNotGDB="Output location is not GDB type: "
msgDir="Failed to load directory"
gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1")

## The mosaic function mosaics all of the MrSID files in the input workspace to the output raster dataset. 

def mosaic(ws):
    try:
        gp.workspace = ws

        #The raster datasets in the input workspace which holds a list of MrSid image files.
        
        in_MrSID_list = gp.ListRasters("","SID")

        #Initialize the input list of MrSID files to the first raster.         
        
        in_MrSID = in_MrSID_list.next()

        #Loop through the array mosaicking each raster to the output workspace.

        while in_MrSID <> "":
            try:

                oIMG = in_MrSID
                oIMG = string.replace(oIMG,".sid",".img")
                oIMG = string.replace(oIMG,".SID",".img")
                
                #convert to IMG file
                gp.CopyRaster_management(in_MrSID,ws + os.sep + oIMG)

                gp.Mosaic_management(in_MrSID, out_dataset, mosaic_method,colormap,ignore_bg,nodata_value,one_to_8,tolerance)

                #remove the temporary IMG
                gp.Delete_management(oIMG)

                gp.AddMessage(msgSuccess + " %s " % (in_MrSID))

            except Exception, ErrorDesc:
            # Except block for the loop. If the tool fails to convert one of the MrSID, it will come into this block
            #  and add warnings to the messages, then proceed to attempt to convert the next input Raster.
                WarningMessage = (msgFail + " %s" %(ws + os.sep + in_MrSID))
                gp.AddWarning(WarningMessage)
            in_MrSID = in_MrSID_list.next()
        gp.AddMessage(msgSuccess + " %s " % (ws))
    except Exception, ErrorDesc:
        gp.AddWarning(msgFail + " %s " % (ws))
        
def pack_dir(indir):
    try:
        mosaic(indir)
        for sub_dir in os.listdir(indir):
            if os.path.isdir(indir + os.sep + sub_dir):
                curdir = indir + os.sep + sub_dir
                pack_dir(curdir)
    except Exception, ErrorDesc:
        gp.AddWarning(msgDir)

try:   
    #The input workspace
    workspace = gp.GetParameterAsText(0)

    #The output raster dataset
    out_dataset =  gp.GetParameterAsText(1)

    #Whether include subdirectories
    include_sub = gp.GetParameterAsText(2)

    #Optional mosaic method (defaults to LAST)
    mosaic_method = gp.GetParameterAsText(3)

    #Optional color map mode
    colormap = gp.GetParameterAsText(4)

    #Optional ignore background value

    ignore_bg = gp.GetParameterAsText(5)

    # Optional nodata value

    nodata_value = gp.GetParameterAsText(6)

    # Convert one bit data to 8 bit data during mosaic?

    one_8 = gp.GetParameterAsText(7)

    if one_8 == "true":
        one_to_8 = "OneBitTo8Bit"
    else:
        one_to_8 = "NONE"

    # Mosaicking tolerance    

    tolerance = gp.GetParameterAsText(8)

    # Derive dataset for model builder connectivity
    gp.SetParameterAsText(9,out_dataset)

    #Check existence
    if not gp.Exists(workspace):
        raise Exception, " %s" % (workspace) + msgNonExist

    # Check if output raster dataset exists
    if not gp.Exists(out_dataset):
        raise Exception," %s" % (out_dataset)+ msgNonExist

    if include_sub == "true":
        pack_dir(workspace)
    else:
        mosaic(workspace)
        
except Exception, ErrorDesc:
    # Except block if the tool could not run at all.
    #  For example, not all parameters are provided, or if the output path doesn't exist.
    gp.AddError(str(ErrorDesc))

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -