1

I am new to Python and am struggling with my code specifically with my loops.The project is supposed to abide by these rules:

  • Must re-project shapefile vector datasets in the folder to match the target dataset's projection.
  • Must append "_projected" to the end of each projected dataset name. For example: CityBoundaries_projected.shp.
  • Must skip projecting any datasets that are already in the target projection.
  • Must report a geoprocessing message of which datasets were projected. In this message, the dataset names can be separated by spaces. In the message, do not include datasets that were skipped because they were already in the target projection.
  • Must not contain any hard-coded values such as dataset names, path names, or projection names.
  • Must be made available as a script tool that can be easily run from ArcToolbox by someone with no knowledge of scripting.

I keep getting a this error:

OSError: "C/Users/jessi/Desktop/CPSUGeog485/Lesson2" does not exist

This is my code so far:

import arcpy
import os

#establish workspace
folderWorkspace = "C/Users/jessi/Desktop/CPSUGeog485/Lesson2"
targetFc = "C:/Users/jessi/Desktop/CPSUGeog485/Lesson2/Countylines.shp"
featureClass = ["CountyLines", "Ferries", "PopulatedPlaces", "CityBoundaries", "StateRoutes"]

#establish spatial reference of selected feature class 
targetDesc= arcpy.Describe(targetFc)
targetSr = targetDesc.SpatialReference
targetSrName = targetSr.Name

arcpy.env.workspace = folderWorkspace
fcList =  arcpy.ListFeatureClasses() 

# List current feature classes in folder
for fcCurrent in featureClass:
    fcCurrentDescribe = arcpy.Describe(folderWorkspace)
    fcCurrentSr = fcCurrentDescribe.SpatialReference
    fcCurrentSrName = fcCurrentSr.Name 
    
for fcCurrentSrName in fcCurrent: 
    if fcCurrentSrName != targetSr: 
        print ("Error Matching Spacial reference")
else: 
    print ("Spatial reference matching succesful")

for fcCurrentSrName in fcCurrent:
    if fcCurrentSrName == targetSrName:  
        continue
    
else:
    # Output feature class and projected name
    fcOut = os.path.splitext(fcCurrent)[0]
    arcpy.Project_management(fcCurrent, fcOut, targetSr)
    print (fcOut +"_projected.shp")```
2
  • Which line is causing the error
    – BERA
    Apr 15, 2021 at 6:35
  • Are you changing the workspace after listing some feature classes? That would cause arcpy not to find the fcs, if you havent prefixed the workspace to all list items.
    – BERA
    Apr 15, 2021 at 6:52

1 Answer 1

3

Try changing this line:

folderWorkspace = "C/Users/jessi/Desktop/CPSUGeog485/Lesson2"

To this:

folderWorkspace = "C:/Users/jessi/Desktop/CPSUGeog485/Lesson2"
0

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.