The goal of these labs was to introduce python scripting functions, learn how it can be utilized in ArcGIS, and gain some knowledge in how python works.
Background
Python scripting is an invaluable tool in the ArcGIS world if you want to perform higher ability functions in the program. Every tool present in the ArcToolbox is scripted using python code and can be drawn upon for use in the python script within Arc. Our labs goal was to learn and perform python scripting for several purposes. Python can also be used across several other softwares as an acceptable form of scripting language.
Scripts
The first script that our class learned was how to add xy coordinate to ArcGIS, convert the coordinate system to UTM_Zone_16N, and then to convert the map units. This is all present in the script below:
#Cody Kroening
#GEOG 337
#Import arcpy
import.arcpy
#Input feature class from GCS_WGS_1984 to UTM_NAD_1983_ZONE_16N
# Replaces a layer or table name with a path to a dataset or create the layer or table view within the script
arcpy.Project_management("XYdata","W:/geog/CHupy/geog337_f13/KROENICJ/EX1.gbd/Script1.py", "PROJCS['NAD_1983_UTM_Zone_16N',GEOGCS['GCS_North_American_1983',DATUM['D_North_American_1983', SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Transverse_Mercator'],PARAMETER['False_Easting',500000.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',-87.0],PARAMETER['Scale_Factor',0.9996],PARAMETER['Latitude_Of_Origin',0.0],UNIT['Meter',1.0]]","WGS_1984_(ITRF00)_To_NAD_1983","GEOGCS['GCS_WGS_1984', DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]]")
#Adds XY coordinates to the input feature class
arcpy.AddXY_management("XYdataProject1")
The second script that I created was tasked with creating buffers that followed airport parameters as seen below. It also creates a distance buffer from the airport.
#Cody Kroening
#Geog 337: GIS 2
# Import arcpy module
import arcpy
# Local variables:
airports_shp = "W:\\geog\\CHupy\\geog337_f13\\KROENICJ\\Ex7\\Results\\airports.shp"
seaplaneairports_shp = "W:\\geog\\CHupy\\geog337_f13\\KROENICJ\\Ex7\\Results\\seaplaneairports.shp"
seabasebuffer_shp = "W:\\geog\\CHupy\\geog337_f13\\KROENICJ\\Ex7\\Results\\seabasebuffer.shp"
airportsselect_shp = "W:\\geog\\CHupy\\geog337_f13\\KROENICJ\\Ex7\\Results\\airportsselect.shp"
airportsbuffer_shp = "W:\\geog\\CHupy\\geog337_f13\\KROENICJ\\Ex7\\Results\\airportsbuffer.shp"
# Process: Select
arcpy.Select_analysis(airports_shp, seaplaneairports_shp, "\"FEATURE\" = 'Seaplane Base'")
# Process: Buffer
arcpy.Buffer_analysis(seaplaneairports_shp, seabasebuffer_shp, "7500 Meters", "FULL", "ROUND", "NONE", "")
# Process: Select (2)
arcpy.Select_analysis(airports_shp, airportsselect_shp, "\"FEATURE\" = 'Airport'")
# Process: Buffer (2)
arcpy.Buffer_analysis(airportsselect_shp, airportsbuffer_shp, "15000 Meters", "FULL", "ROUND", "NONE", "")
Script 3: The final script below was created to print stream names and along with the type of feature class.
#Cody Kroening
#Geog 337: GIS 2
# Import arcpy module
import arcpy
#Print stream name and feature class type
from arcpy import env
env.workspace="W:/geog/CHupy/geog337_f13/KROENICJ/Ex6/Results/NM.gdb"fclist=arcpy.ListFeatureClasses("*")
for fc in fclist:
fcdescribe = arcpy.Describe(fc)
print fcdescribe.name + " is a " + fcdescribe.dataType
Python scripting is a very valuable tool in order to peform higher level functioning and abilities in ArcGIS. It allows for the processing of multiple tools at one as long as you understand the scripting and its capabilities. Python not only allows you to create your own tools and to publish them, but is designed into the tools that we use everyday in the GIS community. It also allows users to create paramters for tools where a generic tool may not reach your specific needs. In conclusion, python scripting is an essential language to learn in higher level geospatial analysis in order for the user to be ahead of the game.
Note: I don't know how to revert the background color of the text to normal, so I'm sorry for the odd configuration.
Sources
Zandbergen, Paul A. January 9, 2013. "Python Scripting for ArcGIS." California: ESRI Press.
No comments:
Post a Comment