Wednesday, June 3, 2020

Geoprocessing

This week we started to apply our python knowledge within ArcGIS itself.  Using scripting can make doing actions much faster and less monotonous than doing everything manually.

In the first part of the lab, we used ArcPro's model builder to create a multistep process that outputs a shapefile.  With the model builder you can drag and drop files and tools and combine them to preform actions in a certain order.  For our lab we made a clipping of all the soils within the extent of a basin.  Then simultaneously used the select tool to pick out all the soils that were classified as "not prime farmland" with a SQL query.  Lastly, we used the generated not prime farmland shapefile to erase from the soils within the file clipped from the basin.  This created a final product where all the good farmland within the basin area remained.

For the second part of the lab, we shifted gears and used the Spyder IDE.  There were three primary goals of the program I wrote: assign XY coordinates to a hospitals shapefile, create a 1000m buffer around those hospitals, and create a dissolved 1000m buffer around the hospitals.  This entailed importing the arcpy module to the freshly created script.  Then I set the workspace environment and set it so it was possible to overwrite output files which made it much easier to re-run scripts over and over while tweaking them.

Adding the XY coordinates to the hospitals was a matter of just running the appropriate module with the correct shapefile fed into the parameter.  The buffers were somewhat more involved since they take more parameters.  The first buffer needed three parameters: the file to create the buffer around, the path of the output file, and the size of the buffer itself.  The dissolved buffer took and extra three parameters, two of which were left blank since they don't apply to this situation and the last one set to 'ALL' so that the buffers would dissolve.  A dissolved buffer is were any overlap between buffers is combined so that the outputted polygons and melded together.

Lastly, I used the GetMessages module with stated the start time of each procedure, if it was successful, and how long each method took.  This shows that the program ran correctly, though I also double checked in ArcPro itself.


The program that gave the hospitals shapefile XY coordinates and also created the buffer layers successfully running.
Overall, I thought scripting would be much more intimidating for someone with a minimal computer science background.  I see how even fairly straightforward applications of Python can make doing operations in ArcGIS much easier as well as faster and I look forward to learning more applications.

Monday, May 25, 2020

Python Debugging

This week's assignment was all about debugging.  Errors in programming are inevitable so it's important to learn how to begin to approach them while learning how to code.  We were provided with three different scripts and had to fix them so that they would all run correctly.
For this class most of our coding is done in Spyder.  When you run a script in Spyder, like all IDEs if it gets hung up on an error it will tell you with some kind of error message, like a traceback or syntax error.  Sometimes the easiest way to find a problem in your code is simply to run it and then see where the problem is.
Once mistakes such as misspellings or incorrect capitalization are cleared up then the program can run correctly. 
Another way to approach debugging is to use Spyder's debugger.  With this, you can work through the code line by line and see what is happening at each point.  This is a good way to identify an error where the code is running but not giving you the sort of output that you are expecting.

This script had eight bugs that needed to be teased out before it would properly run.

Sometimes, you might want to sidestep a bug entirely.  You can do this by adding in a "try" and except clause.  For this section of the assignment we had to identify that part of the code with an error and put it into a "try" clause.  This means that the code will be attempted, but if it cannot run it will turn to the except clause instead of simply breaking.  For the "except" clause I added in an error message that would identify what the problem was and print that out.  Afterwards, the code would continue as normal.
As you can see in Part A an error message is printed out from the "except" clause.  However, Part B runs without issue.


A Flowchart showing the try/except process


Bug fixing can be tedious but it's important to have different approaches to problem solving.  The more errors you fix, the easier it become to figure out other bugs in the future.

Monday, May 18, 2020

Python Fundamentals


The focus this week was getting down the basics of Python programming.  That means understanding variables and lists, using methods and functions, if-elif-else statements, for and while loops.

The first task was to make a string of my full name, then put each name into a list using the split function, then use string indexing to isolate just the last name.  Fairly straightforward, but it's a good way to make sure you have the basics down.

The next task was to fix two errors within a basic dice game.  I first tried to run the game to see where the code got hung up.  I then identified the problems (you can't concatenate an int to a string without first changing the type of the int, and a variable capitalization issue) and fixed them so that the code would properly run.

The final task this week was mastering loops.  First, I used a while loop to append 20 integers to an empty list.  When the list was complete the program printed the list.  Then I chose an integer that I wanted to remove from the list and assigned it to a variable.  I used the count method to check for the presence of this variable within the list in an if-else statement.  The statement would print out if the integer was in the list and how many times it was there.  Then I used a while that ran while the count of the chosen integer was greater than zero.  For each pass through the loop it removed one instance of the chosen integer.  Then the adjusted list was printed again.

Showing the results of the various basic processes covered in this lesson.
Flowchart for the luckyList section of the code.




Monday, May 11, 2020

Python Programming for GIS

This week is the start of another class - GIS programming.  Currently, the predominate scripting language for ArcGIS is Python which we will be using for this class.  Learning to program is useful as it helps to automate tasks and make routine functions much faster.

So far, we have been introduced to the concept of pseudocode which is the line-by-line process of thinking about what we want the code to do without writing it in standard Python syntax.  We also ran a Python script in the IDE Spyder which automatically generated a set of folders for out projects in the coming weeks.

The script-generated folders for the class.

Thursday, April 16, 2020

Google Earth and 3D Mapping

The final project for Cartography class was using Google Earth Pro and .kmz files.  The goal of this lab was to familiarize ourselves with presenting 3D depictions of data by creating a multi-city tour of Southern Florida.

We first had to convert our surface water date in ArcPro to a .kmz file so that it could be imported into Google Earth.  This is done with the "Layer to KML" tool.  Next, I launched Google Earth Pro and imported the required .kmz files.  I also placed a legend on the 3D map.

To create the tour itself, I had to locate the points of interest on the map and then create placemark points for each one.  Following that, I used the program's "record tour" feature to make a recording of each location.  This produces a video of each location that shows off the 3D cityscapes.

Google Earth Pro is fairly straightforward to use, though because of its large scale it can be taxing on a lower end computer when the map is zoomed out.  I think this technology could work particularly well for creating virtual tours of places - such as historic neighborhoods - where an audio narrative could accompany the video.

A dot density population map of Southern Florida presented in Google Earth Pro.  Various body of water are also colorized to make it more obvious that the population of Florida is centered near the coasts and away from marshy areas.


Saturday, April 11, 2020

Isarithmic Mapping

The focus of the lab this week was isarithmic mapping.  Isarithmic maps depict continuous phenomenon that occur across an area.  The process of interpolation makes it possible for an algorithm to generate data across an entire area even though there are only set locations gathering data..  This type of map is particular common for climatological data and is used in a number of industries such as agriculture and engineering.  

I created a map of the average annual precipitation rates in Washington state using a 30 year data set ranging from 1981-2010.  The interpolation method used on this data was the Parameter-elevation Relationships on Independent Slopes Model, also known as PRISM.  This method takes data from the weather stations and factors in environmental attributes such as elevation and proximity to the coast in order to generate a complete set of data.

To create this map I first map a hillshade effect layer using data from the annual precipitation raster.  This improves the look of the terrain by creating the appearance of depth.  Areas of high elevation tend to have higher rates of precipitation, so this is a logical feature to incorporate into this map.

The next step was to create hypsometric tints.  A hypsometric tint is a set of classed graduated colors useful for showing the range of a environmental phenomenon.  This used the spatial analyst tool "int" to process the annual precipitation raster.  I then symbolized the colors into proper classes that corresponded with precipitation amounts.

The last part of map creation was to create contours.  Contours are lines that show the discrete changes between value ranges.  This process involved the contours tool on the annual precipitation layer at the same values as were assigned for the hypometric tints.  This makes the divisions between the different classes even more obvious.

An isarithmic map of Washington state showing the average annual precipitation rates over 30 years.  The map utilizes hypometric tinting as well as contour lines to display the data.



Sunday, April 5, 2020

Choropleth Mapping

In this week's lab we continued to learn about making choropleth maps.  This week we also learned how to work with proportional and graduated symbols.  Choropleth maps are maps with shaded sections to convey the intensity of a phenomenon.  These maps must be normalized by area so when comparing different enumeration units you are making a comparison based off of density and not raw data. 

The goal for this week's lab was to create a map that showed the population density throughout Europe in a choropleth format as well as the consumption of wine per captia.  The map was primarily constructed in ArcGIS Pro with some editing in Adobe Illustrator. 

For the population density, I wrote a SQL exclusion to take the countries of Gibraltar, Jersey, Malta, and Monaco out for when classifying the breaks between populations.  This is because those countries are very small, and thus densely populated - making them outliers in the data.  I classed the remaining countries using the natural breaks method into four different classes.  This created a map with a good amount of contrast between countries. 

The wine consumption was shown through a set of graduated symbols with its associated country.  I decided to take on the extra challenge of using custom symbols for this section.  I downloaded a wine glass icon by Thengakola from the Noun Project.  I then edited this icon in illustrator so that it would have a different fill amount for each of the different classes of consumption.  Again I used natural breaks to divide up the data.  I classed the data into five separate groups to create a range of very low consumption to high consumption.

I used ArcGIS Pro's labeling and annotation feature to generate labels for each country.  Some countries are very small and do not consume significant quantities of wine so they have been omitted.  These include: Gibraltar, Guernsey, Isle of Man, Monaco, Jersey, and San Marino. 

In the final map, I created an inset for the countries near the Adriatic Sea.  This is because in the overview map the information in that area was crowded and difficult to read.  The inset allows for clearer interpretation of the data.

A comparison between the population densities of European countries and their per liter wine consumption.  The population density is shown with choropleth mapping and the wine consumption is showed with overlaid graduated wine glass symbols.
Overall, the take away from this map is that wine consumption correlates a lot with the cultural and agricultural practices of a country.  Vatican City beats all other European countries in wine consumption with a whopping 73.78 liters per person (if an average wine bottle is .75 liters, that's about 100 bottles a year!).  This is in large part to the all-Catholic population of the country that takes part in drinking wine for communion.  Appreciation of wine is also cultural as it is popular in France and Italy.  This is in part because they have a long tradition of growing grapes for wine and have the perfect climate and soil conditions for it.  Other countries may not prefer wine as much but that does not mean they are altogether dry.  Countries with low wine consumption tend to have foodways that put more emphasis on other forms of alcohol such as vodka in Russia and Lithuania.

The most challenging part of this map was placing the wine glass symbols and the country labels just so that it was obvious what they were in reference to without occluding anything else.  I now have great appreciation for cartographers who did this work in the pre-digital age.  As a bonus, I think I now have a much better sense of the geography of Europe too.