5

I have a new question and I hope somebody can help me with this.

I have got a shapefile which shows the extent of every raster I have. Some of these rasters are georeferenced but some not. Now I would like to add a x to the attribute table where the raster is georeferenced. I know that there must be a way with python GetRasterProperties but I'm not sure how to write the script. Maybe someone of you did the same and can give me some help.

I have to do this with ArcGIS 10 and it must be easy to update when new rasters are georeferenced.

Gago-Silva
2,5562 gold badges29 silver badges48 bronze badges
asked Jan 7, 2013 at 16:50
1
  • 1
    Do the rasters that are not georeferenced lack any sort of spatial reference altogether? As in they are just images without any spatial reference yet? If so, you can use arpcy.Describe to check for a spatial reference, and if it returns null (or whatever the missing spatial reference return is), add an 'X' to a field. Commented Jan 7, 2013 at 16:54

1 Answer 1

4

I'm assuming you are georeferencing scanned maps or the like that do not have an associated coordinate system. The attached script creates a table and adds "x" to the row which corresponds to the undefined raster. You should have no problem retrofitting the script to perform the same action with your shapefile. The attached screenshot shows how the script looped through a folder, recorded the raster name and determined whether or not there was an assigned coordinate system.

enter image description here

import arcpy
from arcpy import env
arcpy.env.overwriteOutput = 1
# Set the workspace
env.workspace = r'C:\temp'
Dir = env.workspace
# Create a table and add fields
TableName = "TempTable.dbf"
arcpy.CreateTable_management(Dir, TableName)
arcpy.AddField_management(Dir + "\\" + TableName, "RasterName", "TEXT")
arcpy.AddField_management(Dir + "\\" + TableName, "cs", "TEXT")
# Get the list of raster files
rasters = arcpy.ListRasters()
# Loop through the files and perform the processing
for ras in rasters:
 # Create insert cursor and add values to the table
 rows = arcpy.InsertCursor(Dir + "\\" + TableName) 
 row = rows.newRow()
 row.RasterName = str(ras)
 # Determine if the input has a defined coordinate system
 dsc = arcpy.Describe(ras) 
 if dsc.spatialReference.Name == "Unknown":
 row.cs = "x" # Adds "x" to the row which corresponds to the undefined raster
 else:
 print str(ras) + " has a coordinate system"
 rows.insertRow(row) 
 del rows
 del row
answered Jan 7, 2013 at 17:43
1
  • More or less that is what I'm looking for. One problem is that my rasters are in subfolders so I have to loop through. But I will try it. Thanks! Commented Jan 8, 2013 at 11:08

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.