Showing posts with label GIS Programming GIS4102. Show all posts
Showing posts with label GIS Programming GIS4102. Show all posts

Thursday, July 31, 2014

GIS Programming Module 10 - Creating Tools

This week's work was to create a toolbox and script tool in ArcGIS so as to leverage an existing script via the ArcGIS UI. The script was modified such that parameters were sent to it via a dialogue window in ArcGIS and to send any messages that had been directed to StdOut to the ArcGIS results window instead. The end result is a script tool that can be used easily within ArcGIS by users without any familiarity with scripting for ArcGIS and which is also easy to share with users on other systems.

Input dialogue window generated by the script tool

Results window showing output from the script

Friday, July 25, 2014

GIS Programming Module 9 - Debugging

This week involved debugging code. Error ridden code was provided. Syntax errors and logic errors were discovered and cleaned up. Code then ran. Exception statements were also used to allow code to complete an execution without breaking out in the middle.

Script executes successfully

Script executes successfully

Script encounters an error, prints an error, then continues to execute successfully

Friday, July 18, 2014

GIS Programming Module 8 - Rasters

This week involved manipulating raster files, including performing map algebra via python. The output below took two separate rasters - one displaying land cover and the other elevation - of the same region and transformed the data therein to create a new raster. From the land cover raster, three types of forest were identified and reclassified into a single class and extracted. From the elevation raster, slope and aspect manipulated such that a desired range for both were identified as '1' while all other pixels were assigned '0'. The final raster output, below, is the result of a union of all the data transformations using boolean algebra to generate it.

Forest Cover with desired slope & aspect in yellow

Wednesday, July 2, 2014

GIS Programming Module 7 - Working with Geometries.

This week's script used a cursor object to run through all the rows of a shapefile, collecting their OID, their geometry and a NAME field. These were used to print out the data from the shapefile into a clear text file. The resulting file displayed a row for each point of each feature in the shapefile in a space delimited format. The fields in the text file were:

  • Object ID number
  • A vertice number, as counted up from zero for each feature
  • The vertice/point's X coordinate
  • The vertice/point's Y coordinate
  • The NAME field

Screenshot of resulting text file

Saturday, June 28, 2014

Manipulating Spatial Data (GIS Programming Module 6)

This assignment involved using the arcpy module in Python to access spatial datasets in order to find and manipulate the data within. The script whose output is shown below creates a new file geodatabase, populates it with shapefiles from an extant data directory and then creates a dictionary that holds population values using city names as keys, specifically cities that possess the 'County Seat' attribute from the FEATURE column in the attribute table for the 'cities' feature class.

script output 01

script output 2

Friday, June 20, 2014

Geoprocessing in Python

This week's script called up functions from the Python arcpy module for geoprocessing tools from ArcGIS. The scripting was straightforward. A point vector shapefile had had processed to add XY coordinates to features, then each feature was given a 1000 meter buffer, then the buffered features were dissolved to form a single feature.

From the completed process summary:

1. Added the import call and environment settings (workspace & overwrite = true)

2. Confirmed parameters and syntax for the three geoprocessing functions in the ArcMap python window

3. Created variables for shapefile inputs and outputs

4. Wrote up the calls for the three geoprocessing functions one at a time, printing the results via the GetMessages() function each time. Ran code after each function call was written.

5. Added comments as I went.

Geoprocessing messages were directed to stdout:

Thursday, June 12, 2014

Python Fundamentals II

This week's assignment involved debugging some code provided and then extending it with some directives designed to provide practice with using conditionals and loops. The first part of the output below (names listed as winning and losing) was provided with some bugs in the code to prevent it from running. These were found and fixed. The second part of the assignment involved generating a list of 20 random integers that ranged from 0 to 10, printing the result and then pruning a single integer from the generated list. The list was generated from a simple while loop (as per instructions) that appended a new random number to the list for each iteration. The break state for the loop was when a variable incremented each time reached the value of 20. Python's list functionality made manipulating the list quite easy and only took two lines of code to remove all instances of a particular integer.

Code output

Friday, June 6, 2014

Python Fundamentals I

This week's assignment involved writing a simple script that assigned my full name to a string and then manipulated it in various ways. The output from the script was to be my last name and the number of letters in my last name, tripled. This was a basic introduction to various data types, data structures, functions and methods.

The screenshot below shows the script output from running the script four times, including two times with a different name assigned as the initial string.

Script Output

Thursday, May 29, 2014

Setting up a basic ArcGIS model and converting it into a script.

This assignment was fairly basic. A simple geoprocessing operation was constructed using the ArcGIS Model Builder, which was then exported to a standalone python script.

The process took shapefile with soil data and clipped it to encompass just the area of a small basin defined in a separate shapefile. The clipped layer was then run through the selection tool to identify poor soils via an entry in the attribute table and then the selected features of the layer were erased using the erase tool. The result is the layer depicted below.

Only the best soils.

Thursday, May 22, 2014

Brief Introduction to Python Interfaces

This week's assignment for GIS Programming was simply to access various Windows based ways to code in Python (which ESRI has adopted and integrated deeply into their ArcGIS environment). This included the default installation of IDLE for Python, PythonWin and the Python IDE environment that's a part of ArcGIS 10. After issuing print commands in various ways - via the IDE CLI, via *.py script, etc. - a script was run out of PythonWin that set up a standardized directory hierarchy for future modules, the results of which are depicted below. The only other deliverable was a barebones process summary.

Screenshot.