Upgrade to Pro — share decks privately, control downloads, hide ads and more …

GEOG 315, GIS Programming, Fall 2020; Lecture 5

alan.kasprak
September 25, 2020

GEOG 315, GIS Programming, Fall 2020; Lecture 5

alan.kasprak

September 25, 2020
Tweet

More Decks by alan.kasprak

Other Decks in Education

Transcript

  1. For Today…I can’t teach you what Jupyter can 1. Some

    housekeeping 2. What is ArcPy? 2a. Important ArcPy Considerations: Environments 2b. Important ArcPy Considerations: File Paths 2c. Important ArcPy Considerations: Geodatabases GEOG 315: GIS Programming and Web Mapping Lecture 5 – Arc and Python, together at last
  2. Some Items to Review… First and foremost, you’re all crushing

    this (even if you don’t think you are) You’ve gone from zero to code in a month (in a class that meets once a week) The remainder of the class will deal with maps, not code syntax.
  3. Some Items to Review… First and foremost, you’re all crushing

    this (even if you don’t think you are) You’ve gone from zero to code in a month (in a class that meets once a week) The remainder of the class will deal with maps, not code syntax.
  4. Some Items to Review… Second: please, please, please, please, don’t

    wait until the last minute to do this week’s assignments (or really, any week’s assignments) It’s not necessarily that the assignment is super long. There’s just a lot of room for errors, and the concepts are new, so I want to make sure you have time to ask questions.
  5. For Today…I can’t teach you what Jupyter can 1. Some

    housekeeping 2. What is ArcPy? 2a. Important ArcPy Considerations: Environments 2b. Important ArcPy Considerations: File Paths 2c. Important ArcPy Considerations: Geodatabases GEOG 315: GIS Programming and Web Mapping Lecture 5 – Arc and Python, together at last
  6. What is ArcPy? “ArcPy is a Python site package that

    provides a useful and productive way to perform geographic data analysis, data conversion, data management, and map automation with Python.” -ESRI A tiny part of ArcGIS that lets you run ArcGIS tasks with Python code
  7. What is ArcPy? “ArcPy is a Python site package that

    provides a useful and productive way to perform geographic data analysis, data conversion, data management, and map automation with Python.” -ESRI Sounds cool, how do I use it? import arcpy # on any computer that has ArcMap/Pro installed
  8. What is ArcPy? “ArcPy is a Python site package that

    provides a useful and productive way to perform geographic data analysis, data conversion, data management, and map automation with Python.” -ESRI Sounds cool, how do I use it? import arcpy # on any computer that has ArcMap/Pro installed # this is the same as import math import random import statistics # in that it provides access to tons of functions
  9. Let’s look at the contour tool more closely. Anybody ever

    click this button? ArcPy Considerations 1: Arc Documentation is Helpful
  10. 2. Geoprocessing, done three ways: 2c. With Python/ArcPy “PYTHON WINDOW”

    “STAND-ALONE SCRIPT” What’s the difference? You can run #1 in the PYTHON WINDOW You can run #2 in JUPYTER
  11. ArcPy Considerations 2: Environments Geoprocessing environment settings are additional settings

    that affect geoprocessing tools. These settings provide a powerful way to ensure geoprocessing is performed in a controlled environment where you decide things such as the processing extent that limits processing to a specific geographic area, a coordinate system for all output datasets, or the cell size of output raster datasets.
  12. ArcPy Considerations 2: Environments Geoprocessing environment settings are additional settings

    that affect geoprocessing tools. These settings provide a powerful way to ensure geoprocessing is performed in a controlled environment where you decide things such as the processing extent that limits processing to a specific geographic area, a coordinate system for all output datasets, or the cell size of output raster datasets. For us, there are some really important environment settings we’ll use often.
  13. ArcPy Considerations 2: Environments For us, there are some really

    important environment settings we’ll use often. pro.arcgis.com/en/pro-app/arcpy/classes/env.htm Whether we want to add processing results to the map automatically
  14. ArcPy Considerations 2: Environments For us, there are some really

    important environment settings we’ll use often. pro.arcgis.com/en/pro-app/arcpy/classes/env.htm What cell size we want output raster data to have
  15. ArcPy Considerations 2: Environments For us, there are some really

    important environment settings we’ll use often. pro.arcgis.com/en/pro-app/arcpy/classes/env.htm What we want the coordinate system of output datasets to be
  16. ArcPy Considerations 2: Environments For us, there are some really

    important environment settings we’ll use often. pro.arcgis.com/en/pro-app/arcpy/classes/env.htm Whether we can name an output file the same thing as an existing file (and not get an error)
  17. ArcPy Considerations 2: Environments For us, there are some really

    important environment settings we’ll use often. pro.arcgis.com/en/pro-app/arcpy/classes/env.htm Where the shapefiles/rasters/feature classes we want to work on are located …and where our outputs will go. THIS ONE IS REALLY, REALLY IMPORTANT
  18. ArcPy Considerations 2: Environments For us, there are some really

    important environment settings we’ll use often. pro.arcgis.com/en/pro-app/arcpy/classes/env.htm Setting the workspace (and other environment settings is easy) …but you’ll forget to do it all the time, and so do I.
  19. ArcPy Considerations 2: Environments Setting the workspace (and other environment

    settings is easy) …but you’ll forget to do it all the time, and so do I.
  20. ArcPy Considerations 2: Environments Setting the workspace (and other environment

    settings is easy) …but you’ll forget to do it all the time, and so do I.
  21. ArcPy Considerations 2: Environments Setting the workspace (and other environment

    settings is easy) …but you’ll forget to do it all the time, and so do I. The first time I run this, life is good.
  22. ArcPy Considerations 2: Environments Setting the workspace (and other environment

    settings is easy) …but you’ll forget to do it all the time, and so do I. The first time I run this, life is good. The second time I run this, life isn’t so great.
  23. ArcPy Considerations 2: Environments Setting the workspace (and other environment

    settings is easy) …but you’ll forget to do it all the time, and so do I.
  24. ArcPy Considerations 2: Environments Setting the workspace (and other environment

    settings is easy) …but you’ll forget to do it all the time, and so do I. It’s good practice to have these 3 things in the first cell of all your scripts
  25. ArcPy Considerations 2: Environments File paths need to be exactly,

    completely, 100% accurate. Preface your file paths with r [to indicate it’s a raw text string and ignores escape character \ ]
  26. ArcPy Considerations 2: Environments File paths need to be exactly,

    completely, 100% accurate. Watch your file path for typos…because you won’t know right away!
  27. ArcPy Considerations 2: Environments File paths need to be exactly,

    completely, 100% accurate. Watch your file path for typos…because you won’t know right away! It’ll let you write whatever horribly mangled, typo-ridden thing you want for a workspace…because all it wants is a text string, which this is. …and you won’t realize your mistake until (possibly) way later in your code.
  28. ArcPy Considerations 2: Environments File paths need to be exactly,

    completely, 100% accurate. Watch your file path for typos…because you won’t know right away! CLICK IN HERE TO SHOW PATH
  29. ArcPy Considerations 2: Environments File paths need to be exactly,

    completely, 100% accurate. Watch your file path for typos…because you won’t know right away! CLICK IN HERE TO SHOW PATH THEN COPY/PASTE THIS INTO YOUR CODE
  30. ArcPy Considerations 3: GeoDatabases and their Contents Geodatabases hold spatial

    and attribute data of various kinds together. Think of these like a file cabinet.
  31. ArcPy Considerations 3: GeoDatabases and their Contents Feature Datasets are

    collections of related feature classes that share a common coordinate system. Think of these like folders in a file cabinet.
  32. ArcPy Considerations 3: GeoDatabases and their Contents Feature Classes are

    collections of features that share the same geometry type (point, line, polygon) and same attribute fields. Think of these like papers in folders in a file cabinet.
  33. Lab this week will consist of Comprehension and Homework You’ll

    work through an exercise and learn new skills 1. Learn to set environment variables 2. Learn to show the contents of Geodatabases 3. Learn to automate tasks with loops (Clip, Buffer) You’ll demonstrate these skills in homework 1. Clip feature classes 2. Buffer features classes 3. Intersect feature classes and compute areas A single .ipynb notebook (in the Jupyter assignment) A single .ipynb notebook with some text answers (in the homework assignment)