1

What is preventing the script from identifying the spatial reference for the .tif files? It appears that the script below lists the fc first, then gives the false spatial reference to the subsequent .tif files in the list. Similarly, if there's a fc with an undefined spatial reference, the .tif files show "unknown".

enter image description here enter image description here

arcpy.env.workspace = in_workspace
feature_classes = arcpy.ListFeatureClasses()
for fc in feature_classes:
    spatial_ref = arcpy.Describe(fc).spatialReference
    if spatial_ref.name == "Unknown":
        arcpy.AddError("{0} has an unknown spatial reference".format(fc))
    else:
        arcpy.AddMessage("{0} : {1}".format(fc, spatial_ref.name))
rasters = arcpy.ListRasters("*", "TIF")
for raster in rasters:  
                arcpy.AddMessage("{0} : {1}".format(raster, spatial_ref.name))

1 Answer 1

3

You haven't queried the raster(s) to get the spatial reference, the spatial_ref variable is still set to the spatial reference of the last feature class.

Instead of this:

for raster in rasters:  
    arcpy.AddMessage("{0} : {1}".format(raster, spatial_ref.name))

Do this:

for raster in rasters:  
    spatial_ref = arcpy.Describe(raster).spatialReference
    arcpy.AddMessage("{0} : {1}".format(raster, spatial_ref.name))

Your Answer

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

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