#In this project you'll practice Python fundamentals by writing a script that #re-projects the vector datasets in a folder. From this script, you will then #create a script tool that can easily be shared with others. #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 telling 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. Notice #an example of this type of custom message below in the line "Projected . . . :" #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 # Import system modules import arcpy from arcpy import env #Set workspace env.workspace = "D:\WCGIS\Geog485\Lesson2" rootName = "" if fc.endswith(".shp"): rootName = fc[:-4] #To check if a dataset is already in the target projection, you will need to obtain a Spatial Reference object #for each dataset (the dataset to be projected and the target dataset). You will then need to compare the spatial #reference names of these two datasets. Be sure to compare the Name property of the spatial references; do not #compare the spatial reference objects themselves. This is because you can have two spatial reference objects that #are different entities (and are thus "not equal"), but have the same name property #You should end up with a line similar to this: if fcSR.Name != targetSR.Name: where fcSR is the spatial #reference of the feature class to be projected and targetSR is the target spatial reference obtained from #the target projection shapefile #If you want to show all the messages from each run of the Project tool, add the line: arcpy.AddMessage(arcpy.GetMessages()) #immediately after the line where you run the Project tool. #If you need extra help with making the script tool, refer back to Lesson 1.7.1 and also read Zandbergen 13.1 - 13.10 where #he goes in depth about making your own tools.
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question