Select to view content in your preferred language

script does not work

2936
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
Can you post the entire script?  Be sure to enclose it with
 tags (the # symbol) to preserve indentation.
					
				
			
			
				
			
			
				
			
			
			
			
			
			
		
0 Kudos
GerniceMuhamed
Emerging Contributor
# Import system modules
import arcpy
from arcpy import env
import os, glob
# Set environment settings
arcpy.env.workspace = ("G:/Animals")

# Set local variables
outWorkspace = ("G:/Animals/Reproject_Out.gdb")

# Use ListFeatureClasses to generate a list of shapefiles in the
#  workspace shown above.
fcList = arcpy.ListFeatureClasses()
print fcList

# Set coordinate system only for those inputs which have a defined spatial reference
for infc in fcList:
# Determine if the input has a defined coordinate system
 desc = arcpy.Describe(Animals)
 sr = desc.spatialReference

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...."
                                   
# Print message to say the two fields are being added
    arcpy.AddMessage("Adding fields F_AREA and C_AREA, calculating field values...")

# Execute AddField twice for two new fields  
    arcpy.AddField_management(Animals, F_AREA, "LONG", "", fieldLength)
    arcpy.AddField_management(Animals, C_AREA, "LONG", "", fieldLength)
try:
# Set the current workspace (to avoid having to specify the full path to the feature classes each time)
    arcpy.env.workspace = outCS

# Process: Calculate Areas...
    arcpy.CalculateAreas_stats(outCS, outCS_output_area)
except:
# If an error occurred when running the tool, print out the error message.
    print arcpy.GetMessages()
import math
0 Kudos
GerniceMuhamed
Emerging Contributor
This is what I have so far...I have other script to write but need to get this working first.. So JSkinn3 can you please let me know what you see is wrong...I have tried to use the wrap around the code hope its is better...
0 Kudos
JakeSkinner
Esri Esteemed Contributor
When you are projecting the shapefile, I don't see where you assigned a coordinate system to the 'outCS' variable.

arcpy.Project_management(infc, outFeatureClass, outCS)
0 Kudos
GerniceMuhamed
Emerging Contributor
The shapefiles i have dont have any projection its unknown... i am setting it to 2 different projections wgs84 first then Cylindrical Equal Area. i am not sure how to do it but thought this below would reproject it...

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)
0 Kudos
EokNgo
by
Deactivated User
You'll probably need to define the projection first using arcpy.DefineProjection_management
http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//001700000077000000

Then re-project the data as you have now using the arcpy.Project_management tool.
0 Kudos
GerniceMuhamed
Emerging Contributor
So I dont have to use a script to project the data into WGS84?????? Do I remove the resFc....... part of the script and just have arcpy.Project_management tool?
0 Kudos
JakeSkinner
Esri Esteemed Contributor
You will need to first define the projection of the shapefile that has an Unknown coordinate system, and then reproject the shapefile to your desired coordinate system.  I highlighted in bold the areas I changed:

# Import system modules
import arcpy
from arcpy import env
import os, glob
# Set environment settings
arcpy.env.workspace = ("G:/Animals")

# Set local variables
outWorkspace = ("G:/Animals/Reproject_Out.gdb")

# Use ListFeatureClasses to generate a list of shapefiles in the
#  workspace shown above.
fcList = arcpy.ListFeatureClasses()
print fcList

# Set coordinate system only for those inputs which have a defined spatial reference
for infc in fcList:
# Determine if the input has a defined coordinate system
 desc = arcpy.Describe("Animals.shp")
 sr = desc.spatialReference

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")
0 Kudos
GerniceMuhamed
Emerging Contributor
ok thanx I will try it now
0 Kudos