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

📄 workspacetorastercatalog_mrsid.py

📁 实现大量栅格数据的加载操作,其中效率很快!
💻 PY
字号:
##""********************************************************************************************************************
##TOOL NAME: WorkspaceToRasterCatalog_MrSid
##SOURCE NAME: WorkspaceToRasterCatalog_MrSid.py
##VERSION: ArcGIS 9.0
##AUTHOR: Environmental Systems Research Institute Inc.
##REQUIRED ARGUMENTS: Input workspace
##                    Output raster catalog
##                    Include subdirectories
##OPTIONAL ARGUMENT: Input spatial reference
##TOOL DESCRIPTION: Insert all MrSID image files in the input workspace and subdirectories to the output raster catalog
##--- Because the way MrSID file is compressed, it is more efficient to convert MrSID to IMG and then load to ArcSDE 
##DATE: 5/31/2004
##MODIFIED: 4/8/2005
##
##Usage: WorkspaceToRasterCatalog_MrSid <Input_Directory> <Output_RasterCatalog><Include_SubDirectories><Input_SpatialReference>
##*********************************************************************************************************************"""

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

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

        #The raster datasets in the input workspace
        in_MRSID_list = gp.ListRasters("","SID")

        #Loop through the array copying each featureclass to the output workspace
        in_MRSID = in_MRSID_list.next()

        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)

                #define spatial reference if specified
                if in_cs != "":
                    gp.DefineProjection_management(ws + os.sep + oIMG,in_cs)

                #insert to raster catalog
                gp.CopyRaster_management(oIMG, out_catalog)
                
                #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 Rasters, 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:
        insert(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 catalog
    out_catalog = gp.GetParameterAsText(1)

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

    in_cs = gp.GetParameterAsText(3)

    #Derive raster catalog for model builder connectivity
    gp.SetParameterAsText(4,out_catalog)
    
    #Check existence
    if not gp.Exists(workspace):
        raise Exception, " %s" % (workspace) + msgNonExist

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

    # If subdirectories are included call pack_dir to recusively traverse all subdirectories and insert
    # any MrSID files found. Otherwise just insert the MrSID files in the current workspace into the
    # output raster catalog.

    if include_sub=="true":
        pack_dir(workspace)
    else:
        insert(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 + -