In this week's GIS Programming lab, we learned a lot about using Python to access the ArcMap tools.
This week was something of a watershed for me, because the help pages for the tools makes much more sense than it did before, and I am also more comfortable with the syntax of modules and functions, in their operation as toolboxes and tools. Python, as it works with ArcGIS, is falling into place.
In the figure above, the results are shown for the script this week: the messages for running the tools.
Our task was to first assign XY coordinates to a point shapefile, then buffer it, then dissolve the buffer using the Dissolve tool in Data Management.
The summary of my process for writing this script can be accessed at this link:.
Process Notes for Module 5
Labels
- 2014 (old) Programming
- Applications in GIS
- Cartographic Skills
- GIS
- GIS Internship
- GIS Programming 2015
- Remote Sensing
- Special Topics in GIS
Showing posts with label 2014 (old) Programming. Show all posts
Showing posts with label 2014 (old) Programming. Show all posts
Friday, June 20, 2014
Friday, June 13, 2014
GIS Programming Module 4 - Python Fundamentals Part 2
This week we learned more about Python scripting, especially conditional statements using IF and WHILE. We also did more with lists and started working with modules that must be imported into PythonWin.
The results of the scripting assignment are shown here. The first block is a virtual dice-rolling game that generates random numbers using the imported RANDOM module. We only had to correct a couple of errors in the existing script. In the second block, we generated a list of 20 random numbers, again using the RANDOM module, and a WHILE loop and a counting variable. Finally, in the last block, we took that list of random numbers and removed all instances of an "unlucky" number from it. For this, I used the remove method, inside a WHILE conditional loop, with IN and NOT IN operators.
In addition, I imported the SYS method to Python and used it to allow the user to enter their own unlucky number into the Run Script dialogue box before running the script.. This was discussed in chapter 4 of our text and is very straightforward and convenient way to get input from the user.
Here is a portion of my process in this lab:
The results of the scripting assignment are shown here. The first block is a virtual dice-rolling game that generates random numbers using the imported RANDOM module. We only had to correct a couple of errors in the existing script. In the second block, we generated a list of 20 random numbers, again using the RANDOM module, and a WHILE loop and a counting variable. Finally, in the last block, we took that list of random numbers and removed all instances of an "unlucky" number from it. For this, I used the remove method, inside a WHILE conditional loop, with IN and NOT IN operators.
In addition, I imported the SYS method to Python and used it to allow the user to enter their own unlucky number into the Run Script dialogue box before running the script.. This was discussed in chapter 4 of our text and is very straightforward and convenient way to get input from the user.
Here is a portion of my process in this lab:
Part 1,
Step 4: Removing numbers from the list. Explain how you created this block
of code.
1. I used in and not in within an if, else conditional structure to
determine if the unlucky number was there or not.
2. After the else, I used a new while loop
containing the remove method:
while unlucky in list:
list.remove (unlucky)
This ran the code until the in condition
no longer applied in the while loop.
Wednesday, June 11, 2014
GIS Participation Assignment # 1: How is GIS used in the real world?
For this assignment, I read about a very interesting
application of GIS Network Analysis, which could be expanded and applied to
many needs. As we learned in Intro to
GIS class, ArcMap Network Analysis is well-developed for use by all kinds of
motorists, and especially useful to emergency personnel such as EMT’s, the
police, and firefighters to plan the most efficient route among any number of
destinations or stops. While planning
out a route, it incorporates various forms of impedance to traffic flow, such as stop
signs, speed limits and one-way streets.
The authors of this article realized that people in
wheelchairs face impedance every day, in the form of stairs, rough pavement
and curbs, as they try to navigate around their cities. Their goal was to develop a mapping
application to help people in wheelchairs easily plan the best routes. The researchers manually digitized the
center-lines of sidewalks in the city of Northampton, UK, then incorporated
DEM's to obtain slope for separate segments of the routes. At this point, Event Tables were developed
from field work, which measured surface quality (starting and rolling
resistance), and the presence of any type of obstacle that might frustrate a
wheelchair user: steps, gutters, raised
manhole covers, fixed furniture, narrow sidewalks, and several more. This latter part of the field survey was
actually carried out in the company of disabled volunteers in wheelchairs, who
helped the researchers identify impediments.
The application was developed in ESRI’s ArcView (the
precursor to ArcGIS for Desktop Basic) and featured a user-friendly
interface. The routes were calculated by
considering impedance or “cost” with the network analysis environment as well
as user physical ability and type of wheelchair. Two modes of route selection were offered via
dialogue boxes: a single best route from one location to another, or all
wheelchair-suitable routes from a starting point.
The authors tested their map application with 18 wheelchair
users in that city and got very favorable reviews about its usefulness and
clarity.
This type of network analysis would be very useful in any
area where pedestrians need to navigate, especially tourists, for mapping
restaurants, bus stops, presence or absence of sidewalks, etc. These data can also be crowd-sourced,
for example, with OpenStreetMap, which
we read about in our Cartography class.
This article can be accessed at this link: Mapping for Wheelchair Users: Route Navigation in Urban Spaces .
Source: Beale, L., Field, K., Briggs, D., Picton, P., and Matthews, H. (2006). Mapping for Wheelchair Users: Route Navigation in Urban Spaces. The Cartographic Journal, Vol. 43 (No. 1), pp. 68–81.
Source: Beale, L., Field, K., Briggs, D., Picton, P., and Matthews, H. (2006). Mapping for Wheelchair Users: Route Navigation in Urban Spaces. The Cartographic Journal, Vol. 43 (No. 1), pp. 68–81.
(I have placed the PDF in my UWF I:\ drive because it was downloaded
from my local library’s EBSCO database, for which access is limited to local card
holders.)
Friday, June 6, 2014
GIS Programming Module 3 - Python Fundamentals Part 1
In this week's GIS Programming lab, we learned more about how to write scripts, and the nature of some of the data types in Python, such as numeric values, strings and lists. We learned the definitions of expressions, statements, functions, methods and objects. We practiced using methods and wrote a small script in which the input is our full name, in the form of a list. Running the script causes the last name only to be output, as well as the number of letters in the last name times 3.
My output is shown above. It consists of my last name, and the number of letters in it (5) times 3 (15).
In order to write this code, I utilized the split method, to separate the whole name string into separate names/strings in a list, then indexing to select the last name from the list, and the length function combined with a simple multiplication operator, to find the number of letters in the last name times 3. Print statements were also included in the script to show the last name and for the number of letters times 3.
My output is shown above. It consists of my last name, and the number of letters in it (5) times 3 (15).
In order to write this code, I utilized the split method, to separate the whole name string into separate names/strings in a list, then indexing to select the last name from the list, and the length function combined with a simple multiplication operator, to find the number of letters in the last name times 3. Print statements were also included in the script to show the last name and for the number of letters times 3.
Friday, May 30, 2014
GIS Programming Module 2 - Geoprocessing in ArcGIS
![]() |
| Polygon of suitable farmlands, created in ModelBuilder |
After the model was created in ModelBuilder, it was exported as a Python script and modified (by addition of full file paths to input data). The resulting script can be run in PythonWin, outside the ArcGIS environment, create the output layers, and store them in the appropriate Results folder, to be added to an ArcMap .mxd file at any time.
The steps involved in creating the output dataset of suitable farmlands in the basin are listed below:
1. First, define the task to be performed: Select the areas within the basin that have soils that area suitable for farming.
2. Procedure: Select the polygons from the Soils shapefile that are classified as “not prime farmland” and erase that selection from the Soils shapefile. Then, clip the resulting layer to the extent of the basin.
3. Add the Basin and Soils layers from the Data folder to the blank .mxd.
4. After creating a toolbox in the Module 2 folder, Rt.Click > New > Model.
5. In the ModelBuilder window: Model > Model Properties: Name and label the model, and provide a description of what it does: SoilErase, Soil Erase, and that it will remove the polygons from the Soils shapefile that are not prime farmland, and clip them to the basin layer extent.
6. Drag the Basin and Soils features from the Table of Contents into the Model Builder window
7. Open the Arc Toolbox window. Navigate to the Select tool (Analysis > Extract) and drag it into the modelbuilder window. Then, double click on the Select box.
8. Fill in the parameters for the select tool: Input: soils. Output: will be called soils_Select.shp.
9. The SQL expression for the selection is “FARMLNDCL” = ‘not prime farmland’ Click Okay.
10. The output element will appear with the output file name.
11. Drag the Erase tool (Analysis > Overlay) into the ModelBuilder window and double-click it.
12. Input: soils. Erase feature: soils_Select.shp. Output feature: soils_Erase.shp. Click Okay.
13. Drag the clip tool into the ModelBuilder window. Double click it.
14. Input: soils_Erase.shp. Clip feature: basin. Output: soils_Erase_Clip.shp. This is the final output. All elements are now in color which means they are ready; none are white. They contain the data and filepaths that they need. Original input data is blue, output is green, and tools are yellow.
15. Rt.Click on each of the input and output elements, including the final output, and click Model Parameter for each one. There are five in all (does not include tools).
16. Save the model at the top menu of the ModelBuilder window.
17. To run the model, click on the small blue triangle arrow on the right end of the main menu bar of the ModelBuilder window. The tool and output elements will have a gray drop-shadow once they have run successfully (the original input data elements will not).
18. After creating the model and script, I discovered how to use the Dissolve tool to aggregate the polygons within the Soils_Erase_Clip (Data Management Tools > Generalization > Dissolve). This tool was not included in the model or the script however.
| Model to create a suitable soils layer, using ArcGIS ModelBuilder |
Friday, May 23, 2014
GIS Programming Module 1 - Introducing Python
In the first week of GIS Programming, we were introduced to Python by running a script which created a folder structure for our coursework. We examined the script first, to get an idea of what it generally looks like. Other than practicing a couple of print commands in the Scripting Window, however,we are only running script at this point, not yet writing it.
On the left is an image of the folder structure that I created on my S:\ drive by running the Python script provided by our professor. The parent folder is called GISProgramming, and contains 12 subfolders, for modules 1-12 of this course. In turn, each of those folders contains three folders for Data, Scripts, and Results. Rather than take a long time creating these 36 subfolders by hand, we were able to run the Python script and have them all appear in less than a second. Once we can write script of our own, we'll be able to automate any number of tedious and time-consuming chores which might be much worse than this small task!
Here is my process summary of how I ran the script to create my folder structure:
On the left is an image of the folder structure that I created on my S:\ drive by running the Python script provided by our professor. The parent folder is called GISProgramming, and contains 12 subfolders, for modules 1-12 of this course. In turn, each of those folders contains three folders for Data, Scripts, and Results. Rather than take a long time creating these 36 subfolders by hand, we were able to run the Python script and have them all appear in less than a second. Once we can write script of our own, we'll be able to automate any number of tedious and time-consuming chores which might be much worse than this small task!
Here is my process summary of how I ran the script to create my folder structure:
Running the script in PythonWin
1.
This script, CreateModuleFolders.py, will create a folder called GISProgramming,
with subfolders, within the main S:\ drive.
There is no need to create any other folder before running the script.
2.
First, copy the script CreateModuleFolders.py from the R:\ repository drive into the
student S:\ drive. (I have a subfolder
gds but I put the script at that same level,in the main S:\ drive.)
3.
Go to the S:\ drive and Rt.Click the CreateModuleFolders.py
file.
4.
Select Edit
with PythonWin.
5.
A window for PythonWin will come up, with the
script window open within it.
6.
Two ways to run the script: 1) Ctrl-R; 2) click on the runner icon at the top of the
PythonWin window. The script can be
double-clicked from where it’s stored, as well.
7.
A little confirmation dialog box comes up. Click on the Run button without changing anything.
8.
The folder structure of S:\GISProgramming is created, with its 12 Module subfolders. Each subfolder in turn has 3 empty folders in
which to store Data, Results and Scripts from the 12 modules of this class.
Thursday, May 15, 2014
Introduction: GIS Programming
Hi, I am Gail Sease. This is the first post for the GIS Programming course, Summer Session in GIS, 2014.
Subscribe to:
Posts (Atom)
