Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have a problem and maybe someone is able to help me or give me some hints how to start.

Situation: I have a lot of raster and of every raster I have the center coordinate. Out of this coordinate I build a shapefile to have the information about the approximate location of each raster. Now I included the path for each raster in the attribute table of the shapefile with the field calculator.

Problem: Some of the raster are exactly georeferenced with a word-file. I want to add a new attribute field to show if there is a georeference or not. For this I can use the following code (at the moment a input cursor is missing):

from arcpy import env

arcpy.env.overwriteOutput = 1

env.workspace = r'Z:\path'
path = env.workspace

# Create a table and add fields
table_name = "TempTable.dbf"
arcpy.CreateTable_management(path, table_name)
arcpy.AddField_management(path + "\\" + table_name, "RasterName", "TEXT")
arcpy.AddField_management(path + "\\" + table_name, "cs", "TEXT")

# Get the list of raster files
rasters = arcpy.ListRasters()

# Loop through the files and perform the processing
for ras in rasters:

    # Determine if the input has a defined coordinate system
    dsc = arcpy.GetRasterProperties_management(ras, "TOP")         

    if float(str(dsc.getOutput(0)).replace(",", ".")) > 100:

        row.cs = "y"     # Adds "x" to the row where the image has a georeference

    else:

        row.cs = "n"     # Adds "n" to the row where the image has no georeference

Now I do not know how to add the information in the right way to the attribute table (maybe a join?). I hope there is someone who is able to help me with this.

Thanks!

share|improve this question

2 Answers 2

When you already have the raster paths in your table, I would not iterate through the rasters, but iterate through your table entries with an update cursor. This way round you can call getRasterProperties for each Raster and then immediatly fill the attributes (row.cs="y" is already the right way to do that).

I have no python interpreter right now to check syntax and so on, but the code should look like this:

# Get the list of raster files
cur = arcpy.updateCursor(table_name)

# Loop through the files and perform the processing
for row in cur:

# Determine if the input has a defined coordinate system
dsc = arcpy.GetRasterProperties_management(row.RasterName, "TOP")         

if float(str(dsc.getOutput(0)).replace(",", ".")) > 100:

    row.cs = "y"     # Adds "x" to the row where the image has a georeference

else:

    row.cs = "n"     # Adds "n" to the row where the image has no georeference

Excuse me, if the code is not runnable immediately, perhaps there are some errors. Don't know if I can call GetRasterProperties that way for example.

share|improve this answer

You can use a Cursor to add the description info to the proper feature class record/field.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.