1

This seems like to should be an easy thing to do, but I can't seem to make it work.

arcpy.env.workspace = arcpy.GetParameterAsText(0)  
output_working = arcpy.GetParameterAsText(1)  
PLSS_Intersected = arcpy.GetParameterAsText(2)  
spatial_ref = arcpy.GetParameterAsText(3)  

outCS = arcpy.SpatialReference("spatial_ref")  
outfc = os.path.join(output_working, "PLSS_Intersected")  
arcpy.Project_management(PLSS_Intersected, outfc, outCS) 

EDIT:

How is the error massage that I receive. The very top is what prints out when I printed outCS.enter image description here

  • "spatial_ref" is a string, but spatial_ref is a variable holding a string. – phloem Dec 13 '16 at 23:14
  • One issue is you are providing the string 'spatial_ref' to arcpy.SpatialReference rather than the value you have assigned to spatial_ref via arcpy.GetParameterAsText(3) – GeoSharp Dec 13 '16 at 23:14
  • How do I correct this? Rather, how do I call the value instead of calling the variable holding the value? – sd1272 Dec 13 '16 at 23:16
  • outCS = arcpy.SpatialReference(spatial_ref). This uses the variable, not a string that happens to be the variable name. – GeoSharp Dec 13 '16 at 23:19
  • I think it will be worth using print outCS after you get that 4th parameter as text so that you (and we) can see what a test value is that you enter. – PolyGeo Dec 13 '16 at 23:25
6

Although the comments have identified the immediate problem (that you are using the string literal, "spatial_ref", rather than the variable, spatial_ref), you may find it easier to change the input parameter to data type = Spatial Reference, and use the spatial reference object itself, rather than converting the spatial reference to string and back to a spatial reference object.

arcpy.env.workspace = arcpy.GetParameterAsText(0)  
output_working = arcpy.GetParameterAsText(1)  
PLSS_Intersected = arcpy.GetParameterAsText(2)  
spatial_ref = arcpy.GetParameter(3)  # get spatial reference object

outfc = os.path.join(output_working, "PLSS_Intersected")  
arcpy.Project_management(PLSS_Intersected, outfc, spatial_ref) # set spatial reference to the object

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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