TransWikia.com

Renaming 1,200 rasters in File Geodatabase using ArcPy

Geographic Information Systems Asked by John C. King on April 18, 2021

I’ve been tasked with renaming a large amount of raster files within a file geodatabase (ArcGIS style).

I’m taking weather data which has a name format as such: “G”mmddhhhh
I’m trying to add a year tag in between the G and month: “G”yyyymmddhhhh

Here is the function that I’ve written:

# ----------------------------------------------------------------------------- #
@timeit
def renameRasters(FGDB):
    origdir = arcpy.env.workspace
    arcpy.env.workspace = FGDB

    for rstr in arcpy.ListRasters("G*"):
        try:
            newrstr = "G" + "2014" + rstr.replace("g", "")
            arcpy.Rename_management(rstr, newrstr)

        except:
            print "Failed to rename: " + rstr

    arcpy.env.workspace = origdir
    return None
# ----------------------------------------------------------------------------- #

This function works fine for a small to medium amount of rasters within a FGDB and takes about 1.5 seconds per raster renamed. I run into issues when there are a large number of files to be renamed. 1,200 files takes > 10 hours. At the same rate as the smaller raster sets this should take < 1 hour…

Does anyone have an idea on how to make this process go faster?

If not I’ll set it up to run over the weekend.

I should mention that I am using ArcGIS 10.2.2.

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP