As well as creating Raster,
Geocoding, Spatial Analysis and Interoperability data for the Trempealeau
county data I was also tasked with creating python scripts which we would
utilize in order to make our own selective tools. In order to do this I had to
use the different sources that were available to me in the form of python. Arc
GIS has an integrated python coding system with arcmap 10.2 which was very innovative
and functional while the python script that is available to use on the
University of Wisconsin lab computers is the Win Python coding system, this is
a free to use python scripting software that is open source which can allow a
multitude of options. The differences between the two are minor but significant
at the same time.
I found that the integrated python
scripting system that is in ArcGIS is more user friendly and allows the coding
to be seen almost instantaneous. This also allowed me to mess around with the
tools that are in Arc Map at the same time to see how they will be affected by
my script. When I would code in the Arc Map python script help options would
appear that would help with my understanding of the code I was scripting. In
the Win Python application I could pull a window up to create a script and run
later, this allowed for a free flow of coding that could be edited on the fly
and saved in order to create tools. Using both of these python coding scripts I
was able to create the three basic scripts that would create tools that were
beneficial to Arc GIS.
This script actually runs a Euclidean
distance tool. in the scrip if the extension is available it will run a
EucDistance tool on the bike route and create a cell size of 100, it will then
save this distance in my folder as a new layer that I can use.
import arcpy
... from arcpy import env
... env.workspace = "H:/Documents/Esripress/Python/Data/Exercise05”
... if arcpy.CheckExtension
("spatial")=="Available":
... arcpy.CheckOutExtension("spatial")
... out_distance =
arcpy.sa.EucDistance ("bike_routes.shp", cell_size = 100)
...
out_distance.save("H:/Documents/Esripress/Python/Data/Exercise05/Results/bike_dist")
... arcpy.CheckInExtension("spatial")
# I left the below part out, if I tried to include it in the
python script it would only return with Syntax Errors
>>>...
else:
... print
"spatial analyst license is not available."
This next script that I created
was a great undertaking as my coding was only in html before and that was
during high school. So I was pretty rusty, however using the integrated python
script in Arc Map I was able to create a code that would take a coordinate
notation and that was incorrect and then project a correct coordinate system.
In this case it took the Michigan coordinate system
"Random_mi_project1" and converted it to the correct notation using
the code arcpy.convertcoordinatenotation_management I then told it to project
the coordinate system into UTM zoning, thus creating a correct coordinate
notation.
Final Script to convert to UTM
#This is telling python to import arc python into the
script. it is also setting the environment workspace
Import arcpy
from arcpy import env
Env.Workspace=”W:/geog/CHupy/geog337_f13/Kerraj/ex.#1”
#This is the code that is creating the new coordinate
notation, it is switiching the notation from the incorrect notation into the
correct UTM coordinates
arcpy.ConvertCoordinateNotation_management("random_mi_project1","H:/documents/arcgis/default.gdb/randomconvertutm",
"POINT_X","POINT_Y","DD_2","UTM_ZONES","","")
# This is the final result that can be found
<Result
'H:\\documents\\ArcGIS\\Default.gdb\\randomconvertutm'>
This code allows me to print both
the field class of a feature class as well as the shapes that they represent.
To do this I used the append feature that allowed me to enter my own messages
to the counties, polygons, and points. I marked Railroads, Counties and Cities
as points, Lines, and Polygons that when told to print would print the name and
type of shape file it is. I also used the field list to print the fields that
they represent. This code is helpful to know because it lists all the feature
classes that are as points, lines, and polygons. for example if I was curious
to know what the points are I could use this script to find out that the points
are cities. I can then use other codes to print out a list of the cities in the
form of points and change the titles. I can also go and my own points and
feature classes using this script, for example I could say
points=["cities.shp","towns.shp"] and the points will be
written that towns and cities are points.
import arcpy
from arcpy import env
env.Workspace= "H:/documents/esripress/python/data/exercise06"
# fclist is the feature class list, what I am telling python
to do is to create a list of feature classes based on the list of
"fclist"
fclist= arcpy.ListFeatureClasses()
print fclist
Lines= ["Railroads.shp"]
Polygons= ["Counties.shp"]
Points=["Cities.shp"]
Points.append("Are all point feature classes")
Lines.append("Are all line feature classes")
Polygons.append("Are all polygon feature classes")
print Points
print Lines
print Polygons
fieldlist= arcpy.ListFields("Railroads.shp")
fieldlist= arcpy.ListFields("Counties.shp")
fieldlist= arcpy.ListFields("Cities.shp"]
for field in fieldlist:
print field.name +
""+ field.type
This
code allows me to create a feature point class that only allows the points to
exist that only have the attribute of having Sea Plane Bases inside the
attribute table. This allows me to select points based on attribute table data,
for example, Sea Plane Bases. I can then use this code to create a buffer
around the sea plane bases to create a buffered base, in this case I took the
sea plane bases and created a buffer of 7500 meters from the buffer_analysis
script tool.
import arcpy
from arcpy import env
env.workspace= "H:/documents/esripress/python/data/exercise07"
import arcpy
from arcpy import env
env.workspace= "H:/documents/esripress/python/data/exercise07"
infc= "airports.shp"
outfc= "results/airports_seabases.shp"
delimitedfield= arcpy.AddFieldDelimiters(infc,
"FEATURE")
arcpy.Select_analysis(infc, outfc, delimitedfield+ " = 'Seaplane
Base'")
fc= "airports_Seabases.shp"
unique_name= arcpy.CreateUniqueName("Results/seaplanebuffer.shp")
arcpy.Buffer_analysis(fc, unique_name, "7500
METERS")
fc= "airports.shp"
unique_name= arcpy.CreateUniqueName("Results/buffer.shp")
arcpy.Buffer_analysis(fc, unique_name, "15000
METERS")
No comments:
Post a Comment