GEOG 315, GIS Programming, Fall 2020; Lecture 8

GEOG 315, GIS Programming, Fall 2020; Lecture 8

C45c5d4012ce7408eec95eb01eac2de9?s=128

alan.kasprak

October 16, 2020
Tweet

Transcript

  1. GEOG 315: GIS Programming and Web Mapping Lecture 8 –

    Reading and Writing Data
  2. For today… 1. A bit about classtools.py 2. A bit

    about spatial references GEOG 315: GIS Programming and Web Mapping Lecture 8 – Reading and Writing Data 3. A review of the CSV homework from Week 6 4. An introduction to cursors, this week’s topic
  3. 1. A bit about classtools.py classtools.py is a python module

    that was written by Chris Garrard at Utah State, and which I’ve modified for this class a Python module provides functions that do certain things; arcpy is a module, so are csv, math, random classtools.py looks like this…
  4. 1. A bit about classtools.py classtools.py is a python module

    that was written by Chris Garrard at Utah State, and which I’ve modified for this class a Python module provides functions that do certain things; arcpy is a module, so are csv, math, random classtools.py looks like this… the “get_extent” function the “plot” function the “is_path” function We’ll write our own modules to do GIS stuff in a few weeks!
  5. 1. A bit about classtools.py But for now, you don’t

    need to know why something like this works:
  6. 1. A bit about classtools.py But for now, you don’t

    need to know why something like this works: You do, however, need to know that: 1. classtools.py needs to be in the same folder as your notebook
  7. 1. A bit about classtools.py But for now, you don’t

    need to know why something like this works: You do, however, need to know that: 1. classtools.py needs to be in the same folder as your notebook 2. if your point isn’t called p1_point, things won’t go well
  8. 1. A bit about classtools.py But for now, you don’t

    need to know why something like this works: You do, however, need to know that: 1. classtools.py needs to be in the same folder as your notebook 2. if your point isn’t called p1_point, things won’t go well
  9. 2. A bit about spatial references Probably the most important

    thing to know about spatial references is that you need to create a spatial reference object from a coordinate system before you can do anything else! There are many ways to create a spatial reference object, so let’s go through them again. I’ll order these from the ones I use the most frequently to the ones I rarely use. SPATIAL REFERENCE OBJECT CREATION METHOD #1: THE NAME OF A COORDINATE SYSTEM https://pro.arcgis.com/en/pro- app/arcpy/classes/spatialreference.htm …OR GOOGLE ‘ARCPY SPATIAL REFRENCE’ …but note that the underscores need to go away when you tell arcpy the name
  10. 2. A bit about spatial references Probably the most important

    thing to know about spatial references is that you need to create a spatial reference object from a coordinate system before you can do anything else! There are many ways to create a spatial reference object, so let’s go through them again. I’ll order these from the ones I use the most frequently to the ones I rarely use. SPATIAL REFERENCE OBJECT CREATION METHOD #2: THE WELL-KNOWN ID (WKID) OF A COORDINATE SYSTEM https://pro.arcgis.com/en/pro- app/arcpy/classes/spatialreference.htm …OR GOOGLE ‘ARCPY SPATIAL REFRENCE’ Note that a coordinate system’s name is a string, and was in ‘single quotes’, while a WKID is just an integer, no quotes needed.
  11. 2. A bit about spatial references Probably the most important

    thing to know about spatial references is that you need to create a spatial reference object from a coordinate system before you can do anything else! There are many ways to create a spatial reference object, so let’s go through them again. I’ll order these from the ones I use the most frequently to the ones I rarely use. SPATIAL REFERENCE OBJECT CREATION METHOD #3: USE ANOTHER SHAPEFILE’S COORDINATE SYSTEM
  12. 2. A bit about spatial references Probably the most important

    thing to know about spatial references is that you need to create a spatial reference object from a coordinate system before you can do anything else! There are many ways to create a spatial reference object, so let’s go through them again. I’ll order these from the ones I use the most frequently to the ones I rarely use. SPATIAL REFERENCE OBJECT CREATION METHOD #4: USE A .prj FILE This one isn’t the best, because you have to type the full path to your .prj file (it doesn’t honor your arcpy.env.workspace) …but, .prj’s are pretty easy to snag from ArcGIS.
  13. 2. A bit about spatial references Probably the most important

    thing to know about spatial references is that you need to create a spatial reference object from a coordinate system before you can do anything else! There are many ways to create a spatial reference object, so let’s go through them again. I’ll order these from the ones I use the most frequently to the ones I rarely use. SPATIAL REFERENCE OBJECT CREATION METHOD #4: USE A .prj FILE This one isn’t the best, because you have to type the full path to your .prj file (it doesn’t honor your arcpy.env.workspace) …but, .prj’s are pretty easy to snag from ArcGIS.
  14. 3. A review of the CSV homework from Week 6

    courses.fortlewis.edu Let’s walk through the first problem from Week 6 together…
  15. 4. An introduction to cursors, this week’s topic https://pro.arcgis.com/en/pro-app/arcpy/get-started/data-access-using-cursors.htm

  16. None
  17. None
  18. What if I wanted to… - delete one of these

    points? - modify one of these points? - insert a new point that I’d collected? - insert 50,000 new points? - export every ‘rocks’ point to a new shapefile? CURSORS allow us to read and change attribute table data for points, lines, and polygons
  19. 4. An introduction to cursors, this week’s topic There are

    three types of cursors: think of all these as tools that loop through an attribute table and do something to it (read, delete, write new data) Search Cursor [arcpy.da.SearchCursor()] Allows you to read features but not change them or add any new features. Update Cursor [arcpy.da.UpdateCursor()] Allows you to read, update, and delete existing features, but not add any new features. Insert Cursor [arcpy.da.InsertCursor()] Allows you to add new features only (not read or delete) Why arcpy.da? Because these cursors live in ArcPy’s DATA ANALYSIS Module
  20. 4. An introduction to cursors, this week’s topic There are

    three types of cursors: think of all these as tools that loop through an attribute table and do something to it (read, delete, write new data) Search Cursor [arcpy.da.SearchCursor()] Allows you to read features but not change them or add any new features. Update Cursor [arcpy.da.UpdateCursor()] Allows you to read, update, and delete existing features, but not add any new features. Insert Cursor [arcpy.da.InsertCursor()] Allows you to add new features only (not read or delete) Why arcpy.da? Because these cursors live in ArcPy’s DATA ANALYSIS Module
  21. Lab this week will consist of Jupyter and a short

    Homework Just one(!) Homework Problem Combining CSVs and Cursors Five(!) Jupyter Notebooks for Comprehension 1. Search Cursors 2. Update Cursors 3. Insert Cursors 4. Using multiple cursors at once 5. Some helpful coding tricks Two Jupyter notebooks and one CSV file in a single .zip folder (for the homework assignment) Turn in your five notebooks as a single .zip folder (for the Jupyter Assignment)
  22. Let’s work through (some of) the homework! courses.fortlewis.edu download the

    week 7 zip folder