Select to view content in your preferred language

script does not work

2937
23
12-30-2011 04:06 AM
GerniceMuhamed
Emerging Contributor
Hi can some please assist me in reprojecting shapefiles. I want to reproject it in Geographic Coordinate System WGS 1984 and then into the Projected Coordinate System ???World_Cylindrical_Equal_Area..My script does not work..keeps telling me that there is an invalid syntax..When it reaches the resFC i get that invalid syntax at the line

This is what i have

if sr.Name == "Unknown":
# skip
     continue
else:
# Determine the new output feature class path and name
    outFeatureClass = os.path.join(outWorkspace, infc.strip(".shp")
# Set output coordinate system
resFc = outFeatureClass + "," + ("<install directory>/Coordinate Systems/Projected Coordinate Systems/WGS 1984.prj/Cylindrical Equal Area (world).prj")
                arcpy.Project_management(infc, outFeatureClass, outCS)
                arcpy.AddMessage("The shapefiiles have been reprojected")
                print "Get Area Info...."
Tags (2)
0 Kudos
23 Replies
JakeSkinner
Esri Esteemed Contributor
One other change you should make.  Change the following line:

desc = arcpy.Describe("Animals.shp")


to

desc = arcpy.Describe(infc)
0 Kudos
GerniceMuhamed
Emerging Contributor
Now its telling me continue is not properly looped
0 Kudos
JakeSkinner
Esri Esteemed Contributor
You will not have to use 'continue'.  You should have your functions under the 'if' statement (since you want to project all shapefiles with an Unknown coordinate system), and 'pass' under your 'else' statement.  Pass will skip the shapefiles that have a coordinate system defined:

if sr.name == "Unknown":
# Determine the new output feature class path and name
    outFeatureClass = os.path.join(outWorkspace, infc.strip(".shp"))
# Set output coordinate system
    outCS = "Coordinate Systems\Geographic Coordinate Systems\World\WGS 1984.prj"
    outCS2 = "Coordinate Systems\Projected Coordinate Systems\World\Cylindrical Equal Area (world).prj"
    arcpy.DefineProjection_management(infc, outCS)
    arcpy.Project_management(infc, outFeatureClass, outCS2)
    arcpy.AddMessage("The shapefiiles have been reprojected")
    print "Get Area Info...."
else:
    pass
0 Kudos
JakeSkinner
Esri Esteemed Contributor
You will not need to use 'continue'.

if sr.name == "Unknown":
# Determine the new output feature class path and name
    outFeatureClass = os.path.join(outWorkspace, infc.strip(".shp"))
# Set output coordinate system
    outCS = "Coordinate Systems\Geographic Coordinate Systems\World\WGS 1984.prj"
    outCS2 = "Coordinate Systems\Projected Coordinate Systems\World\Cylindrical Equal Area (world).prj"
    arcpy.DefineProjection_management(infc, outCS)
    arcpy.Project_management(infc, outFeatureClass, outCS2)
    arcpy.AddMessage("The shapefiiles have been reprojected")
    print "Get Area Info...."
0 Kudos
GerniceMuhamed
Emerging Contributor
I got another problem...got this error if sr.Name == "Unknown":
NameError: name 'sr' is not defined...sr = desc.spatialReference...Doesn't this define it...
0 Kudos
JakeSkinner
Esri Esteemed Contributor
The arcpy module is case-sensitive.  You will need to change it to sr.name.  If you copy and paste the code I uploaded into Pythonwin, it should run successfully.  I don't believe I changed any of the paths.
0 Kudos
GerniceMuhamed
Emerging Contributor
I copied it and still got an invalid syntax error at outCS...I guess i am bad lucky..cause i get an error every time i correct something
0 Kudos
JakeSkinner
Esri Esteemed Contributor
Not sure why the copy/paste did not work.  You were receiving your initial error because you were missing a parentheses at the end of the following line:

outFeatureClass = os.path.join(outWorkspace, infc.strip(".shp")


Should be:

outFeatureClass = os.path.join(outWorkspace, infc.strip(".shp"))
0 Kudos
GerniceMuhamed
Emerging Contributor
I got it to not give an error..thanx much JSkinn3...Much appreciated
0 Kudos
GerniceMuhamed
Emerging Contributor
This is what my script did...[]...Did you get this?
0 Kudos