Processing math: 100%

2 votos

¿Cambiar el nombre de los rásteres en el directorio basándose en el valor del campo de la clase de característica del centroide en ArcGIS Desktop?

Tengo un montón de rásters con nombres como r001.tif, r002.tif y así sucesivamente.

Hay un shapefile de puntos con los centroides de estos rasters y su nombre real en la tabla de atributos.

Estoy buscando una manera o alguna herramienta/modelo para renombrar estos rásteres de acuerdo a su nombre real en la característica de punto centroide?

1voto

Aaron Puntos 25882

Hay un tutorial aquí que te guiará por el proceso paso a paso. Si no utiliza Python, puede traducir el flujo de trabajo del tutorial a un modelo en ArcMap.

# Author: John Speargas
# Import module
import os

# Input folder containing files to be renamed
folder = “C:\\GIS\\TEST\\directory_to_be_renamed\\”

# Input lookup table
lookupTable = open(folder + “LookupTable.txt”)

# Read lookup table and close file
tableList = lookupTable.readlines()
lookupTable.close()

# Input fields corresponding to the old and new names
old = “OLD”
new = “NEW”

# Read the lines in the table and strip away unnecessary characters
newTable = []
for line in tableList:
    newLine = line.strip()   
    newerLine = newLine.strip(“,”)  
    newestLine = newerLine.strip(“‘”)   
    almostFinalLine = newestLine.replace(‘”‘,”")  
    finalLine = almostFinalLine.split(“,”)
    newTable.append(finalLine)

# Get position of old and new field names
header = newTable[0]
indexOld = header.index(old) – 1
indexNew = header.index(new) – 1

# Make lists corresponding the new and old values
oldList = []
newList = []
for item in newTable:
    if item != newTable[0]:
        valueOld = item[indexOld]
        valueNew = item[indexNew]
        oldList.append(valueOld)
        newList.append(valueNew)

# For each file in the folder, parse the old name from (the path
# and-?) the extension
for file in os.listdir(folder):
    nameAndExt = os.path.splitext(file)
    oldName = nameAndExt[0]
    extension = nameAndExt[1]

#   Index the old name in the old list if it is present
    if oldName in oldList:
        indexOldName = oldList.index(oldName)

#       Locate the same index in the “new” list
        newName = newList[indexOldName]

#       Rename the file using the path, the new name, and the extension
        os.rename(folder + oldName + extension, folder + newName + extension)

i-Ciencias.com

I-Ciencias es una comunidad de estudiantes y amantes de la ciencia en la que puedes resolver tus problemas y dudas.
Puedes consultar las preguntas de otros usuarios, hacer tus propias preguntas o resolver las de los demás.

Powered by:

X