0

I have updated the script from my previous question;

Project only required shapefiles in folder

I can't get the if fcspatialRef != spatialRef: to work. The script won't filter the shapefiles in ArcGIS, any advice/suggestions?

import arcpy

# Set Workspace  
arcpy.env.workspace = arcpy.GetParameterAsText(0)

#Access shapefiles  
fcList = arcpy.ListFeatureClasses()

try:
# Projection template   
  template = arcpy.GetParameterAsText(1)  
# Output folder  
  outFolder = arcpy.GetParameterAsText(2)

# Get the spatial reference  
 spatialRef = arcpy.Describe(template).SpatialReference 

 #Loop through shapfiles in folder and reproject  
 for fc in fcList:  
    fcspatialRef = arcpy.Describe(fc).SpatialReference  
    if fcspatialRef != spatialRef:      
        arcpy.Project_management(fc, outFolder + "\\" + fc, spatialRef)

# Return any errors   
except:
    arcpy.AddMessage(arcpy.GetMessages ())

# Print shapefile list  
for fc in fcList:  
    print fc
6
  • 1
    What is your question? Why shouldn't this be closed as a duplicate?
    – Vince
    Apr 10 '15 at 13:21
  • Oh sorry, I cant get the if fcspatialRef != spatialRef: to work. The script won't filter the shapefiles in ArcGIS, any advice/suggestions?
    – Pete
    Apr 10 '15 at 13:23
  • Hi Pete, can you please update the question to be clearer as to what you're asking. If your question isn't clear, it's unlikely you'll get any useful answers. Apr 10 '15 at 13:25
  • Yes Vince, that's me from yesterday, but the script doesnt work in ArcGIS. The spatial reference isnt working. S_TssG was helping me.
    – Pete
    Apr 10 '15 at 13:28
  • Hi Pete, maybe you should consider registering as it would allow you to easily edit any previous questions with new information. And also because this is an awesome forum :)
    – Joseph
    Apr 10 '15 at 13:31
1

Using the spatial reference name method will likely work for you.

 # Get the spatial reference  
 spatialRef = arcpy.Describe(template).SpatialReference.name 

 #Loop through shapfiles in folder and reproject  
 for fc in fcList:  
    fcspatialRef = arcpy.Describe(fc).SpatialReference.name  
    if fcspatialRef != spatialRef:      
         arcpy.Project_management(fc, outFolder + "\\" + fc, spatialRef)

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