Hollinger Week 2

Chapter 3:

Reading Notes:

  • I don’t think that I have ever searched for a tool using the analysis gallery. I usually always go straight to the geoprocessing pane, which seems more robust anyway.
  • Built-in tools: Built using ArcObjects and compiled in PL like C++.
  • Script Tools: Python Scripts are accessible from the dialog box.
  • Model Tools: Created using model builder
  • System vs. Custom Tools
  • Current vs. Scratch workplace: Current specifies where inputs and outputs are placed and Scratch is used for intermediate data in model and script tools.
  • Environments can be set for the application, the individual tool, the properties of a model, or a script.
  • Data Connectors, Environment Connectors, Pre-Condition Connectors; and Feedback Connectors
  • You can schedule a script to be run at a certain time. 

Answers to Review Questions:

  • The geoprocessing framework includes toolsets and toolboxes, the ability to search and run tools, environment settings, and parameters, dialog boxes for controlling and executing tools, ModelBuilder (a point + click visual programming language for sequence tools), a Python window, geoprocessing history and lots, and methods for creating python scripts.
  • The three types of tools are built-in tools, script tools, and model tools. 
  • System tools are installed as a part of the ArcGIS Pro Software and created by ESRI. Most system tools are built-in, but some are scripts. Custom tools are created by a user or obtained by a 3rd party and usually consist of script and model tools.
  • Different environments include: Workspace defines the path of where your datasets are located and where your inputs are and outputs will be. There are also settings for specific data types and functions as well.
  • The limitations of batch processing are that filling out the tool can take some time and the tool does not execute faster than normal. However, the strengths are that once you have populated the batch tool it can run multiple times without user input which can be nice for repetition of a task (for example, clipping multiple layers to the same extent). 
  • Dynamic naming allows you to create a unique name for each output layer in batch processing. %Name% is used to take the first part of a layer name and create the output name. Without this step, the file would be continually overwritten. The same process could be done for a path and other output elements. 
  • ModelBuilder requires no programming experience and has little syntax. Scripting has some functionality for lower-level tasks and more advanced programming logic that Model Builder does not. Scripting can also be used to combine applications and can stand alone outside of ArcGIS Pro. The two are similar because there are many geoprocessing workflows that work in both ModelBuilder and Scripting.
  • You may choose a script workflow instead of a model for a lower-level task or a more advanced function/extension with additional packages that can only be done in scripting. Additionally, scripting allows for the use of other software like Excel or R as well. Then finally, as mentioned above, scripts can be run and stand-alone outside of ArcGIS Pro. 
  • I am honestly not 100% sure if this is what this question is asking, but to automate workflows you can run Python code in ArcGIS’s Python editor or use an external editor like IDLE or PyCharm.

Chapter 4:

Reading Notes:

  • Immutable vs. mutable
  • I have never used a tuple before so I looked it up. It’s basically a list but you cannot edit its contents. 
  • The most important statements in a programming language are statements that assign values to variables.
  • Every object has a value, a unique identifier, and a type.
  • Methods are functions coupled to an object like: <object>.<method>(<arguments>)
  • F-strings example: f”The temperature is {temp} degrees”
  • Pairs are also referred to as items in the dictionary
  • Set is another datatype to organize elements. It is an unordered collection without duplicates and the elements are enclosed with curly braces. Elements of a set must be immutable.
  • input() function gets user input

Answers to Review Questions:

  • The main data types are strings, integers, float, and Boolean. Lists, tuples, and dictionaries are more complex data types. Strings, lists, and tuples are sequences. Strings, numbers, and tuples are immutable because you can replace them with new values, but not modify them. Lists and dictionaries are mutable.
  • True division is a floating point division where the result of division is reported as a decimal even if the numerator and denominator are integers. In floor division you use the // symbol and the division is truncated to zero decimal points, except for with negative numbers where the result is rounded up (really down) to the nearest whole number. 
  • Dynamic assignment of the variable means that the type of your variable will be automatically inferred based on whatever values you assign to it. 
  • variable_name1 and variablename2 would be examples of good variable names because they consist of only letters, digits, and underscores and they don’t include Python keywords or variable names. In a real scenario, these should also be more descriptive of what the variable represents like count or my_raster.
  • An expression comes from literal values using operators and functions, but a statement is an instruction that tells the computer to do something. 
  • Quotation marks are used to denote something as a string in Python. Double and single quotation marks can be used interchangeably. 
  • Unicode strings are strings stored in characters of the Unicode system which is designed to represent every character from every language. Because of this, you can work with many different languages in Python. 
  • Five built-in Python functions — #1: print(x) would print the contents of the variable x. #2: id(x) would return the unique identifier of the variable x. #3: type(x) would return the object type of the variable x. #4: abs(x) would return the absolute value of the numeric variable x. #5: round (x, n) would round the float variable x off to n number of digits.
  • Dot notion may look something like this <object>.<method>(<arguments>) and it is when the object is written before the period with the method following. It shows that whatever is after the period belongs to the object before the period. 
  • Forward indexing will assign elements an index from first to last starting with 0. Reverse indexing will assign elements an index from last to first starting with -1.
  • Three methods of string objects — #1: join() method given a list of elements will join them into a single string. #2: strip() method will remove any of the given characters in the argument from the string no matter what order they are in. #3: replace() method will replace one substring with another everywhere it occurs.
  • Lists and Tuples are generally the same except that you can modify a list while tuples are immutable and the sequence and elements cannot be modified.
  • A Boolean is used to evaluate if an expression is either true or false. 
  • To create a dictionary you would populate it as follows: dictionaryname = { “Key” : ”Value”, “Key2” : “Value2”, “Key3” : “Value3” } You could also create an empty dictionary by not putting anything in the brackets. To add an element you would do as follows: dictionaryname[“Key4”] = “Value4”.
  • You should avoid backslashes because they are used as an escape character in Python. 
  • Branching is kind of like a chose-your-adventure situation in the sense that you just need to decide to take one path or another. Typically this means using if statements. 
  • A compound statement is a block that contains multiple statements and statements that determine when other statements will be executed like if, for, while, try, and with.
  • Two main loop structures: A while looping structure runs the other statements within the block while the argument given in the while statement evaluates true. Then there is a for loop which typically runs for the duration of a sequence. 
  • You can use a backslash as a line continuation, or (), [], and {} as an implied line continuation to improve readability for long lines of code. 
  • Comments provide information and descriptions about your script that can help you remember and others understand why the script was created.

Chapter 5:

Reading Notes:

  • ArcPy is organized into modules, functions, and classes
  • Workspace is your default location for files and can be set in a script
  • Good practice not to add extra spaces
  • Quotation marks are always straight in Python
  • Parameters have a name, type, direction, and required value
  • Non-tool functions are available only in ArcPy
  • Environments are set as properties of the env class
  • All functions have a reference/help page that includes sample code, syntax, and explanations of each parameter.

Answers to Review Questions:

  • Geoprocessing tools in ArcGIS Pro can all be accessed through ArcPy. To reference a tool its tool name is often the same as the tool label in ArcGIS Pro without spaces. To reference a tool you would also need to include its toolbox alias.
  • Required parameters must be specified for a tool to run. Optional parameters are just as they sound, optional, and are usually indicated in documentation by curly brackets. This affects script writing because parameters must be specified in the order listed in the tool documentation. You can specify the name of a parameter or fill its spot with “” or # when not defining all of the optional parameters. 
  • An example of using variables instead of hard-coded values as parameters would be: arcpy.Clip_analysis(input_file, clip_file, output_file).
  • The result object can be used as input for another function as it may contain the path to a dataset, it may also return a string, number, or Boolean values. The result objects will also include messages and parameters based on the tool run. 
  • Classes are used as input parameters as a shortcut that would often be much more complicated. This helps in scenarios where parameters cannot be defined by just a simple string like coordinate systems for example. 
  • To reference a coordinate system you can use arcpy.Describe(), arcpy.da.Describe(), use the name of the coordinate system (ex: arcpy.SpatialReference(“NAD 1983 StatePlane Texas Central FIPS                             4203 (US Feet)”), or using the factory code/well-known id (ex: arcpy.SpatialReference(2277)). 
  • Some typical environments set in a script are the workspace (ex: arcpy.env.workspace = “C:/Data”), the cell size (ex: arcpy.env.cellSize = 30), and allowing overwriting (ex: arcpy.env.overwriteOutput = True). 
  • You can obtain a meaningful message by using arcpy.GetMessages(), which is typically the most useful and will give you a list of messages. arcpy.GetMessageCount() will allow you to obtain the number of total messages and can be useful for viewing the last message. Finally, arcpy.GetMaxSeverity() will return a severity level indicating an information, warning, or error message. 
  • ArcGIS Pro is licensed with a Named User license, a Single Use license, and a Concurrent Use license. Available products may vary based on the user account. Scripts will not run and extensions using ArcPy cannot be checked out if no license is available.

Hollinger Week 1

Chapter 1: 

Quick Answers to Review Questions: 

  • #1: It is a general purpose language, free and open source, and works cross-platform (but this doesn’t typically matter for ArcGIS runs only on Windows).
  • #2: It means that Python does not need compilation in binary before running. 
  • #3: Scripting is automating functionality in another program, while programming focuses more on the development of applications. 
  • #4:  ArcGIS Pro uses Python 3. The current version at the time this book was written was Python 3.9.18.
  • #5: Investing time and effort into learning Python is important because while it can take time to write scripts, in the end they can be used for repetitive tasks, or adjusted and reused for multiple projects, so automating some of your workflow saves time in the long run! Python also has a lot of other application so it’s a very transferable skill beyond ArcGIS.
  • #6 The main goal of developing scripts for ArcGIS Pro is to automate a task that would typically need to be done manually. 

Chapter 2:

Quick Answers to Review Questions:

  • #1: Integrated Development Environment
  • #2:  Python is an interpreted language because when you enter commands they are interpreted and then carried out.
  • #3: IDLE
  • #4: Primarily IDLE and PyCharm in this book, but Microsoft Visual Studio and Eclipse are widely used for Python generally as well.
  • #5: Syntax will always be the same for all editors, but there will be differences in how scripts are created, organized, and tested. IDLE is good for beginners and simpler scripts, but PyCharm has more functionality. PyCharm can handle multiple versions and environments, while IDLE needs a different version for each Python version and environment. 
  • #6:  IDLE is installed by default with every Python installation and PyCharm needs to be installed by you. To access and configure IDLE if you have ArcGIS Pro on your computer all you have to do is navigate to a script, right-click, and hit “Edit with IDLE (ArcGIS Pro)” and it will automatically use the active ArcGIS Pro environment. PyCharm is a bit more complicated. Simply put — you need to Open a New Project and then set a Custom Environment (selecting conda and arcgispro-py3) when starting a new project. You can also set the interpreter for new projects going forward and change it for an existing project.

No questions from me this week! I have used PyCharm, IDLE, and Python before so this was all a good refresher!

Applications I Googled: 

One of the applications I found was a python GIS flood tool. It uses “commonly available topographic data and commercial geographic information system” to make flood vulnerability mapping more accessible to communities where it might otherwise not be! 

This is the example map they gave:

Source: https://www.usgs.gov/software/python-gis-flood-tool-pygft 

This next one isn’t necessarily python related, but they used ArcGIS to simulate a Zombie outbreak, which way zombies would travel, and model where they would go next. They didn’t explicitly mention Python, but I have used Python and ArcPy for one of the methods they used (Buffer Analysis) so I’m sure it could be incorporated for further Zombie prediction in this area and beyond! 

Source: https://www.esri.com/about/newsroom/arcuser/the-undead-liven-up-the-classroom/