Python is the programming language used by ArcGIS that allows for additional operations and tools to be used. An experienced Python user can perform advanced techniques of analysis that would not be possible without this training. Because of this, it is extremely useful to have at least some experience using Python.
Goal
Our objective was to get an introduction to using Python by writing several basic scripts for simple functions in ArcGIS. These are the three scripts that we did finish during the course of the semester.
For each script, I include a screenshot from PyWin and also text so that the script can be copied.
Figure 1 - Clip script |
The first script was a simple clip tool (figure 1).
import arcpy
arcpy.env.workspace = W:/geog/CHupy/geog337_f13/HAASTA/Exercise02
arcpy.Clip_analysis("lakes.shp", "basin.shp", "Results/lakes_myClip.shp")
Figure 2 - List of features |
(point, line, polygon).
import arcpy
from arcpy import env
env.workspace = "W:\geog\CHupy\geog337_f13\HAASTA\Exercise_Data\Exercise07"
fclist = arcpy.ListFeatureClasses ()
for fc in fclist:
fcdescribe = arcpy.Describe (fc)
print fcdescribe.name + " is a " + fcdescribe.shapeType + " feature class "
Figure 3 - Airport buffers |
import arcpy
from arcpy import env
env.workspace = "W:\geog\CHupy\geog337_f13\HAASTA\Exercise_Data\Exercise07"
fc = "Results/airports.shp"
airport = "Challenge/airport_selection.shp"
seaplane = "Challenge/seaplane_selection.shp"
where_clause = '"FEATURE" = \'Airport\''
arcpy.Select_analysis (fc, airport, where_clause)
where_clause = '"FEATURE" = \'Seaplane Base\''
arcpy.Select_analysis (fc, seaplane, where_clause)
airportBuffer = "Challenge/airport_buffer.shp"
seaplaneBuffer = "Challenge/seaplane_buffer.shp"
arcpy.Buffer_analysis (airport, airportBuffer, "15000 METERS")
arcpy.Buffer_analysis (seaplane, seaplaneBuffer, "7500 METERS")
Conclusion
Python is a very helpful, though tough to learn, tool. Having no background at all in programming languages, I struggled somewhat when doing these exercises. Also, it was at the beginning of the semester that I wrote these, so I apologize for not being able to elaborate more on each individual script. I simply didn't document the process well enough at the time. However, I did find that I enjoyed working with Python and I realized that it can be an incredibly helpful tool in the right hands. I would very much like to continue my education in this area, as it will compliment the other GIS skills I have learned this semester very well.
No comments:
Post a Comment