7

How would I automate the Define Projection tool so that I can just enter my layer each time?

I have it as a script in toolbox, but I am unsure how to set it so I can just input my layer as GetParameterAsText

Here is the script. I want to replace the "forest.shp" with a layer of my own choosing each time

 # set local variables
 inDataset = "forest.shp"
 coordinateSystem ="GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]]"
arcpy.DefineProjection_management(inDataset, coordinateSystem)
PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Oct 26, 2011 at 14:52
1
  • 2
    You could make the input to your tool a Model Parameter. Upon running the tool, it will ask for you input just like when you run it from the Toolbox. Do you know the you can run it as a "batch" as well by right clicking on the Define Projection tool. Commented Oct 26, 2011 at 15:25

2 Answers 2

10

You can do it in python by adding

inDataset = arcpy.GetParameterAsText(0)

here is that example.

Understanding_script_tool_parameters

Then add as a script tool. Adding_a_script_tool

Or just set the model param as MLowry suggested. That is probably quicker and easier.

user
1,3474 gold badges18 silver badges28 bronze badges
answered Oct 26, 2011 at 15:49
4

your .py file must be :

import arcpy 
try:
 coordinateSystem ="GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]]"
 fc = arcpy.GetParameterAsText(0) #your featureclass file
 dessr = arcpy.Describe(fc)
 srr = dessr.spatialReference
 arcpy.AddMessage("Your previous projection: %s" % (srr))
 arcpy.DefineProjection_management(fc, coordinateSystem)
 arcpy.AddMessage("Your process finished...")
except:
 arcpy.AddMessage("Cant trasformed new projection")

and then follow theJones direction....

answered Oct 26, 2011 at 16:36

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.