├── .gitignore ├── .idea ├── .gitignore ├── inspectionProfiles │ └── profiles_settings.xml ├── misc.xml ├── modules.xml ├── programming-for-gis-and-rs.iml └── vcs.xml ├── Final Project ├── Example 1 - STL Crime.pptx ├── Example 2.pptx ├── Example 3 - Image Processing.pptx ├── Example 4 - GIS 5090-Final Project.pptx ├── Example 5 - Lockmiler_finalprojectProposal.pptx ├── Example 6- Snap Point to Line Feature Geoprocessing Tool - Proposal.pptx ├── Proposal.md └── README.md ├── GIS 4090-5090 Programming for GIS&RS Syllabus Fall 2020.docx ├── ILoveToCode.md ├── InstructorInformation.md ├── LearnToCode.md ├── LectureLiveStream.md ├── LetsRoll.png ├── Project 1 └── README.md ├── Project 2 └── README.md ├── README.md ├── Unit 1 ├── Lecture_1_Slides.pptx ├── Missouri.gdb.zip ├── README.md ├── Welcome.pptx ├── configuring_the_notebook_directory.html ├── unit_1_lesson_1_intro_to_python.ipynb └── unit_1_lesson_2_more_python.ipynb ├── Unit 10 ├── README.md └── addresses.csv ├── Unit 11 ├── README.md ├── STL_Crime_1.gdb.zip ├── STL_Crime_gjb.gdb.zip ├── Thunder_Acquisitions_gjb.csv ├── Thunder_Departures_gjb.csv ├── national_rainfall_data_demogjb.zip └── nbrhds_wards_demo1.zip ├── Unit 12 ├── Lecture 1 - Matplotlib.ipynb ├── Lecture 2 - Intro to Spatial Dataframes (Feature to CSV in Lat and Longitude).ipynb ├── Lecture 3 - CSV to Spatial DataFrame to GIS Data.ipynb ├── Lecture 4 - plotting_with_plotly.ipynb ├── README.md ├── SENZA_0_SUNAA_0_CORN.xlsx ├── crime_data.gdb.zip └── matplotlib_styles.ipynb ├── Unit 13 └── README.md ├── Unit 14 └── README.md ├── Unit 15 └── README.md ├── Unit 2 ├── README.md ├── blocks_files.png ├── unit_1_lesson_2_more_python.ipynb ├── unit_2_lesson_1_geoprocessing_in_arcgis_pro.ipynb ├── unit_2_lesson_1_geoprocessing_in_arcmap.ipynb ├── unit_2_lesson_2_arcpy_in_arcgis_notebooks.ipynb └── unit_2_lesson_2_arcpy_in_arcgis_pro.ipynb ├── Unit 3 ├── OSM.zip ├── README.md ├── Singapore_Data.gdb.zip ├── data.zip ├── describe_demo_data.zip ├── unit_3_lesson_1_exploring_spatial_data.ipynb ├── unit_3_lesson_2_environments_and_coordinates_systems.ipynb └── unit_3_lesson_3_text_files_and_csvs.ipynb ├── Unit 4 ├── Crime.gdb.zip ├── Cursor_Lecture_Slides.pptx ├── Exercise07.zip ├── README.md ├── insert_cursor_crime.py ├── search_cursor_crime.py ├── unit_4_lesson_1_cursor_demos.ipynb └── update_cursor_crime.py ├── Unit 5 ├── README.md ├── unit_5_lesson_1_geometries.ipynb └── week_5_slides.pptx ├── Unit 6 ├── Exercise09.zip ├── README.md ├── Unit_6_Rasters.pptx ├── unit_6_lesson_1_working_with_rasters_arcpy.ipynb ├── unit_6_lesson_2_working_with_rasters_numpy.ipynb ├── unit_6_lesson_3_working_with_rasters_in_the_cloud.ipynb ├── working_with_rasters_arcpy__xid-18874256_1.html ├── working_with_rasters_in_the_cloud__xid-18874257_1.html └── working_with_rasters_numpy__xid-18874258_1.html ├── Unit 7 ├── Python_GP_Tools.ppt ├── README.md ├── problem1_script.py ├── problem2_script.py ├── unit_7_boto_and_azure.ipynb └── unit_7_gdal__xid.ipynb ├── Unit 8 ├── February2020.CSV ├── README.md ├── functions_example.html ├── functions_example.ipynb ├── requests.html ├── requests.ipynb ├── try_except.html └── try_except.ipynb ├── Unit 9 ├── Oklahoma_City_Thunder.png ├── README.md ├── all_week_aug_13_20.csv ├── chennai-rainfall.csv ├── me.gif └── profile_pic.jpg ├── Welcome.md ├── utilities └── final_project_order.py └── ~$S 4090-5090 Programming for GIS&RS Syllabus Fall 2020.docx /.gitignore: -------------------------------------------------------------------------------- 1 | *username* 2 | sample_docs/* 3 | *answer* 4 | code_arcpy_and_arcgis/* 5 | Week_10/lecture_imagery/* 6 | Week_10/Landsat_p114r75/* 7 | Week_10/Amberg_tif/* 8 | Week_9/Exercise09/* 9 | Week_9/python_exercises_all_chapters* 10 | *Homework* 11 | Project_2_Ideas/* 12 | Week_11/Exercise10/Exercise10/Austin/ 13 | Week_11/Exercise10/Exercise10/ 14 | Week_12/Project* 15 | Unit 3/dems.zip 16 | Unit 3/csv_demo_data.zip 17 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Default ignored files 3 | /workspace.xml -------------------------------------------------------------------------------- /.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/programming-for-gis-and-rs.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 11 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Final Project/Example 1 - STL Crime.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gbrunner/programming-for-gis-and-rs/e623312548ca5807730f37e625a304ca93e6c36e/Final Project/Example 1 - STL Crime.pptx -------------------------------------------------------------------------------- /Final Project/Example 2.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gbrunner/programming-for-gis-and-rs/e623312548ca5807730f37e625a304ca93e6c36e/Final Project/Example 2.pptx -------------------------------------------------------------------------------- /Final Project/Example 3 - Image Processing.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gbrunner/programming-for-gis-and-rs/e623312548ca5807730f37e625a304ca93e6c36e/Final Project/Example 3 - Image Processing.pptx -------------------------------------------------------------------------------- /Final Project/Example 4 - GIS 5090-Final Project.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gbrunner/programming-for-gis-and-rs/e623312548ca5807730f37e625a304ca93e6c36e/Final Project/Example 4 - GIS 5090-Final Project.pptx -------------------------------------------------------------------------------- /Final Project/Example 5 - Lockmiler_finalprojectProposal.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gbrunner/programming-for-gis-and-rs/e623312548ca5807730f37e625a304ca93e6c36e/Final Project/Example 5 - Lockmiler_finalprojectProposal.pptx -------------------------------------------------------------------------------- /Final Project/Example 6- Snap Point to Line Feature Geoprocessing Tool - Proposal.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gbrunner/programming-for-gis-and-rs/e623312548ca5807730f37e625a304ca93e6c36e/Final Project/Example 6- Snap Point to Line Feature Geoprocessing Tool - Proposal.pptx -------------------------------------------------------------------------------- /Final Project/Proposal.md: -------------------------------------------------------------------------------- 1 | # Final Project Proposal 2 | In my experience, all students and professionals need at least one demo or 3 | presentation that they can be prepared to give for a job interview, 4 | conference presentation, or other type of meeting. Through this class, 5 | I’d like each student to develop that demo or presentation, with the 6 | foundation of that presentation being some sort of spatial analysis, 7 | imagery analysis, or GIS analysis with Python. Each student will be 8 | responsible for a short 5-10 minute presentation to be given during 9 | the final week of class on a project of their own choosing that will 10 | leverage Python. In this discussion forum, please submit a short write 11 | up (no more than 5 bullet points) of what your project will be, 12 | what problem you will solve, how you will use Python to solve the 13 | problem. Also, please read and comment on at least 2 proposals 14 | from your classmates. 15 | 16 | On December 2, please be prepared to give a 5-10 minute presentation 17 | to the class via Zoom explaining your problem, solution, how you got 18 | there, and hopefully some cool maps and results. 19 | 20 | This is the first time I have used discussion forums in Blackboard, 21 | so please let me know if this isn't working as expected. **Start a 22 | "New Thread" and enter your proposal!** 23 | 24 | For examples of what students have proposed in the past, see the 25 | Power Point slides in the **Final Project Proposal** folder. 26 | 27 | **Due date for proposal submission is midnight, October 16.** 28 | -------------------------------------------------------------------------------- /Final Project/README.md: -------------------------------------------------------------------------------- 1 | Please submit your final project here. 2 | 3 | For your final projects, you are expected to give a 5-10 minutes presentation 4 | on Week 15 (5/6) of class. I will be including the presentation as part of the 5 | final project grade. 6 | 7 | Your final project submission should include your presentation, code, 8 | and any data products you produce. Please submit this all in a single 9 | zipped folder. 10 | 11 | I have used Python to randomly assign an order to the presentations. 12 | Below is the order we will go through presentations: -------------------------------------------------------------------------------- /GIS 4090-5090 Programming for GIS&RS Syllabus Fall 2020.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gbrunner/programming-for-gis-and-rs/e623312548ca5807730f37e625a304ca93e6c36e/GIS 4090-5090 Programming for GIS&RS Syllabus Fall 2020.docx -------------------------------------------------------------------------------- /ILoveToCode.md: -------------------------------------------------------------------------------- 1 | **Basketball** – https://github.com/gbrunner/court-js 2 | 3 | **Fun maps!** – https://twitter.com/gregbrunn/status/718271695212126213 4 | 5 | **Notebooks** - http://earthpy.org/analyzing-whale-tracks.html 6 | 7 | **Baseball** - https://gavinr.com/2016/12/22/create-pitch-charts-python/ 8 | -------------------------------------------------------------------------------- /InstructorInformation.md: -------------------------------------------------------------------------------- 1 | # Instructor Information 2 | 3 | **Instructor Name**: Gregory Brunner 4 | 5 | **Contact Information**: gregory.brunner@slu.edu 6 | 7 | **Virtual Office Hours**: 4 - 5 PM on Monday via Zoom - https://slu.zoom.us/j/98618329215?pwd=QmtPK3RrUnVybzlhZDcwdFVWdXpiQT09 8 | 9 | **Brief Biography**: Mr. Brunner is an experienced scientist and 10 | awards winning professor. He is an expert in the fields of 11 | geographic information systems (GIS), geospatial application development, 12 | remote sensing, big data analytics, Python, and ArcGIS. 13 | He is an excellent teacher who has taught undergraduate and 14 | graduate level geospatial programming courses at Saint Louis University. 15 | He has served on multiple academic program boards. He is an intelligent 16 | and passionate research professional with a Master of Science (MS) in 17 | Physics from Rice University. He has given presentations across the 18 | world on topics ranging from green infrastructure to augmented reality. 19 | -------------------------------------------------------------------------------- /LearnToCode.md: -------------------------------------------------------------------------------- 1 | Watch this awesome introduction to Python - https://www.youtube.com/watch?v=rkx5_MRAV3A -------------------------------------------------------------------------------- /LectureLiveStream.md: -------------------------------------------------------------------------------- 1 | Gregory Brunner is inviting you to a scheduled Zoom meeting. 2 | 3 | Topic: Weekly Lecture 4 | Time: Aug 19, 2020 04:00 PM Central Time (US and Canada) 5 | Every week on Wed, 15 occurrence(s) 6 | Aug 19, 2020 04:00 PM 7 | Aug 26, 2020 04:00 PM 8 | Sep 2, 2020 04:00 PM 9 | Sep 9, 2020 04:00 PM 10 | Sep 16, 2020 04:00 PM 11 | Sep 23, 2020 04:00 PM 12 | Sep 30, 2020 04:00 PM 13 | Oct 7, 2020 04:00 PM 14 | Oct 14, 2020 04:00 PM 15 | Oct 21, 2020 04:00 PM 16 | Oct 28, 2020 04:00 PM 17 | Nov 4, 2020 04:00 PM 18 | Nov 11, 2020 04:00 PM 19 | Nov 18, 2020 04:00 PM 20 | Nov 25, 2020 04:00 PM 21 | Please download and import the following iCalendar (.ics) files to your calendar system. 22 | Weekly: https://slu.zoom.us/meeting/tJcufuCpqDsuHNRkwv1LpuazXGXg4Gw5DHoQ/ics?icsToken=98tyKuCrrTIjG9KVtB-HRowqA4r4XevwpmJbgo1vlwjzUgxDdwLsDsV6NeZYB430 23 | 24 | Join Zoom Meeting 25 | https://slu.zoom.us/j/93399160460?pwd=azZrQXNlWG5ZUW44TktZYlVWdHlaUT09 26 | 27 | Meeting ID: 933 9916 0460 28 | Password: 408750 29 | 30 | One tap mobile 31 | +13126266799,93399160460# US (Chicago) 32 | +19292056099,93399160460# US (New York) 33 | 34 | Dial by your location 35 | +1 312 626 6799 US (Chicago) 36 | +1 929 205 6099 US (New York) 37 | +1 301 715 8592 US (Germantown) 38 | +1 346 248 7799 US (Houston) 39 | +1 669 900 6833 US (San Jose) 40 | +1 253 215 8782 US (Tacoma) 41 | Meeting ID: 933 9916 0460 42 | Find your local number: https://slu.zoom.us/u/aHo8GueHA -------------------------------------------------------------------------------- /LetsRoll.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gbrunner/programming-for-gis-and-rs/e623312548ca5807730f37e625a304ca93e6c36e/LetsRoll.png -------------------------------------------------------------------------------- /Project 1/README.md: -------------------------------------------------------------------------------- 1 | # Spring 2020 2 | ## Problem 1 (15 Points)¶ 3 | 4 | Unzip imagery.zip. Create a Notebook that uses arcpy Answer the following questions: 5 | 6 | 1. How many rasters are in the folder? 7 | 2. What is the projection of the rasters? 8 | 3. Do all the rasters have the same projection? 9 | 4. How many bands to the rasters have? 10 | 5. What is the raster format? 11 | 12 | Please use markdown cells to explain your answers. I'm not looking for anything too fancy here, just show me how you can use Python and arcpy to answer these questions. 13 | 14 | ## Problem 2 (15 Points) 15 | 16 | Unzip tlgdb_2019_a_us_school.gdb. Create a Notebook that uses arcpy to create a report about the features in the geodatabase. List out the following: 17 | 18 | 1. Feature class name 19 | 2. Number of features in the feature class 20 | 3. Projection of the feature class 21 | 4. Shape type of the feature class (point, polyline, polygon, etc.) 22 | 23 | Bonus (5 points) Write your results out to a text file or comma separated text file. 24 | 25 | ## Problem 3 (15 Points) 26 | 27 | Unzip usa_cities.gdb.zip. Identify the largest cities in the United States that have a population greater than 1 million people. Using Python, print a table that lists those largest cities and their corresponding population, according to the cities feature class. Use **POPULATION** as the population field. 28 | 29 | I recommend using ```arcpy.da.SearchCursor``` to iterate through the cities feature class to create a list of the cities and corresponding populations. 30 | 31 | ## Problem 4 (15 Points) 32 | 33 | Unzip usa_cities.gdb.zip. Create a list of city capitals and their corresponding state. 34 | 35 | I recommend Using ```arcpy.da.SearchCursor``` to iterate through the cities feature class to create a list of the cities and corresponding populations. 36 | 37 | ## Problem 5 (20 Points) 38 | 39 | Create a Python script or Notebook that copies all cities with a population over 1 million to a new feature class in the same geodatabase. 40 | 41 | I recommend exploring the following GP tools: 42 | 43 | - [Make Feature Layer](https://pro.arcgis.com/en/pro-app/tool-reference/data-management/make-feature-layer.htm) 44 | - [Select Layer by Attribute](https://pro.arcgis.com/en/pro-app/tool-reference/data-management/select-layer-by-attribute.htm) 45 | - [Copy Features](https://pro.arcgis.com/en/pro-app/tool-reference/data-management/copy-features.htm) 46 | 47 | ### Bonus (10 points) Using a for loop, write out the following 4 feature classes: 48 | 49 | 1. Feature class with a population greater than 1 million. 50 | 2. Feature class with a population between 500,000 and 1 million. 51 | 3. Feature class with a population between 100,000 and 500,000. 52 | 4. Feature class with a population less than 100,000 53 | 54 | ## Grading 55 | 56 | The project is out of a total of 100 points, 80 points for the problems, 20 points for you code documentation. Please use Markdown cells in your notebooks to explain what you are doing or code comments such as ## in your code cells. Any Bonus points can your score above 100 percent. -------------------------------------------------------------------------------- /Project 2/README.md: -------------------------------------------------------------------------------- 1 | # Spring 2019 2 | Please Complete Both Problems 3 | 4 | ## Problem 1 (**60 Points**) 5 | There is a tool in ArcGIS Pro and ArcMap called [Points to Line](https://pro.arcgis.com/en/pro-app/tool-reference/data-management/points-to-line.htm). This tool creates line features from points. **For this problem, do not use that tool!**. What I want you to do is essentially create that tool using cursors. 6 | 7 | What I would like you to do is create a line feature from the point features in **zoo_featues_wgs84.shp** by using a search cursor to retrieve the x,y locations of the points and an insert cursor to insert thost features into a new feature class. 8 | 9 | Grading this problem breaks down as follows: 10 | - Read geometries from **zoo_features_wgs84.shp** (10 points) 11 | - Create a new *'Polyline'* features class (10 points) 12 | - Convert points to a line (10 points) 13 | - Insert points into *'Polyline'* feature class (10 points) 14 | - Create Python Script Tool to turn points into a polyline 15 | - User interface (10 points) 16 | - Connecting the script to the tool with right parameters (10 points) 17 | 18 | If you a re looking for a starting point, I recoment looking at Zandbergen's Chapter 8 Challenge Problems and Solutions. 19 | 20 | ## Problem 2 (**40 points**) 21 | Write a Python script that uses *Raster* objects (see Zandbergen Chapter 9) and Spatial Analyst to create an average (mean) raster from p114r075_7t20000501_z50_nn10.tif, p114r075_7t20000501_z50_nn20.tif, p114r075_7t20000501_z50_nn30.tif, and p114r075_7t20000501_z50_nn40.tif found here (). Use mathematical operations similar to achieve this. If you need help, look to the exercises from Chapter 9 of Zandbergen. 22 | 23 | # Fall 2020 24 | ## Problem 1 (out of 50 points) 25 | Here is a list of Landsat Scenes over Oregon: 26 | 27 | https://landsat-pds.s3.amazonaws.com/c1/L8/046/028/LC08_L1TP_046028_20200908_20200918_01_T1/LC08_L1TP_046028_20200908_20200918_01_T1_B1.TIF 28 | https://landsat-pds.s3.amazonaws.com/c1/L8/046/028/LC08_L1TP_046028_20200908_20200918_01_T1/LC08_L1TP_046028_20200908_20200918_01_T1_B2.TIF 29 | https://landsat-pds.s3.amazonaws.com/c1/L8/046/028/LC08_L1TP_046028_20200908_20200918_01_T1/LC08_L1TP_046028_20200908_20200918_01_T1_B3.TIF 30 | https://landsat-pds.s3.amazonaws.com/c1/L8/046/028/LC08_L1TP_046028_20200908_20200918_01_T1/LC08_L1TP_046028_20200908_20200918_01_T1_B4.TIF 31 | https://landsat-pds.s3.amazonaws.com/c1/L8/046/028/LC08_L1TP_046028_20200908_20200918_01_T1/LC08_L1TP_046028_20200908_20200918_01_T1_B5.TIF 32 | https://landsat-pds.s3.amazonaws.com/c1/L8/046/028/LC08_L1TP_046028_20200908_20200918_01_T1/LC08_L1TP_046028_20200908_20200918_01_T1_B6.TIF 33 | https://landsat-pds.s3.amazonaws.com/c1/L8/046/028/LC08_L1TP_046028_20200908_20200918_01_T1/LC08_L1TP_046028_20200908_20200918_01_T1_B7.TIF 34 | https://landsat-pds.s3.amazonaws.com/c1/L8/046/028/LC08_L1TP_046028_20200908_20200918_01_T1/LC08_L1TP_046028_20200908_20200918_01_T1_B8.TIF 35 | https://landsat-pds.s3.amazonaws.com/c1/L8/046/028/LC08_L1TP_046028_20200908_20200918_01_T1/LC08_L1TP_046028_20200908_20200918_01_T1_B9.TIF 36 | https://landsat-pds.s3.amazonaws.com/c1/L8/046/028/LC08_L1TP_046028_20200908_20200918_01_T1/LC08_L1TP_046028_20200908_20200918_01_T1_B10.TIF 37 | https://landsat-pds.s3.amazonaws.com/c1/L8/046/028/LC08_L1TP_046028_20200908_20200918_01_T1/LC08_L1TP_046028_20200908_20200918_01_T1_B11.TIF 38 | 39 | You can also access them through: https://landsat-pds.s3.amazonaws.com/c1/L8/046/028/LC08_L1TP_046028_20200908_20200918_01_T1/index.html 40 | 41 | Using Python, create the following raster products: 42 | 43 | 1. [Calculate the NDVI of the scene (10 points)](https://www.usgs.gov/core-science-systems/nli/landsat/landsat-normalized-difference-vegetation-index?qt-science_support_page_related_con=0#qt-science_support_page_related_con) 44 | 2. [Calculate the SAVI of the scene (10 points)](https://www.usgs.gov/core-science-systems/nli/landsat/landsat-soil-adjusted-vegetation-index#:~:text=This%20image%20displays%20a%20(left,Adjusted%20Vegetation%20Index%20(SAVI).&text=SAVI%20is%20used%20to%20correct,where%20vegetative%20cover%20is%20low.) 45 | 3. Using [Composite Bands](https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/composite-bands.htm), create a 3 band R-G-B image from [bands 2, 3, and 4 (10 points)](https://gisgeography.com/landsat-8-bands-combinations/) 46 | 4. Using [Composite Bands](https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/composite-bands.htm), create a false color infrared image from [bands 3, 4, 5 (10 points)](https://gisgeography.com/landsat-8-bands-combinations/) 47 | 48 | Be sure to save the resulting rasters to disk as TIF files. 49 | Please create a clear, well-documented script or notebook. 50 | The readability will be graded out of 10 points. 51 | 52 | You can use ```arcpy``` or ```numpy```. Just solve the problem. 53 | 54 | ## Problem 2 - Out of 50 Points 55 | 56 | Turn script2.py into an ArcGIS Python GP Tool. 57 | Please submit the modified python script and the ArcGIS geoprocessing toolbox. 58 | You can test the script with the August2020.CSV file that is attached. 59 | 60 | I am being very open ended here. 61 | I just want to see you complete the tasks. 62 | Don't over think it. 63 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Course Description 2 | This course will introduce students to Python programming and its 3 | applications to remote sensing and GIS. Through completing this course, 4 | students will be able to use Python to perform common GIS and remote 5 | sensing analysis tasks, automate workflows, and develop custom Python 6 | tools. Topics will include describing data, manipulating data, 7 | automating spatial analysis tasks, creating Python scripts and tools, 8 | and using Python for imagery analysis. We will also introduce students to 9 | WebGIS and how Python can be used to interface with data that is shared online. 10 | 11 | # Course Objectives 12 | - Students will learn Python and understand how to use it to 13 | solve problems in GIS and Remote Sensing and will demonstrate 14 | their knowledge by completing multiple homework assignments and projects. 15 | - Students will be encouraged to use Python through relevant 16 | examples and assignments. 17 | - Students will begin implementing it in their own research 18 | projects such as theses and capstones. 19 | 20 | # Materials 21 | Course Materials will be shared using Blackboard. Slides, labs, 22 | and homework are in the folders that correspond to the specific units covered in class. 23 | 24 | # Texts 25 | - (Primary Textbook) Paul A Zandenbergen. [Python Scripting for ArcGIS Pro.](https://esripress.esri.com/display/index.cfm?fuseaction=display&websiteID=393&moduleID=0) ISBN: 9781589484993. $79.99 26 | - Paul A Zandenbergen. [Advanced Python Scripting for ArcGIS Pro.](https://esripress.esri.com/display/index.cfm?fuseaction=display&websiteID=384&moduleID=12) ISBN: 9781589486188. $79.99 27 | - (Optional) Laura Tateosian. Python for ArcGIS. ISBN 978-3-319-18398-5. $99.00 28 | 29 | # Grading 30 | 1. 15% - Lab Work & Programming Exercises 31 | 2. 15% - Homework Assignments 32 | 3. 20% - Project 1 33 | 4. 20% - Project 2 34 | 5. 30% - Final Project 35 | 36 | # Feedback and Assessment 37 | In order to ensure that students are on track to achieve the course objectives, 38 | students will have weekly coding assignments. The coding 39 | assignments will be graded and returned before the next online 40 | lecture, where the solutions will be reviewed, and questions will 41 | be addressed. Feedback on respective assignments will also be given to 42 | each student through Blackboard. Weekly assignment will become the 43 | foundation for student projects which will serve as the benchmarks for 44 | whether students understand how to use programming to solve GIS and 45 | remote sensing problems. There will be 3 projects over the course of 46 | the semester. Two will be defined by the professor. The third and final 47 | project will be defined by the student in consultation with me. For the 48 | final project, the student will define the questions he or she wants to 49 | answer, find the data to answer it, code up a solution to the question(s), 50 | and put together a presentation on the project and solution that will be 51 | presented during our final class. For the final project, discussion with 52 | classmates and me is encouraged as each student will define his or her own 53 | project and goals. The instructor will make himself available for virtual 54 | office hours weekly on Mondays from 4 to 5 PM using Zoom. If you have 55 | questions or concerns, don’t hesitate to meet with me during office hours, 56 | send me an email, or schedule an ad-hoc meeting with me outside of our 57 | regular meetings or office hours. For week 1 of class, please post your 58 | name, discipline of study, and academic interests in the Introductions 59 | discussion channel in Blackboard. If you ever need to talk, do not 60 | hesitate to reach out to me. 61 | 62 | # Schedule 63 | | Week | Topic | 64 | | ---- | ----- | 65 | | Week 1 | Intro to Python & Jupyter | 66 | | Week 2 | Intro to ```arcpy``` | 67 | | Week 3 | Exploring spatial data | 68 | | Week 4 | Working with feature data and cursors | 69 | | Week 5 | Working with features and geometries | 70 | | Week 6 | Rasters & imagery | 71 | | Week 7 | Creating Python script tools | 72 | | Week 8 | Functions, classes, and error handling | 73 | | Week 9 | Intro to Python for web GIS | 74 | | Week 10 | Interacting with AGOL using Python | 75 | | Week 11 | Publishing and consuming GIS services | 76 | | Week 12 | Plotting and data visualization | 77 | | Week 13 | Introduction to HTML and JavaScript | 78 | | Week 14 | Scientific data | 79 | | Week 15 | Final Project presentations | 80 | 81 | # Homework 82 | The purpose of the homework is twofold: to keep you thinking about 83 | Python outside of the lab and to prepare you for the next class. 84 | I do not want to overwhelm you with homework. I do want to ensure 85 | that you are learning how to use Python to solve GIS and remote 86 | sensing problems. Please do not hesitate to ask me or your classmates 87 | questions on homework if you are encountering difficulties. Furthermore, 88 | I would like your feedback as to whether assignments get too difficult or 89 | too easy so that I can adjust the assignments and in-class materials 90 | accordingly. Homework is to be submitted via blackboard before class on 91 | the day that it is due. 92 | 93 | # In Class Exercises 94 | The easiest way to learn to code is by writing code! Lectures are 95 | designed to be interactive. If I am typing code, you should be too! 96 | Lectures will be followed by in-class exercises that are designed to 97 | get you writing code on your own. The exercises that I have written 98 | as Python notebooks (.ipynb files) have questions throughout them. 99 | Please answer these questions and submit them via Blackboard before 100 | the beginning of the following week of class. 101 | 102 | # Project 1 103 | Project 1 will likely consist of working with 104 | tabular data (CSV or text file) or generating 105 | some report based on GIS data using Python. 106 | I will give the assignment by week 4. It is due 107 | before class on week 6. 108 | 109 | # Project 2 110 | Project 2 will likely consist of using Python to do some 111 | sort of spatial analysis or raster analysis. It will be 112 | assigned by week 9. It is due before class on week 11. 113 | 114 | # Final Project 115 | In my experience, all students and professionals need at 116 | least one demo or presentation that they can be prepared 117 | to give for a job interview, conference presentation, or 118 | other type of meeting. Through this class, I’d like each 119 | student to develop that demo or presentation, with the 120 | foundation of that presentation being some sort of spatial 121 | analysis, imagery analysis, or GIS analysis with Python. 122 | Each student will be responsible for a short 10 minute 123 | presentation to be given during either Week 14 or 15 of 124 | class on a project of their own choosing that will leverage 125 | Python. Before Spring Break (i.e. by Week 8), please submit 126 | to me a short write up (no more than 1 page) of what your 127 | project will be, what problem you will solve, how you will 128 | use Python to solve the problem. On week 14 or 15, please 129 | be prepared to give a 10 minute presentation explaining 130 | your problem, solution, how you got there, and hopefully 131 | some cool maps and results. -------------------------------------------------------------------------------- /Unit 1/Lecture_1_Slides.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gbrunner/programming-for-gis-and-rs/e623312548ca5807730f37e625a304ca93e6c36e/Unit 1/Lecture_1_Slides.pptx -------------------------------------------------------------------------------- /Unit 1/Missouri.gdb.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gbrunner/programming-for-gis-and-rs/e623312548ca5807730f37e625a304ca93e6c36e/Unit 1/Missouri.gdb.zip -------------------------------------------------------------------------------- /Unit 1/README.md: -------------------------------------------------------------------------------- 1 | # This Week's Reading 2 | This week, please read the following: 3 | - Beginner's guide to Python in ArcGIS Pro, Part 1: Why? 4 | - Beginner’s guide to Python in ArcGIS Pro, Part 2: How? 5 | - Chapters 1 and Chapters 4 of Python Scripting for ArcGIS Pro 6 | 7 | # Last Year's Week 1 Lecture Recording 8 | Here are the links to the first lecture from last year. This link is not intended to be used in place of this week's lecture. I am providing it as an additional resource for extra context. 9 | - First half of lecture - https://slu.hosted.panopto.com/Panopto/Pages/Viewer.aspx?id=e01fab5b-e86b-4f7a-b584-ab41016e8a56 10 | - Second half of lecture - https://slu.hosted.panopto.com/Panopto/Pages/Viewer.aspx?id=d55b6de0-817d-479d-86d6-ab410188ecf4 11 | 12 | # Presentations 13 | Here are the PowerPoint slides that I plan to use for week 1. 14 | Attached Files: 15 | 16 | File Lecture_1_Slides.pptx Click for more options (2.058 MB) 17 | File Welcome.pptx Click for more options (515.31 KB) 18 | 19 | # Data and Notebooks 20 | This week's lecture notebooks can be found in the [GIS 4090\5090 Unit 1 Notebooks](This week's lecture notebooks can be found in the GIS 4090\5090 Unit 1 Notebooks group on ArcGIS Online or downloaded here. Please download the Missouri.gdb.zip so that we can use it for the lecture.) 21 | group on ArcGIS Online or downloaded here. 22 | Please download the Missouri.gdb.zip so that we can use it for the lecture. 23 | Attached Files: 24 | 25 | File unit_1_lesson_1_introto_python.ipynb Click for more options (36.852 KB) 26 | File unit_1_lesson_2_more_python.ipynb Click for more options (19.851 KB) 27 | File Missouri.gdb.zip Click for more options (10.712 MB) 28 | 29 | # Configuring Jupyter Notebooks 30 | This document provides instructions to configure Jupyter Notebooks on your computer. We will go through this process 31 | to setup Jupyter Notebooks on your lab computer or personal computer. 32 | Attached Files: 33 | 34 | File configuring_the_notebook_directory.html Click for more options (269.886 KB) 35 | 36 | # Unit 1 Exercise and Discussion Questions 37 | ## Exercises 38 | 39 | Before completing the assignment, I recommend completing the following exercises. Completing these 3 exercises should not take more than an hour. 40 | 41 | Complete the Hello, Notebook !exercise. After you complete it, add another map object and a different dataset to the map. Save the Notebook and share the link to the Notebook here. I will be able to see your notebook even if you don't explicitly share it with me in ArcGIS Online because I am an administrator in the ArcGIS Online organization. 42 | Please complete Python Scripting for ArcGIS Pro Exercise 1. This should take no more than 15 minutes. 43 | Please complete Python Scripting for ArcGIS Pro Exercise 4. This will take a little bit longer but I think you will find it very helpful. Please submit the Python scripts that you create. 44 | 45 | ## Discussion Questions 46 | 47 | Please submit a Word file or text file that answers the following questions. 48 | 49 | What is the version Python that comes with ArcGIS Pro? 50 | Name 3 methods of string objects in Python and give an example of each. 51 | What two values can a boolean take on? 52 | How do you denote a comment line in Python and what should yo use comments? 53 | 54 | # Unit 1 Assignment 55 | ## Assignment 56 | 57 | Please submit a Word file, text file, or ArcGIS Notebook that answers the following questions. If you do this in ArcGIS Notebooks, you can save the notebook and just send me a URL to the item in ArcGIS Online. 58 | 59 | 1. Consider the following variable called happyCow 60 | 61 | happyCow = 'meadows.shp' 62 | 63 | Determine the following: 64 | 65 | happyCow[0] 66 | happyCow[0:5] + happyCow[-4:] 67 | len(happyCow) 68 | happyCow[0:5] 69 | happyCow[-4:] 70 | happyCow[11] 71 | happyCow[:5] 72 | happyCow in "5meadows.shp" 73 | happyCow[5] 74 | 'W' in happyCow 75 | 76 | 77 | 2. Determine if each statement is True or False using the variable LCS_ID = '0017238' 78 | 79 | '17' in LCS_ID 80 | LCS_ID.isdigit() 81 | LCS_ID.lstrip('0') == '17238' 82 | LCS_ID.zfill(10) == '10101010' 83 | LCS_ID + '10' == 17248 84 | LCS_ID[6] == '3' 85 | len(LCS_ID) == 7 86 | LCS_ID[0:7] == '0017238' 87 | int(LCS_ID) + 10 == 17248 88 | LCS_ID != 17238 89 | 90 | 3. The list variable 'census' is as follows: 91 | 92 | census = ['4', '3', '79', '1', '66', '9', '1'] 93 | 94 | Determine the following: 95 | 96 | len(census) 97 | census.insert(0,2) 98 | census.append(2) 99 | census.remove('1') 100 | census = '0'.join(census) 101 | census.pop(3) 102 | census.count('1') 103 | census.sort() 104 | census.reverse() 105 | 106 | 107 | 4. Consider the following list: 108 | 109 | mylist = ["Athens", "Barcelona", "Cairo", "Florence", "Helsinki"] 110 | 111 | Determine the results of the following: 112 | 113 | len(mylist) 114 | mylist[2] 115 | mylist[1:] 116 | mylist[-1] 117 | mylist.index("Cairo") 118 | mylist.pop(1) 119 | mylist.sort(reverse = True) 120 | mylist.append("Berlin") 121 | 122 | These operations are all to be performed on the original list—that is, not as a sequence of operations. Try to determine the answer manually first, and then check your result by running the code. 123 | -------------------------------------------------------------------------------- /Unit 1/Welcome.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gbrunner/programming-for-gis-and-rs/e623312548ca5807730f37e625a304ca93e6c36e/Unit 1/Welcome.pptx -------------------------------------------------------------------------------- /Unit 1/unit_1_lesson_2_more_python.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# More Python Fundamentals" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "In these excercises, we will address more of what I consider Python fundamentals." 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "## File Paths" 22 | ] 23 | }, 24 | { 25 | "cell_type": "markdown", 26 | "metadata": {}, 27 | "source": [ 28 | "File paths in Python can seem very peculiar to newcomers to programming. Typically, we see a filpath represented as something like C:\\Documents\\my_document.docx. In Python, we can not just reference a file this way. Let's walk through the 3 ways we can reference file names in Python using the week 1 or week 2 excercise data." 29 | ] 30 | }, 31 | { 32 | "cell_type": "code", 33 | "execution_count": null, 34 | "metadata": { 35 | "collapsed": true 36 | }, 37 | "outputs": [], 38 | "source": [ 39 | "input_fc = \"C:\\\\Users\\\\greg6750\\\\Documents\\\\IPython Notebooks\\\\Python_for_GIS_and_RS\\\\Week_1\\\\data\\\\Missouri.gdb\\\\County\"" 40 | ] 41 | }, 42 | { 43 | "cell_type": "markdown", 44 | "metadata": {}, 45 | "source": [ 46 | "Let's print out input_fc to see how Python interprets that." 47 | ] 48 | }, 49 | { 50 | "cell_type": "code", 51 | "execution_count": null, 52 | "metadata": {}, 53 | "outputs": [], 54 | "source": [ 55 | "print(input_fc)" 56 | ] 57 | }, 58 | { 59 | "cell_type": "markdown", 60 | "metadata": {}, 61 | "source": [ 62 | "Notice that Python has removed the double backslashes. Rather than using double backslashes, we could use single forward slashes as follows." 63 | ] 64 | }, 65 | { 66 | "cell_type": "code", 67 | "execution_count": null, 68 | "metadata": { 69 | "collapsed": true 70 | }, 71 | "outputs": [], 72 | "source": [ 73 | "input_fc = \"C:/Users/greg6750/Documents/IPython Notebooks/Python_for_GIS_and_RS/Week_1/data/Missouri.gdb/County\"" 74 | ] 75 | }, 76 | { 77 | "cell_type": "markdown", 78 | "metadata": {}, 79 | "source": [ 80 | "Now, when we print that out we see that Python shows a single forward slash." 81 | ] 82 | }, 83 | { 84 | "cell_type": "code", 85 | "execution_count": null, 86 | "metadata": {}, 87 | "outputs": [], 88 | "source": [ 89 | "print(input_fc)" 90 | ] 91 | }, 92 | { 93 | "cell_type": "markdown", 94 | "metadata": {}, 95 | "source": [ 96 | "The final way to reference file path is by placeing the letter _r_ in front of the string. This indicates to Python that the single backslash not be read as an escape character." 97 | ] 98 | }, 99 | { 100 | "cell_type": "code", 101 | "execution_count": null, 102 | "metadata": { 103 | "collapsed": true 104 | }, 105 | "outputs": [], 106 | "source": [ 107 | "input_fc = r\"C:\\Users\\greg6750\\Documents\\IPython Notebooks\\Python_for_GIS_and_RS\\Week_1\\data\\Missouri.gdb\\County\"" 108 | ] 109 | }, 110 | { 111 | "cell_type": "markdown", 112 | "metadata": {}, 113 | "source": [ 114 | "Now, when we print this string out, we should see single backslashes." 115 | ] 116 | }, 117 | { 118 | "cell_type": "code", 119 | "execution_count": null, 120 | "metadata": {}, 121 | "outputs": [], 122 | "source": [ 123 | "print(input_fc)" 124 | ] 125 | }, 126 | { 127 | "cell_type": "markdown", 128 | "metadata": {}, 129 | "source": [ 130 | "## Modules" 131 | ] 132 | }, 133 | { 134 | "cell_type": "markdown", 135 | "metadata": { 136 | "collapsed": true 137 | }, 138 | "source": [ 139 | "Modules are functionality that can be imported into Python to extend its capabilities. Here, we will import and examine a few modules that we will use in the future." 140 | ] 141 | }, 142 | { 143 | "cell_type": "code", 144 | "execution_count": null, 145 | "metadata": { 146 | "collapsed": true 147 | }, 148 | "outputs": [], 149 | "source": [ 150 | "import arcpy" 151 | ] 152 | }, 153 | { 154 | "cell_type": "markdown", 155 | "metadata": {}, 156 | "source": [ 157 | "Let's see what version of arcpy we're using." 158 | ] 159 | }, 160 | { 161 | "cell_type": "code", 162 | "execution_count": null, 163 | "metadata": {}, 164 | "outputs": [], 165 | "source": [ 166 | "arcpy.GetInstallInfo()" 167 | ] 168 | }, 169 | { 170 | "cell_type": "markdown", 171 | "metadata": {}, 172 | "source": [ 173 | "## Question 1: What is the version number of arcpy?" 174 | ] 175 | }, 176 | { 177 | "cell_type": "markdown", 178 | "metadata": {}, 179 | "source": [ 180 | "You can also print out the help for each function using the __doc__ command. Let's see what the ArcGIS Documentation says about the [Clip function](http://pro.arcgis.com/en/pro-app/tool-reference/analysis/clip.htm)" 181 | ] 182 | }, 183 | { 184 | "cell_type": "code", 185 | "execution_count": null, 186 | "metadata": {}, 187 | "outputs": [], 188 | "source": [ 189 | "arcpy.Clip_analysis.__doc__" 190 | ] 191 | }, 192 | { 193 | "cell_type": "markdown", 194 | "metadata": {}, 195 | "source": [ 196 | "We can also list out all of the functions within the arcpy library using the __dir__ command." 197 | ] 198 | }, 199 | { 200 | "cell_type": "code", 201 | "execution_count": null, 202 | "metadata": {}, 203 | "outputs": [], 204 | "source": [ 205 | "dir(arcpy)" 206 | ] 207 | }, 208 | { 209 | "cell_type": "markdown", 210 | "metadata": {}, 211 | "source": [ 212 | "We can count the number of functions in the arcpy module using the __len__ function," 213 | ] 214 | }, 215 | { 216 | "cell_type": "code", 217 | "execution_count": null, 218 | "metadata": {}, 219 | "outputs": [], 220 | "source": [ 221 | "len(dir(arcpy))" 222 | ] 223 | }, 224 | { 225 | "cell_type": "markdown", 226 | "metadata": {}, 227 | "source": [ 228 | "## Question 2: How many functions are there in arcpy?" 229 | ] 230 | }, 231 | { 232 | "cell_type": "markdown", 233 | "metadata": {}, 234 | "source": [ 235 | "Another module that we'll be using is the _time_ module. This will help us track how long processes take to run, how to manipulate strings that contain time or data information, and much more. Let's import _time_." 236 | ] 237 | }, 238 | { 239 | "cell_type": "code", 240 | "execution_count": null, 241 | "metadata": { 242 | "collapsed": true 243 | }, 244 | "outputs": [], 245 | "source": [ 246 | "import time" 247 | ] 248 | }, 249 | { 250 | "cell_type": "markdown", 251 | "metadata": {}, 252 | "source": [ 253 | "We can get the locatime using this time object module." 254 | ] 255 | }, 256 | { 257 | "cell_type": "code", 258 | "execution_count": null, 259 | "metadata": {}, 260 | "outputs": [], 261 | "source": [ 262 | "time.localtime()" 263 | ] 264 | }, 265 | { 266 | "cell_type": "markdown", 267 | "metadata": {}, 268 | "source": [ 269 | "This function returned a tuple containing year, month, day, hour, min, sec, etc. describing the local time. An easier way to represent time would be as asctime." 270 | ] 271 | }, 272 | { 273 | "cell_type": "code", 274 | "execution_count": null, 275 | "metadata": {}, 276 | "outputs": [], 277 | "source": [ 278 | "time.asctime()" 279 | ] 280 | }, 281 | { 282 | "cell_type": "markdown", 283 | "metadata": {}, 284 | "source": [ 285 | "## Conditoinal Statements" 286 | ] 287 | }, 288 | { 289 | "cell_type": "markdown", 290 | "metadata": {}, 291 | "source": [ 292 | "Conditional statements, also knows as if/else statements, are common to all programming languages. COnditional statements evaluate data, and make a decision based on the result. Let's write a few if/else statements.\n", 293 | "\n", 294 | "Python has a module called _random_ which can be used to generate random numbers. Here we can similate a coinflip using random. Import random." 295 | ] 296 | }, 297 | { 298 | "cell_type": "code", 299 | "execution_count": null, 300 | "metadata": { 301 | "collapsed": true 302 | }, 303 | "outputs": [], 304 | "source": [ 305 | "import random" 306 | ] 307 | }, 308 | { 309 | "cell_type": "markdown", 310 | "metadata": {}, 311 | "source": [ 312 | "We can generate a random number that is either 1 or 2 using the _randint_ function. If the number is 1, we say the number is odd. If the number is 2 we say the number is even. Try the following code." 313 | ] 314 | }, 315 | { 316 | "cell_type": "code", 317 | "execution_count": null, 318 | "metadata": {}, 319 | "outputs": [], 320 | "source": [ 321 | "random_val = random.randint(1, 2)\n", 322 | "if random_val == 1:\n", 323 | " print(str(random_val) + \" is Odd\")\n", 324 | "else: \n", 325 | " print(str(random_val) + \" is Even\")" 326 | ] 327 | }, 328 | { 329 | "cell_type": "markdown", 330 | "metadata": {}, 331 | "source": [ 332 | "Let's write a conditional statement that evaluates a list of data. Type and execute the following code." 333 | ] 334 | }, 335 | { 336 | "cell_type": "code", 337 | "execution_count": null, 338 | "metadata": {}, 339 | "outputs": [], 340 | "source": [ 341 | "data = [1,2,3,4,5,6,7,8,9,10]\n", 342 | "for val in data:\n", 343 | " if val % 2 == 0:\n", 344 | " print(val,\"No remainder\") # the % sign is the modulus operator and tests for a remainder\n", 345 | " elif val % 3 == 2:\n", 346 | " print(val,\"Remainder of Two\")\n", 347 | " else:\n", 348 | " print(\"Final Case\")" 349 | ] 350 | }, 351 | { 352 | "cell_type": "markdown", 353 | "metadata": {}, 354 | "source": [ 355 | "COnditional statements are very powerful. You will be using the a lot! [Check out this site to learn more about the comparison operators and logical operators n Python](https://www.tutorialspoint.com/python/python_basic_operators.htm)" 356 | ] 357 | }, 358 | { 359 | "cell_type": "markdown", 360 | "metadata": {}, 361 | "source": [ 362 | "## Loops" 363 | ] 364 | }, 365 | { 366 | "cell_type": "markdown", 367 | "metadata": {}, 368 | "source": [ 369 | "### While Loops" 370 | ] 371 | }, 372 | { 373 | "cell_type": "markdown", 374 | "metadata": {}, 375 | "source": [ 376 | "Truth be told, I never use while loops! This might actually be the first one I've written in Python. This is because I find _for_ loops and conditional statements more intuitive. That being said, let's take our random number generator example and run it 10 times using a while loop and see what answers we get." 377 | ] 378 | }, 379 | { 380 | "cell_type": "code", 381 | "execution_count": null, 382 | "metadata": {}, 383 | "outputs": [], 384 | "source": [ 385 | "import random\n", 386 | "\n", 387 | "i = 1\n", 388 | "while i <= 10:\n", 389 | " random_val = random.randint(1, 2)\n", 390 | " if random_val == 1:\n", 391 | " print(\"Trial \" + str(i) + \": \" + str(random_val) + \" is Odd\")\n", 392 | " else: \n", 393 | " print(\"Trial \" + str(i) + \": \" + str(random_val) + \" is Even\")\n", 394 | " i += 1" 395 | ] 396 | }, 397 | { 398 | "cell_type": "markdown", 399 | "metadata": {}, 400 | "source": [ 401 | "## Question 3: How many odd and how many even results did you get over 10 Trials?" 402 | ] 403 | }, 404 | { 405 | "cell_type": "markdown", 406 | "metadata": {}, 407 | "source": [ 408 | "In the example above, the trials are run while the value of _i_ is less than 10. Once the 10th trial is hit, Python exits out of the loop." 409 | ] 410 | }, 411 | { 412 | "cell_type": "markdown", 413 | "metadata": {}, 414 | "source": [ 415 | "### For Loops" 416 | ] 417 | }, 418 | { 419 | "cell_type": "markdown", 420 | "metadata": {}, 421 | "source": [ 422 | "Like I mentioned above, I prefer using for loops to while loops. For loops repeat parts of your code but are not tied to a specific condition. We will encounter for loops throughout our programming careers and understanding them will be key to your growth as a programmer or developer. Let's write a few for loops." 423 | ] 424 | }, 425 | { 426 | "cell_type": "code", 427 | "execution_count": null, 428 | "metadata": { 429 | "collapsed": true 430 | }, 431 | "outputs": [], 432 | "source": [ 433 | "top_five = [\"Patriots\", \"Seahawks\", \"Cowboys\", \"Chiefs\", \"Steelers\"]" 434 | ] 435 | }, 436 | { 437 | "cell_type": "markdown", 438 | "metadata": {}, 439 | "source": [ 440 | "Here we've created a list of the top 5 teams in the NFL (hypothetical). We can print out each team name using a for loop." 441 | ] 442 | }, 443 | { 444 | "cell_type": "code", 445 | "execution_count": null, 446 | "metadata": {}, 447 | "outputs": [], 448 | "source": [ 449 | "for team in top_five:\n", 450 | " print(team)" 451 | ] 452 | }, 453 | { 454 | "cell_type": "markdown", 455 | "metadata": {}, 456 | "source": [ 457 | "We can print out each team name in all caps using the _upper_ function." 458 | ] 459 | }, 460 | { 461 | "cell_type": "code", 462 | "execution_count": null, 463 | "metadata": {}, 464 | "outputs": [], 465 | "source": [ 466 | "for team in top_five:\n", 467 | " print(team.upper())" 468 | ] 469 | }, 470 | { 471 | "cell_type": "markdown", 472 | "metadata": {}, 473 | "source": [ 474 | "A practical application of for loops is that we can list all datasets in a folder or geodatabase. Packaged in the Week 2 folder we have a census dataset. Let's import the census dataset using arcpy and list all of the feature classes in the census geodatabase. " 475 | ] 476 | }, 477 | { 478 | "cell_type": "code", 479 | "execution_count": null, 480 | "metadata": {}, 481 | "outputs": [], 482 | "source": [ 483 | "import arcpy\n", 484 | "\n", 485 | "arcpy.env.workspace = r'C:\\Users\\greg6750\\Documents\\IPython Notebooks\\Python_for_GIS_and_RS\\Week_2\\data\\tlgdb_2016_a_44_ri.gdb'\n", 486 | "\n", 487 | "fcs = arcpy.ListFeatureClasses()\n", 488 | "\n", 489 | "for fc in fcs:\n", 490 | " print(fc)" 491 | ] 492 | }, 493 | { 494 | "cell_type": "markdown", 495 | "metadata": {}, 496 | "source": [ 497 | "Here, we imported arcpy. We set the arcpy environment to be the census geodatabase. We used ListFeatureClasses to create a list of feature classes in the geodatabase, and we printed out the names of each feature class. We can also print out the number of features in the geodatabase." 498 | ] 499 | }, 500 | { 501 | "cell_type": "code", 502 | "execution_count": null, 503 | "metadata": {}, 504 | "outputs": [], 505 | "source": [ 506 | "print(len(fcs))" 507 | ] 508 | }, 509 | { 510 | "cell_type": "markdown", 511 | "metadata": {}, 512 | "source": [ 513 | "## Question 4: How many feature classes are in that geodatabase?" 514 | ] 515 | }, 516 | { 517 | "cell_type": "markdown", 518 | "metadata": {}, 519 | "source": [ 520 | "## OS" 521 | ] 522 | }, 523 | { 524 | "cell_type": "markdown", 525 | "metadata": {}, 526 | "source": [ 527 | "The [_os_ module](https://docs.python.org/2/library/os.html) allows Python users to interact with their computer's operating system. This includes accessing directories, files, and other data on the OS. It is a library that you will use very often to find files, move files, create file path, and more. Here, we'll introduce you to a few ways to use OS." 528 | ] 529 | }, 530 | { 531 | "cell_type": "code", 532 | "execution_count": null, 533 | "metadata": { 534 | "collapsed": true 535 | }, 536 | "outputs": [], 537 | "source": [ 538 | "import os" 539 | ] 540 | }, 541 | { 542 | "cell_type": "markdown", 543 | "metadata": {}, 544 | "source": [ 545 | "Let's take one of the filenames that we've used above." 546 | ] 547 | }, 548 | { 549 | "cell_type": "code", 550 | "execution_count": null, 551 | "metadata": { 552 | "collapsed": true 553 | }, 554 | "outputs": [], 555 | "source": [ 556 | "missouri_gdb = r\"C:\\Users\\greg6750\\Documents\\IPython Notebooks\\Python_for_GIS_and_RS\\Week_1\\data\\Missouri.gdb\"" 557 | ] 558 | }, 559 | { 560 | "cell_type": "markdown", 561 | "metadata": {}, 562 | "source": [ 563 | "We can use os to split that path into geodatabase and the path to the geodatabase as follows:" 564 | ] 565 | }, 566 | { 567 | "cell_type": "code", 568 | "execution_count": null, 569 | "metadata": {}, 570 | "outputs": [], 571 | "source": [ 572 | "os.path.basename(missouri_gdb) #returns the geodatabase" 573 | ] 574 | }, 575 | { 576 | "cell_type": "code", 577 | "execution_count": null, 578 | "metadata": {}, 579 | "outputs": [], 580 | "source": [ 581 | "os.path.dirname(missouri_gdb) #returns the directory" 582 | ] 583 | }, 584 | { 585 | "cell_type": "markdown", 586 | "metadata": {}, 587 | "source": [ 588 | "You could also use:" 589 | ] 590 | }, 591 | { 592 | "cell_type": "code", 593 | "execution_count": null, 594 | "metadata": {}, 595 | "outputs": [], 596 | "source": [ 597 | "path, gdb = os.path.split(missouri_gdb)\n", 598 | "print(path) #returns the path\n", 599 | "print(gdb) #returns the geodatabase" 600 | ] 601 | }, 602 | { 603 | "cell_type": "markdown", 604 | "metadata": {}, 605 | "source": [ 606 | "Another cool function in _os_ is _walk_. Walk can be used to list all of the files in a directory. Choose a directory on your machine and try it!" 607 | ] 608 | }, 609 | { 610 | "cell_type": "code", 611 | "execution_count": null, 612 | "metadata": {}, 613 | "outputs": [], 614 | "source": [ 615 | "folder = r'C:\\Users\\greg6750\\Documents\\IPython Notebooks\\Python_for_GIS_and_RS\\Week_1'\n", 616 | "for (path, dirs, files) in os.walk(folder):\n", 617 | " print(path)\n", 618 | " print(dirs)\n", 619 | " print(files)" 620 | ] 621 | }, 622 | { 623 | "cell_type": "markdown", 624 | "metadata": {}, 625 | "source": [ 626 | "This should list everything you find in the folder, including subsolders!" 627 | ] 628 | }, 629 | { 630 | "cell_type": "markdown", 631 | "metadata": {}, 632 | "source": [ 633 | "## SYS" 634 | ] 635 | }, 636 | { 637 | "cell_type": "markdown", 638 | "metadata": {}, 639 | "source": [ 640 | "The [_sys_ module](https://docs.python.org/2/library/sys.html) provides access to some variables used or maintained by the interpreter and to functions that interact strongly with the interpreter. Here, we'll learn a few common ways that you might use _sys_." 641 | ] 642 | }, 643 | { 644 | "cell_type": "code", 645 | "execution_count": null, 646 | "metadata": { 647 | "collapsed": true 648 | }, 649 | "outputs": [], 650 | "source": [ 651 | "import sys" 652 | ] 653 | }, 654 | { 655 | "cell_type": "markdown", 656 | "metadata": {}, 657 | "source": [ 658 | "You can use _sys.path_ to look at your Windows path variable." 659 | ] 660 | }, 661 | { 662 | "cell_type": "code", 663 | "execution_count": null, 664 | "metadata": {}, 665 | "outputs": [], 666 | "source": [ 667 | "print(sys.path)" 668 | ] 669 | }, 670 | { 671 | "cell_type": "markdown", 672 | "metadata": {}, 673 | "source": [ 674 | "We can search for Python in our system path variable. If it is in there, we should be able to execute python from the Windows command prompt." 675 | ] 676 | }, 677 | { 678 | "cell_type": "code", 679 | "execution_count": null, 680 | "metadata": {}, 681 | "outputs": [], 682 | "source": [ 683 | "path = sys.path\n", 684 | "for element in path:\n", 685 | " if 'python' in element:\n", 686 | " print(\"Python is in our Path variable!\")" 687 | ] 688 | }, 689 | { 690 | "cell_type": "markdown", 691 | "metadata": {}, 692 | "source": [ 693 | "## Question 5: Is Python in your path variable?" 694 | ] 695 | }, 696 | { 697 | "cell_type": "markdown", 698 | "metadata": {}, 699 | "source": [ 700 | "If Python is in your path, you should be able to run python from your command prompt as follows: ![](https://cdn.rawgit.com/gbrunner/Python_for_GIS_and_RS/master/Week_2/images/command_prompt.png)\n", 701 | "\n", 702 | "If it's not, we can add Python to our system path as follows.\n", 703 | "1. Go to your system properties.![](https://cdn.rawgit.com/gbrunner/Python_for_GIS_and_RS/master/Week_2/images/sys_properties.png)\n", 704 | "\n", 705 | "2. Open your environment variables.![](https://cdn.rawgit.com/gbrunner/Python_for_GIS_and_RS/master/Week_2/images/env_variables.png)\n", 706 | "\n", 707 | "3. Select Path and click 'Edit'.![](https://cdn.rawgit.com/gbrunner/Python_for_GIS_and_RS/master/Week_2/images/edit_vars.png)\n", 708 | "\n", 709 | "4. Add the location of the python.exe file (usually something like C:\\Python27\\ArcGIS10.3\\python.exe) to your path.\n", 710 | "\n", 711 | "Now, you should be able to type 'python' at the command prompt and enter a python session. " 712 | ] 713 | }, 714 | { 715 | "cell_type": "markdown", 716 | "metadata": {}, 717 | "source": [ 718 | "## Getting User Input" 719 | ] 720 | }, 721 | { 722 | "cell_type": "markdown", 723 | "metadata": {}, 724 | "source": [ 725 | "A common way for python scripts to take user input is to use the sys module. In the Week 2 materials, you should see a addition.py file. The only code in that file is the following." 726 | ] 727 | }, 728 | { 729 | "cell_type": "code", 730 | "execution_count": null, 731 | "metadata": {}, 732 | "outputs": [], 733 | "source": [ 734 | "import sys\n", 735 | "\n", 736 | "var1 = int(sys.argv[1])\n", 737 | "var2 = int(sys.argv[2])\n", 738 | "\n", 739 | "print('The answer is ' + str(var1+var2))" 740 | ] 741 | }, 742 | { 743 | "cell_type": "markdown", 744 | "metadata": { 745 | "collapsed": true 746 | }, 747 | "source": [ 748 | "If this code is run at the command line as follows.![](https://cdn.rawgit.com/gbrunner/Python_for_GIS_and_RS/master/Week_2/images/addition.png)\n", 749 | "\n", 750 | "Notice that the command line arguments get entered immediately after the script name and they are separated by spaces. Try is out!" 751 | ] 752 | }, 753 | { 754 | "cell_type": "markdown", 755 | "metadata": {}, 756 | "source": [ 757 | "## Guidenlines for Python Coding" 758 | ] 759 | }, 760 | { 761 | "cell_type": "markdown", 762 | "metadata": {}, 763 | "source": [ 764 | "First things first:" 765 | ] 766 | }, 767 | { 768 | "cell_type": "code", 769 | "execution_count": null, 770 | "metadata": {}, 771 | "outputs": [], 772 | "source": [ 773 | "import this" 774 | ] 775 | }, 776 | { 777 | "cell_type": "markdown", 778 | "metadata": {}, 779 | "source": [ 780 | "Take these recommendations into account while coding!\n", 781 | "\n", 782 | "Additionally, Python has what is called [PEP 8 - Style Guide for Python Code](https://www.python.org/dev/peps/pep-0008/). The '8' is becuase this is version 8. Let's check it out. Not every recommendation here is madatory, but they should definately be considered best pratices." 783 | ] 784 | } 785 | ], 786 | "metadata": { 787 | "anaconda-cloud": {}, 788 | "kernelspec": { 789 | "display_name": "Python 3", 790 | "language": "python", 791 | "name": "python3" 792 | }, 793 | "language_info": { 794 | "codemirror_mode": { 795 | "name": "ipython", 796 | "version": 3 797 | }, 798 | "file_extension": ".py", 799 | "mimetype": "text/x-python", 800 | "name": "python", 801 | "nbconvert_exporter": "python", 802 | "pygments_lexer": "ipython3", 803 | "version": "3.6.9" 804 | } 805 | }, 806 | "nbformat": 4, 807 | "nbformat_minor": 1 808 | } 809 | -------------------------------------------------------------------------------- /Unit 10/README.md: -------------------------------------------------------------------------------- 1 | # Watch these videos 2 | - [ArcGIS API for Python: Introduction to Scripting your Web GIS](https://www.youtube.com/watch?v=WSXzlpVZM50) 3 | - [ArcGIS Python API for Administrators and Content Publishers](https://www.youtube.com/watch?v=4AzOodYTHs4) 4 | 5 | # This weeks notebooks 6 | This weeks notebooks are in ArcGIs Online at 7 | [GIS 4090\5090 Unit 10 Notebooks](https://slustl.maps.arcgis.com/home/group.html?id=dd378276497c4d9994ffc50be5c15d8d#overview) 8 | 9 | We will use the same datasets that we used last week. 10 | 11 | # Lecture 12 | 13 | ## Let's take a step back... 14 | 1. Searching Content in AGOL 15 | 2. Renderers and Publishing a CSV 16 | 17 | ## Administering ArcGIS Online 18 | 1. Go to ArcGIS Online. 19 | 2. Show users the *Overview* tab. 20 | 3. Show users the *Members* tab. 21 | 4. Show *Licenses*, *Status*, and *Settings* tabs. 22 | 5. Go to user: Gregory Brunner 23 | 6. Show students options to change on their personal user info. 24 | 7. Show students *Groups*. 25 | 8. Create a new *Group*. 26 | 9. Invite the students. 27 | 10. Add Content to the *Group*. 28 | 29 | # ArcGIS API for Python 30 | To learn more about the ArcGIS API for Python, go to https://developers.arcgis.com/python/ 31 | 32 | # ArcGIS API for Python Samples 33 | To see more samples of how to use the ArcGIS API for Python go to https://developers.arcgis.com/python/sample-notebooks/ 34 | 35 | # Unit 10 Exercise and Discussion Questions 36 | ## Problem 1 37 | Create a new Jupyter Notebook or ArcGIS Notebook that: 38 | 1. Contains a map 39 | 2. Zooms to a particular city of interest 40 | 3. Changes the basemap from the default Terrain basemap 41 | 4. Please use Markdown to apply meaningful descriptions of your steps. 42 | 5. Contains at least 3 layers, not including the basemap 43 | 44 | ## Problem 2 45 | 2. Using the ArcGIS API for Python and following from the examples in class, geocode the addresses in the addresses.csv. Add them to a map. Save the map as a webmap. What is the common theme among the addresses? 46 | 47 | Attached Files: 48 | 49 | File addresses.csv Click for more options (438 B) 50 | -------------------------------------------------------------------------------- /Unit 10/addresses.csv: -------------------------------------------------------------------------------- 1 | Single Line Address 2 | "470 E Lockwood Ave, Webster Groves, MO 63119" 3 | "1 Brookings Dr, St. Louis, MO 63130" 4 | "1 N Grand Blvd, St. Louis, MO 63103" 5 | "1 Hairpin Dr, Edwardsville, IL 62026" 6 | "1263 Lincoln Dr, Carbondale, IL 62901" 7 | "1 University Blvd, St. Louis, MO 63121" 8 | "5000 Holmes St, Kansas City, MO 64110" 9 | "6823 St Charles Ave, New Orleans, LA 70118" 10 | "300 College Park, Dayton, OH 45469" 11 | "2807 N Glebe Rd, Arlington, VA 22207" 12 | -------------------------------------------------------------------------------- /Unit 11/README.md: -------------------------------------------------------------------------------- 1 | # This week's lectures 2 | This week's lecture notebooks can be found in 3 | ArcGIS Online at [GIS 4090\5090 Unit 11 Notebooks](https://slustl.maps.arcgis.com/home/group.html?id=b3d8431a10c64970b43e4ff59dd083d6#overview) 4 | 5 | # Data for this week 6 | Here are a few datasets that we will use this week: 7 | 8 | File Thunder_Departures_gjb.csv Click for more options (1.215 KB) 9 | File Thunder_Acquisitions_gjb.csv Click for more options (1.304 KB) 10 | File STL_Crime_gjb.gdb.zip Click for more options (640.133 KB) 11 | File STL_Crime_1.gdb.zip Click for more options (640.133 KB) 12 | File nbrhds_wards_demo1.zip Click for more options (179.985 KB) 13 | File national_rainfall_data_demogjb.zip Click for more options (992.424 KB) 14 | 15 | # Supplemental materials 16 | If you are new to hex codes and colors, you can learn more on [the colorwheel](https://www.colorspire.com/rgb-color-wheel/). 17 | 18 | # Unit 11 Exercise and Discussion Questions 19 | Please complete the following for homework: 20 | 1. For context, [read this tutorial on Adding Spreadsheet data to ArcGIS Online.](https://www.esri.com/arcgis-blog/products/arcgis-online/data-management/add-spreadsheet-data-to-arcgis-online/) 21 | 2. Optionally, [watch the videos in Symbolize Data and Publish Maps.](https://learn.arcgis.com/en/paths/symbolize-data-and-publish-maps/) 22 | 3. Download the attached CSVs. Rename them to "Thunder_Departed_" followed by 23 | your initials and ".csv" and "Thunder_Acquisitions_" followed by your initials 24 | and ".csv". Create a notebook that geocodes those CSVs of addresses and adds 25 | each to the same map object with a different symbology 26 | (see [this tutorial](https://developers.arcgis.com/python/sample-notebooks/publishing-sd-shapefiles-and-csv/#Publish-a-CSV-file-and-move-it-into-a-folder) 27 | if you need help). Save this as a webmap following from [this 28 | example](https://developers.arcgis.com/python/guide/working-with-web-maps-and-web-scenes/#Saving-or-Updating-a-web-map). 29 | Be sure to go to ArcGIS online and check that the Webmap is there! 30 | 31 | **Hint:** You can change the symbology by changing the renderer. 32 | For example, if you change the color values in this renderer, the points will 33 | change color accordingly. 34 | 35 | simple_renderer = { 36 | "renderer": { 37 | "type": "simple", 38 | "symbol": { 39 | "color": [ 40 | 0, 41 | 0, 42 | 128, 43 | 128 44 | ], 45 | "size": 15, 46 | "angle": 0, 47 | "xoffset": 0, 48 | "yoffset": 0, 49 | "type": "esriSMS", 50 | "style": "esriSMSCircle", 51 | "outline": { 52 | "color": [ 53 | 0, 54 | 0, 55 | 128, 56 | 255 57 | ], 58 | "width": 0.99975, 59 | "type": "esriSLS", 60 | "style": "esriSLSSolid" 61 | } 62 | } 63 | } 64 | } 65 | 66 | map1.add_layer(acled, simple_renderer) -------------------------------------------------------------------------------- /Unit 11/STL_Crime_1.gdb.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gbrunner/programming-for-gis-and-rs/e623312548ca5807730f37e625a304ca93e6c36e/Unit 11/STL_Crime_1.gdb.zip -------------------------------------------------------------------------------- /Unit 11/STL_Crime_gjb.gdb.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gbrunner/programming-for-gis-and-rs/e623312548ca5807730f37e625a304ca93e6c36e/Unit 11/STL_Crime_gjb.gdb.zip -------------------------------------------------------------------------------- /Unit 11/Thunder_Acquisitions_gjb.csv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gbrunner/programming-for-gis-and-rs/e623312548ca5807730f37e625a304ca93e6c36e/Unit 11/Thunder_Acquisitions_gjb.csv -------------------------------------------------------------------------------- /Unit 11/Thunder_Departures_gjb.csv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gbrunner/programming-for-gis-and-rs/e623312548ca5807730f37e625a304ca93e6c36e/Unit 11/Thunder_Departures_gjb.csv -------------------------------------------------------------------------------- /Unit 11/national_rainfall_data_demogjb.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gbrunner/programming-for-gis-and-rs/e623312548ca5807730f37e625a304ca93e6c36e/Unit 11/national_rainfall_data_demogjb.zip -------------------------------------------------------------------------------- /Unit 11/nbrhds_wards_demo1.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gbrunner/programming-for-gis-and-rs/e623312548ca5807730f37e625a304ca93e6c36e/Unit 11/nbrhds_wards_demo1.zip -------------------------------------------------------------------------------- /Unit 12/Lecture 2 - Intro to Spatial Dataframes (Feature to CSV in Lat and Longitude).ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Remember that Crime CSV file we used to make a webapp earlier in the semester?" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "## Let's import the SpatialDataFrame" 15 | ] 16 | }, 17 | { 18 | "cell_type": "code", 19 | "execution_count": 5, 20 | "metadata": {}, 21 | "outputs": [], 22 | "source": [ 23 | "import arcgis\n", 24 | "from arcgis.features import GeoAccessor as ga" 25 | ] 26 | }, 27 | { 28 | "cell_type": "markdown", 29 | "metadata": {}, 30 | "source": [ 31 | "## We can read a feature class directly into a Dataframe" 32 | ] 33 | }, 34 | { 35 | "cell_type": "code", 36 | "execution_count": 6, 37 | "metadata": {}, 38 | "outputs": [], 39 | "source": [ 40 | "#Or C:\\Users\\greg6750\\Documents\\IPython Notebooks\\Advanced_Python_for_GIS_and_RS\\Week 9\\crime_data.gdb\\STL_CRIME_POINTS_CopyFeature1\n", 41 | "sdf = ga.from_featureclass(\n", 42 | " r\"crime_data.gdb\\STL_CRIME_POINTS_CopyFeature1\"\n", 43 | ")" 44 | ] 45 | }, 46 | { 47 | "cell_type": "markdown", 48 | "metadata": {}, 49 | "source": [ 50 | "## Let's look at the first 5 Values in the dataframe" 51 | ] 52 | }, 53 | { 54 | "cell_type": "code", 55 | "execution_count": 7, 56 | "metadata": {}, 57 | "outputs": [ 58 | { 59 | "data": { 60 | "text/html": [ 61 | "
\n", 62 | "\n", 75 | "\n", 76 | " \n", 77 | " \n", 78 | " \n", 79 | " \n", 80 | " \n", 81 | " \n", 82 | " \n", 83 | " \n", 84 | " \n", 85 | " \n", 86 | " \n", 87 | " \n", 88 | " \n", 89 | " \n", 90 | " \n", 91 | " \n", 92 | " \n", 93 | " \n", 94 | " \n", 95 | " \n", 96 | " \n", 97 | " \n", 98 | " \n", 99 | " \n", 100 | " \n", 101 | " \n", 102 | " \n", 103 | " \n", 104 | " \n", 105 | " \n", 106 | " \n", 107 | " \n", 108 | " \n", 109 | " \n", 110 | " \n", 111 | " \n", 112 | " \n", 113 | " \n", 114 | " \n", 115 | " \n", 116 | " \n", 117 | " \n", 118 | " \n", 119 | " \n", 120 | " \n", 121 | " \n", 122 | " \n", 123 | " \n", 124 | " \n", 125 | " \n", 126 | " \n", 127 | " \n", 128 | " \n", 129 | " \n", 130 | " \n", 131 | " \n", 132 | " \n", 133 | " \n", 134 | " \n", 135 | " \n", 136 | " \n", 137 | " \n", 138 | " \n", 139 | " \n", 140 | " \n", 141 | " \n", 142 | " \n", 143 | " \n", 144 | " \n", 145 | " \n", 146 | " \n", 147 | " \n", 148 | " \n", 149 | " \n", 150 | " \n", 151 | " \n", 152 | " \n", 153 | " \n", 154 | " \n", 155 | " \n", 156 | " \n", 157 | " \n", 158 | " \n", 159 | " \n", 160 | " \n", 161 | " \n", 162 | " \n", 163 | " \n", 164 | " \n", 165 | " \n", 166 | " \n", 167 | " \n", 168 | " \n", 169 | " \n", 170 | " \n", 171 | " \n", 172 | " \n", 173 | " \n", 174 | " \n", 175 | " \n", 176 | " \n", 177 | " \n", 178 | " \n", 179 | " \n", 180 | " \n", 181 | " \n", 182 | " \n", 183 | " \n", 184 | " \n", 185 | " \n", 186 | " \n", 187 | " \n", 188 | " \n", 189 | " \n", 190 | " \n", 191 | " \n", 192 | " \n", 193 | " \n", 194 | " \n", 195 | " \n", 196 | " \n", 197 | " \n", 198 | " \n", 199 | " \n", 200 | " \n", 201 | " \n", 202 | " \n", 203 | " \n", 204 | " \n", 205 | " \n", 206 | " \n", 207 | " \n", 208 | " \n", 209 | " \n", 210 | " \n", 211 | " \n", 212 | " \n", 213 | " \n", 214 | " \n", 215 | " \n", 216 | " \n", 217 | " \n", 218 | " \n", 219 | " \n", 220 | " \n", 221 | " \n", 222 | " \n", 223 | " \n", 224 | "
OBJECTIDComplaintCodedMonthDateOccurFlagCrimeFlagUnfoundedFlagAdministrativeCountFlagCleanupCrime...ILEADSAddressILEADSStreetNeighborhoodLocationNameLocationCommentCADAddressCADStreetXCoordYCoordSHAPE
0116-0602252016-112013-01-01 09:37:00YNoneNone1None115400...6111.0MICHIGAN AVE1NoneNone6111.0MICHIGAN892049.5992992.3{'x': -90.24875893499996, 'y': 38.560418371000...
1216-0568492016-112016-01-30 10:00:00YNoneNone1None65701...0.0HORNSBY AVE / NEWBY ST74NoneNone992.0RIVERVIEW895706.01050752.0{'x': -90.23538879799997, 'y': 38.718992161000...
2316-0598162016-112016-02-03 00:01:00YNoneNone1None121000...3915.0OLIVE ST38NoneNone3915.0OLIVE894624.91022655.0{'x': -90.23945786399997, 'y': 38.641849847000...
3416-0591702016-112011-02-04 00:01:00YNoneNone1None43025...3761.0MERAMEC ST16NoneNone3756.0MERAMEC892275.91001225.0{'x': -90.24788817199999, 'y': 38.583023065000...
4516-0573452016-112010-03-07 00:01:00YNoneNone1None43026...3927.0CHIPPEWA ST15NoneNone3927.0CHIPPEWA890901.71003595.0{'x': -90.25267325099998, 'y': 38.589541155000...
\n", 225 | "

5 rows × 22 columns

\n", 226 | "
" 227 | ], 228 | "text/plain": [ 229 | " OBJECTID Complaint CodedMonth DateOccur FlagCrime FlagUnfounded \\\n", 230 | "0 1 16-060225 2016-11 2013-01-01 09:37:00 Y None \n", 231 | "1 2 16-056849 2016-11 2016-01-30 10:00:00 Y None \n", 232 | "2 3 16-059816 2016-11 2016-02-03 00:01:00 Y None \n", 233 | "3 4 16-059170 2016-11 2011-02-04 00:01:00 Y None \n", 234 | "4 5 16-057345 2016-11 2010-03-07 00:01:00 Y None \n", 235 | "\n", 236 | " FlagAdministrative Count FlagCleanup Crime ... ILEADSAddress \\\n", 237 | "0 None 1 None 115400 ... 6111.0 \n", 238 | "1 None 1 None 65701 ... 0.0 \n", 239 | "2 None 1 None 121000 ... 3915.0 \n", 240 | "3 None 1 None 43025 ... 3761.0 \n", 241 | "4 None 1 None 43026 ... 3927.0 \n", 242 | "\n", 243 | " ILEADSStreet Neighborhood LocationName LocationComment \\\n", 244 | "0 MICHIGAN AVE 1 None None \n", 245 | "1 HORNSBY AVE / NEWBY ST 74 None None \n", 246 | "2 OLIVE ST 38 None None \n", 247 | "3 MERAMEC ST 16 None None \n", 248 | "4 CHIPPEWA ST 15 None None \n", 249 | "\n", 250 | " CADAddress CADStreet XCoord YCoord \\\n", 251 | "0 6111.0 MICHIGAN 892049.5 992992.3 \n", 252 | "1 992.0 RIVERVIEW 895706.0 1050752.0 \n", 253 | "2 3915.0 OLIVE 894624.9 1022655.0 \n", 254 | "3 3756.0 MERAMEC 892275.9 1001225.0 \n", 255 | "4 3927.0 CHIPPEWA 890901.7 1003595.0 \n", 256 | "\n", 257 | " SHAPE \n", 258 | "0 {'x': -90.24875893499996, 'y': 38.560418371000... \n", 259 | "1 {'x': -90.23538879799997, 'y': 38.718992161000... \n", 260 | "2 {'x': -90.23945786399997, 'y': 38.641849847000... \n", 261 | "3 {'x': -90.24788817199999, 'y': 38.583023065000... \n", 262 | "4 {'x': -90.25267325099998, 'y': 38.589541155000... \n", 263 | "\n", 264 | "[5 rows x 22 columns]" 265 | ] 266 | }, 267 | "execution_count": 7, 268 | "metadata": {}, 269 | "output_type": "execute_result" 270 | } 271 | ], 272 | "source": [ 273 | "sdf.head()" 274 | ] 275 | }, 276 | { 277 | "cell_type": "markdown", 278 | "metadata": {}, 279 | "source": [ 280 | "## Notice the Columns in the dataframe align with the attribute table of the feature class\n", 281 | "\n", 282 | "Show this in ArcGIS Pro." 283 | ] 284 | }, 285 | { 286 | "cell_type": "markdown", 287 | "metadata": {}, 288 | "source": [ 289 | "## We can export this to a CSV file" 290 | ] 291 | }, 292 | { 293 | "cell_type": "code", 294 | "execution_count": 9, 295 | "metadata": {}, 296 | "outputs": [], 297 | "source": [ 298 | "#change the name of this\n", 299 | "sdf.to_csv(path_or_buf=r\"test.csv\")" 300 | ] 301 | }, 302 | { 303 | "cell_type": "markdown", 304 | "metadata": {}, 305 | "source": [] 306 | }, 307 | { 308 | "cell_type": "markdown", 309 | "metadata": {}, 310 | "source": [ 311 | "## For this CSV to work with the webapp, the coordinates had to be in Latitude and Longitude. I had to convert that SHAPE JSON into Latitude and Longitude coordinates.\n", 312 | "\n", 313 | "This code effectively strips out the x and y values from the JSON and puts them into new pandas dataframe columns named Lon and Lat." 314 | ] 315 | }, 316 | { 317 | "cell_type": "code", 318 | "execution_count": 34, 319 | "metadata": {}, 320 | "outputs": [ 321 | { 322 | "data": { 323 | "text/html": [ 324 | "
\n", 325 | "\n", 338 | "\n", 339 | " \n", 340 | " \n", 341 | " \n", 342 | " \n", 343 | " \n", 344 | " \n", 345 | " \n", 346 | " \n", 347 | " \n", 348 | " \n", 349 | " \n", 350 | " \n", 351 | " \n", 352 | " \n", 353 | " \n", 354 | " \n", 355 | " \n", 356 | " \n", 357 | " \n", 358 | " \n", 359 | " \n", 360 | " \n", 361 | " \n", 362 | " \n", 363 | " \n", 364 | " \n", 365 | " \n", 366 | " \n", 367 | " \n", 368 | " \n", 369 | " \n", 370 | " \n", 371 | " \n", 372 | " \n", 373 | " \n", 374 | " \n", 375 | " \n", 376 | " \n", 377 | " \n", 378 | " \n", 379 | " \n", 380 | " \n", 381 | " \n", 382 | " \n", 383 | " \n", 384 | " \n", 385 | " \n", 386 | " \n", 387 | " \n", 388 | " \n", 389 | " \n", 390 | " \n", 391 | " \n", 392 | " \n", 393 | " \n", 394 | " \n", 395 | " \n", 396 | " \n", 397 | " \n", 398 | " \n", 399 | " \n", 400 | " \n", 401 | " \n", 402 | " \n", 403 | " \n", 404 | " \n", 405 | " \n", 406 | " \n", 407 | " \n", 408 | " \n", 409 | " \n", 410 | " \n", 411 | " \n", 412 | " \n", 413 | " \n", 414 | " \n", 415 | " \n", 416 | " \n", 417 | " \n", 418 | " \n", 419 | " \n", 420 | " \n", 421 | " \n", 422 | " \n", 423 | " \n", 424 | " \n", 425 | " \n", 426 | " \n", 427 | " \n", 428 | " \n", 429 | " \n", 430 | " \n", 431 | " \n", 432 | " \n", 433 | " \n", 434 | " \n", 435 | " \n", 436 | " \n", 437 | " \n", 438 | " \n", 439 | " \n", 440 | " \n", 441 | " \n", 442 | " \n", 443 | " \n", 444 | " \n", 445 | " \n", 446 | " \n", 447 | " \n", 448 | " \n", 449 | " \n", 450 | " \n", 451 | " \n", 452 | " \n", 453 | " \n", 454 | " \n", 455 | " \n", 456 | " \n", 457 | " \n", 458 | " \n", 459 | " \n", 460 | " \n", 461 | " \n", 462 | " \n", 463 | " \n", 464 | " \n", 465 | " \n", 466 | " \n", 467 | " \n", 468 | " \n", 469 | " \n", 470 | " \n", 471 | " \n", 472 | " \n", 473 | " \n", 474 | " \n", 475 | " \n", 476 | " \n", 477 | " \n", 478 | " \n", 479 | " \n", 480 | " \n", 481 | " \n", 482 | " \n", 483 | " \n", 484 | " \n", 485 | " \n", 486 | " \n", 487 | "
OBJECTIDComplaintCodedMonthDateOccurFlagCrimeFlagUnfoundedFlagAdministrativeCountFlagCleanupCrime...NeighborhoodLocationNameLocationCommentCADAddressCADStreetXCoordYCoordSHAPELonLat
0116-0602252016-112013-01-01 09:37:00YNoneNone1None115400...1NoneNone6111.0MICHIGAN892049.5992992.3{'x': -90.24875893499996, 'y': 38.560418371000...-90.24875938.560418
1216-0568492016-112016-01-30 10:00:00YNoneNone1None65701...74NoneNone992.0RIVERVIEW895706.01050752.0{'x': -90.23538879799997, 'y': 38.718992161000...-90.23538938.718992
2316-0598162016-112016-02-03 00:01:00YNoneNone1None121000...38NoneNone3915.0OLIVE894624.91022655.0{'x': -90.23945786399997, 'y': 38.641849847000...-90.23945838.641850
3416-0591702016-112011-02-04 00:01:00YNoneNone1None43025...16NoneNone3756.0MERAMEC892275.91001225.0{'x': -90.24788817199999, 'y': 38.583023065000...-90.24788838.583023
4516-0573452016-112010-03-07 00:01:00YNoneNone1None43026...15NoneNone3927.0CHIPPEWA890901.71003595.0{'x': -90.25267325099998, 'y': 38.589541155000...-90.25267338.589541
\n", 488 | "

5 rows × 24 columns

\n", 489 | "
" 490 | ], 491 | "text/plain": [ 492 | " OBJECTID Complaint CodedMonth DateOccur FlagCrime FlagUnfounded \\\n", 493 | "0 1 16-060225 2016-11 2013-01-01 09:37:00 Y None \n", 494 | "1 2 16-056849 2016-11 2016-01-30 10:00:00 Y None \n", 495 | "2 3 16-059816 2016-11 2016-02-03 00:01:00 Y None \n", 496 | "3 4 16-059170 2016-11 2011-02-04 00:01:00 Y None \n", 497 | "4 5 16-057345 2016-11 2010-03-07 00:01:00 Y None \n", 498 | "\n", 499 | " FlagAdministrative Count FlagCleanup Crime ... Neighborhood \\\n", 500 | "0 None 1 None 115400 ... 1 \n", 501 | "1 None 1 None 65701 ... 74 \n", 502 | "2 None 1 None 121000 ... 38 \n", 503 | "3 None 1 None 43025 ... 16 \n", 504 | "4 None 1 None 43026 ... 15 \n", 505 | "\n", 506 | " LocationName LocationComment CADAddress CADStreet XCoord YCoord \\\n", 507 | "0 None None 6111.0 MICHIGAN 892049.5 992992.3 \n", 508 | "1 None None 992.0 RIVERVIEW 895706.0 1050752.0 \n", 509 | "2 None None 3915.0 OLIVE 894624.9 1022655.0 \n", 510 | "3 None None 3756.0 MERAMEC 892275.9 1001225.0 \n", 511 | "4 None None 3927.0 CHIPPEWA 890901.7 1003595.0 \n", 512 | "\n", 513 | " SHAPE Lon Lat \n", 514 | "0 {'x': -90.24875893499996, 'y': 38.560418371000... -90.248759 38.560418 \n", 515 | "1 {'x': -90.23538879799997, 'y': 38.718992161000... -90.235389 38.718992 \n", 516 | "2 {'x': -90.23945786399997, 'y': 38.641849847000... -90.239458 38.641850 \n", 517 | "3 {'x': -90.24788817199999, 'y': 38.583023065000... -90.247888 38.583023 \n", 518 | "4 {'x': -90.25267325099998, 'y': 38.589541155000... -90.252673 38.589541 \n", 519 | "\n", 520 | "[5 rows x 24 columns]" 521 | ] 522 | }, 523 | "execution_count": 34, 524 | "metadata": {}, 525 | "output_type": "execute_result" 526 | } 527 | ], 528 | "source": [ 529 | "#x = []\n", 530 | "#y = []\n", 531 | "for idx,val in enumerate(sdf.iterrows()):\n", 532 | " #print(val[1].SHAPE)\n", 533 | " j = val[1].SHAPE\n", 534 | " #x.append(j['x'])\n", 535 | " #y.append(j['y'])\n", 536 | " sdf.loc[idx,'Lon'] = j['x']\n", 537 | " sdf.loc[idx,'Lat'] = j['y']\n", 538 | " \n", 539 | "#sdf['Lon'] = x\n", 540 | "#sdf['Lat'] = y\n", 541 | "sdf.head()" 542 | ] 543 | }, 544 | { 545 | "cell_type": "code", 546 | "execution_count": null, 547 | "metadata": {}, 548 | "outputs": [], 549 | "source": [] 550 | }, 551 | { 552 | "cell_type": "markdown", 553 | "metadata": {}, 554 | "source": [ 555 | "## Now I can save that dataframe to a CSV with a subset of fields" 556 | ] 557 | }, 558 | { 559 | "cell_type": "code", 560 | "execution_count": 35, 561 | "metadata": {}, 562 | "outputs": [], 563 | "source": [ 564 | "sdf.to_csv(\n", 565 | " path_or_buf=r\"stl_crime_wgs_84_10282018.csv\", \n", 566 | " columns=['Crime', 'District', 'Neighborhood', 'ILEADSStreet', 'CADStreet', 'Lon', 'Lat']\n", 567 | ")" 568 | ] 569 | }, 570 | { 571 | "cell_type": "markdown", 572 | "metadata": {}, 573 | "source": [ 574 | "## This is cool, but..." 575 | ] 576 | }, 577 | { 578 | "cell_type": "code", 579 | "execution_count": null, 580 | "metadata": {}, 581 | "outputs": [], 582 | "source": [] 583 | } 584 | ], 585 | "metadata": { 586 | "kernelspec": { 587 | "display_name": "Python 3", 588 | "language": "python", 589 | "name": "python3" 590 | }, 591 | "language_info": { 592 | "codemirror_mode": { 593 | "name": "ipython", 594 | "version": 3 595 | }, 596 | "file_extension": ".py", 597 | "mimetype": "text/x-python", 598 | "name": "python", 599 | "nbconvert_exporter": "python", 600 | "pygments_lexer": "ipython3", 601 | "version": "3.6.9" 602 | } 603 | }, 604 | "nbformat": 4, 605 | "nbformat_minor": 2 606 | } 607 | -------------------------------------------------------------------------------- /Unit 12/README.md: -------------------------------------------------------------------------------- 1 | # This week's notebooks 2 | This week's lecture notebooks are in ArcGIS Online at 3 | [GIS 4090\5090 Unit 12 Notebooks](https://slustl.maps.arcgis.com/home/group.html?id=87bd11b5636a470db344bb2cc6bb03ef#overview) 4 | 5 | You can also find older versions of these notebooks here: 6 | 7 | File Lecture 4 - plotting_with_plotly.ipynb Click for more options (3.502 MB) 8 | File matplotlib_styles.ipynb Click for more options (1.509 KB) 9 | File Lecture 1 - Matplotlib.ipynb Click for more options (71.808 KB) 10 | File Lecture 2 - Intro to Spatial Dataframes (Feature to CSV in Lat and Longitude).ipynb Click for more options (19.769 KB) 11 | File Lecture 3 - CSV to Spatial DataFrame to GIS Data.ipynb Click for more options (64.365 KB) 12 | 13 | # Data for lectures 14 | The following CSV and GDB are used for the lecture demos: 15 | 16 | File SENZA_0_SUNAA_0_CORN.xlsx Click for more options (426.275 KB) 17 | File crime_data.gdb.zip Click for more options (639.273 KB) 18 | 19 | # Potting Resources 20 | These are resources from the [Python Data Science Handbook](https://jakevdp.github.io/PythonDataScienceHandbook/): 21 | - [Matplotlib](https://jakevdp.github.io/PythonDataScienceHandbook/04.00-introduction-to-matplotlib.html) 22 | - [Line Plots](https://jakevdp.github.io/PythonDataScienceHandbook/04.01-simple-line-plots.html) 23 | - [Scatter Plots](https://jakevdp.github.io/PythonDataScienceHandbook/04.02-simple-scatter-plots.html) 24 | 25 | # Homework 26 | ## Final Project Status Update 27 | In this discussion forum, please give the class an update on where you are 28 | with your final project. Please include a paragraph that summarize your 29 | status. Feel free to share any links, data, screen shots, or notebooks 30 | that you are willing to share or looking for feedback on. 31 | 32 | Please comment on two of your classmate posts. 33 | 34 | Start by clicking "Create Thread". 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /Unit 12/SENZA_0_SUNAA_0_CORN.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gbrunner/programming-for-gis-and-rs/e623312548ca5807730f37e625a304ca93e6c36e/Unit 12/SENZA_0_SUNAA_0_CORN.xlsx -------------------------------------------------------------------------------- /Unit 12/crime_data.gdb.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gbrunner/programming-for-gis-and-rs/e623312548ca5807730f37e625a304ca93e6c36e/Unit 12/crime_data.gdb.zip -------------------------------------------------------------------------------- /Unit 12/matplotlib_styles.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# https://matplotlib.org/tutorials/introductory/customizing.html" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": 2, 13 | "metadata": {}, 14 | "outputs": [], 15 | "source": [ 16 | "from matplotlib import pyplot as plt" 17 | ] 18 | }, 19 | { 20 | "cell_type": "code", 21 | "execution_count": 3, 22 | "metadata": {}, 23 | "outputs": [ 24 | { 25 | "name": "stdout", 26 | "output_type": "stream", 27 | "text": [ 28 | "['bmh', 'classic', 'dark_background', 'fast', 'fivethirtyeight', 'ggplot', 'grayscale', 'seaborn-bright', 'seaborn-colorblind', 'seaborn-dark-palette', 'seaborn-dark', 'seaborn-darkgrid', 'seaborn-deep', 'seaborn-muted', 'seaborn-notebook', 'seaborn-paper', 'seaborn-pastel', 'seaborn-poster', 'seaborn-talk', 'seaborn-ticks', 'seaborn-white', 'seaborn-whitegrid', 'seaborn', 'Solarize_Light2', 'tableau-colorblind10', '_classic_test']\n" 29 | ] 30 | } 31 | ], 32 | "source": [ 33 | "print(plt.style.available)" 34 | ] 35 | }, 36 | { 37 | "cell_type": "code", 38 | "execution_count": null, 39 | "metadata": {}, 40 | "outputs": [], 41 | "source": [] 42 | } 43 | ], 44 | "metadata": { 45 | "kernelspec": { 46 | "display_name": "Python 3", 47 | "language": "python", 48 | "name": "python3" 49 | }, 50 | "language_info": { 51 | "codemirror_mode": { 52 | "name": "ipython", 53 | "version": 3 54 | }, 55 | "file_extension": ".py", 56 | "mimetype": "text/x-python", 57 | "name": "python", 58 | "nbconvert_exporter": "python", 59 | "pygments_lexer": "ipython3", 60 | "version": "3.6.9" 61 | } 62 | }, 63 | "nbformat": 4, 64 | "nbformat_minor": 4 65 | } 66 | -------------------------------------------------------------------------------- /Unit 13/README.md: -------------------------------------------------------------------------------- 1 | # Watch this video 2 | [ArcGIS API for JavaScript: Getting Started](https://www.youtube.com/watch?v=pYHWoSNsSIU) 3 | 4 | # Check out ArcGIS JSAPI Samples 5 | [ArcGIS API for JavaScript Sample Code](https://developers.arcgis.com/javascript/latest/sample-code/) 6 | 7 | # Learn JS using Esri Hackerlabs 8 | These have not been updated in three or four years, but they used to be awesome. [Check out 9 | the hackerlabs](https://github.com/Esri/geodev-hackerlabs) 10 | 11 | # CodePen.io 12 | If you continue with the Advanced course next semester, you will learn JavaScript. 13 | We will use [CodePen.io](https://codepen.io/) as a tool to write and test code. 14 | 15 | # Web Mapping Development Intro 16 | 17 | Jacob Wasilkowski 18 | 19 | [Twitter @JWasilGeo](https://twitter.com/JWasilGeo) 20 | 21 | [https://jwasilgeo.github.io](https://jwasilgeo.github.io) 22 | 23 | ## Intro to HTML, CSS, and JavaScript 24 | 25 | What's the purpose of each and how do they work together? 26 | 27 | READ :clap: THE :clap: DOCS :clap: 28 | 29 | [https://developer.mozilla.org/en-US/docs/Web](https://developer.mozilla.org/en-US/docs/Web) 30 | 31 | ## JavaScript: syntax intro 32 | 33 | ```javascript 34 | // variable declaration 35 | let myString; 36 | 37 | // and then later assignment 38 | myString = 'sample string'; 39 | 40 | // variable declaration and assignment at same time 41 | let myNumber = 90210; 42 | 43 | console.log(myNumber - 90209); // simple math 44 | 45 | // strings 46 | let question = 'Is pizza awesome?'; 47 | let answer = 'Without a doubt.'; 48 | let qAndA = question + ' ' + answer; // concatenate strings 49 | 50 | console.log(qAndA); 51 | 52 | // format with template strings 53 | console.log(`${question} ${answer}`); 54 | 55 | // booleans 56 | console.log(1.5 === 1.5); // true 57 | console.log(1 + 1 === 3); // false 58 | 59 | // arrays 60 | let myArray = [1, 2, 3, 'x', 'y', 'z']; 61 | 62 | console.log(myArray[3]); 63 | 64 | myArray.push(100); 65 | 66 | let stringFromArray = myArray.join(' and '); 67 | 68 | console.log(stringFromArray); 69 | 70 | // functions 71 | let sumThreeNumbers = function(a, b, c) { 72 | // do something with the function arguments 73 | console.log(a, b, c); 74 | // return the sum 75 | return a + b + c; 76 | }; 77 | 78 | // objects 79 | let myObject = { 80 | name: 'Greg', 81 | totalCats: 15, 82 | faveLanguages: ['Python', 'JavaScript'], 83 | isInCharge: true, 84 | tellMeSomethingInteresting: function() { 85 | return this.name + ' has ' + this.totalCats + ' cats.' 86 | } 87 | }; 88 | 89 | console.log(myObject.name); 90 | 91 | console.log(myObject.tellMeSomethingInteresting()); 92 | 93 | // conditional statements 94 | let whatHappened; 95 | if (1 === 2) { 96 | whatHappened = 'bad math'; 97 | } else if (true && false) { 98 | whatHappened = 'bad logic'; 99 | } else { 100 | whatHappened = 'we got to the "else!"'; 101 | } 102 | console.log(whatHappened); 103 | ``` 104 | 105 | **Start thinking in terms of user interaction _"events"_ instead of top-to-bottom script execution.** 106 | 107 | Obligatory JS meme 108 | 109 | ![JS meme](https://pbs.twimg.com/media/B-SjB7XIcAAoOzU.jpg) 110 | 111 | ## HTML and CSS and JavaScript 112 | 113 | **Exercise:** create `index.html` page, insert ` 204 | 205 | 206 | 207 | ``` 208 | 209 | ## Let's get mappy in the browser 210 | 211 | - Intros to [ArcGIS API for JavaScript](https://js.arcgis.com) and [LeafletJS](https://leafletjs.com/) 212 | 213 | - Getting started with [CodePen](https://codepen.io) 214 | 215 | - Why? Your browser will block functionality if browsing files directly from hard drive. You must use a web server. CodePen is interactive and easy to experiment with, just like Python Notebooks. 216 | 217 | - **Leaflet exercise** 218 | 219 | 1. Copy and paste the contents of `leaflet-demo.html` into a new CodePen. 220 | 221 | 2. Set the map's initial position to be centered at and zoomed to St. Louis. 222 | 223 | 3. Change the basemap to a [different Esri basemap](https://esri.github.io/esri-leaflet/api-reference/layers/basemap-layer.html). 224 | 225 | 4. Add a ["marker" positioned at SLU](https://leafletjs.com/examples/quick-start/#markers-circles-and-polygons) onto the map. 226 | 227 | - **Esri exercise** 228 | 229 | 1. Copy and paste the contents of `esri-demo.html` into a new CodePen. 230 | 231 | 2. Make the Esri demo into 3D! You can instruct the code to use a [`SceneView`](https://developers.arcgis.com/javascript/latest/api-reference/esri-views-SceneView.html) instead of a `MapView`. 232 | 233 | ## Resources 234 | 235 | - ["Maps in JS" presentation by Gavin Rehkemper](https://github.com/gavinr/presentations/tree/master/src/maps-in-js) 236 | 237 | - [ArcGIS API for JavaScript](https://js.arcgis.com) 238 | 239 | - [LeafletJS](https://leafletjs.com/) (and optionally the [Esri-Leaflet plugin](https://esri.github.io/esri-leaflet/)) 240 | 241 | - ["JavaScript: The Good Parts", Douglas Crockford (2008)](http://lib.slu.edu/) 242 | - A must-read which will go by quickly! It is available at SLU Libraries...you don't really have a good excuse to avoid this book. 243 | 244 | - [The Modern JavaScript Tutorial](https://javascript.info/) 245 | 246 | - [JavaScript for Cats](http://jsforcats.com/) :cat2: :cat: :cat2: 247 | 248 | - [Mozilla Dev Network: JavaScript](https://developer.mozilla.org/en-US/docs/Web/JavaScript) 249 | 250 | - [Mozilla Dev Network: A re-introduction to JavaScript (JS tutorial)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re-introduction_to_JavaScript) 251 | 252 | - [DevDocs.io](https://devdocs.io/) 253 | 254 | 255 | # Optional Unit 13 Assignment 256 | This is optional, but the students who complete it 257 | tell me that they got a lot out of it. If you want to learn more about Javascript and the 258 | ArcGIS JSAPI, complete the following two lessons: 259 | 1. [Create a starter app](https://developers.arcgis.com/javascript/latest/display-a-map/) 260 | 2. [Add layers to a map](https://developers.arcgis.com/javascript/latest/add-a-feature-layer/) 261 | 262 | Copy and past the code into text files and submit the text files. 263 | -------------------------------------------------------------------------------- /Unit 14/README.md: -------------------------------------------------------------------------------- 1 | # This week's notebooks 2 | You can find this week's notebooks on ArcGIS Online at [GIS 4090\5090 Unit 14 Notebooks](https://slustl.maps.arcgis.com/home/group.html?id=8924b798d1884dd1b86d9f3ec73e13fe#overviewIS%204090\5090) 3 | 4 | # Data for lecture 5 | The data used for this week's lecture is on [Google drive](https://drive.google.com/drive/folders/1AS3YMuziY7qHe8KA_8UGUpqqJJt0kxiF) 6 | 7 | # Beyond basic Python 8 | - [Advanced Programming for GIS and Remote Sensing](https://github.com/gbrunner/adv-programming-for-gis-and-rs) 9 | - [Learning Anaconda](https://www.youtube.com/watch?v=23aQdrS58e0) 10 | - [Learning JavaScript](https://www.youtube.com/watch?v=pYHWoSNsSIU) 11 | - [Leaflet](https://leafletjs.com/examples.html) 12 | - [ArcGIS API for JavaScript](https://developers.arcgis.com/javascript/latest/showcase/) 13 | 14 | # Multidimmensional Data and Scientific Data 15 | In this lecture we will discuss multidimmensional data. We will learn how you can interact with it through ArcGIS Pro, arcpy, and [xarray](http://xarray.pydata.org/en/stable/) and different kinds of analysis that can be done agaist spatio-temporal scientific datasets. 16 | 17 | This week, we will use the [DAYMET monthly climate summary NetCDF datasets](https://daac.ornl.gov/DAYMET/guides/Daymet_V3_Monthly_Climatology.html) 18 | 19 | # Preparation 20 | 1. [Multidimensional Data](https://www.esri.com/arcgis-blog/products/arcgis-pro/imagery/multidimensional-analysis-arcgis-pro/) and [Multidimmensional Analysis in ArcGIS Pro](https://youtu.be/qBACfb2sMo8) 21 | 2. [Python: Working with Multidimensional Scientific Data](https://www.esri.com/videos/watch?videoid=lqKYoiFlCJc) 22 | 3. [Xarray](https://www.youtube.com/watch?v=Dgr_d8iEWk4) 23 | 24 | # Lecture 1 - Multidimensional Data in ArcGIS Pro 25 | 1. Create a new ArcGIS Pro Map Project 26 | 2. Add Data 27 | 3. Choose Multidimensional Raster Layer and then add **daymet_v3_tmin_monavg_2017_na.nc4***. 28 | ![](https://github.com/gbrunner/developing-with-imagery/blob/master/Week%205/add_multidim_raster_layer.png?raw=true) 29 | 30 | 4. Notice how th data gets added with a time-slider in the view. 31 | ![](https://github.com/gbrunner/developing-with-imagery/blob/master/Week%205/multidim_raster_layer.png?raw=true) 32 | 33 | 5. Right click on layer in Table of Contents. **Select Create Chart** -> **Temporal Profile** 34 | 6. Set chart parameters. 35 | 7. Choose **Point** for **Area of Interest** and click on map to see temperature profile. 36 | ![](https://github.com/gbrunner/developing-with-imagery/blob/master/Week%205/temp_profiles.png?raw=true) 37 | 38 | 8. Export Raster as CRF. We will use this as input into the arcpy API. 39 | 40 | # Lecture 2 - Multidimensional Data with Arcpy 41 | Demonstrate how we can use **Raster** objects using the **arcpy API** to do similar analysis. This can be demonstrated through the [**multidimensional_data_using_arcpy_api.ipynb**](https://github.com/gbrunner/developing-with-imagery/blob/master/Week%205/multidimensional_data_using_arcpy_api.ipynb) Notebook. 42 | 43 | # Lecture 3 - Multidimensional Data with Xarray 44 | You can use xarray, an open source Python library to work with multidimensional data. For those of you who are fluent at Python, numpy, and pandas, you will probably like xarray. I will not cover every detail of the Python library, but I will go through how to work with NetDCF files in the [multidimensional_data_using_xarray.ipynb](https://github.com/gbrunner/developing-with-imagery/blob/master/Week%205/multidimensional_data_using_xarray.ipynb) Notebook. 45 | 46 | # Lecture 4 (if there is enough time) - Multidimensional Data in Python Raster Functions 47 | The same techniques that we used last week to create raster functions with Landsat can be applied to Multidimensional NetCDF data. If there is enough time, we can discuss this. 48 | 49 | # Exercise 50 | 1. Run through the ArcGIS Tutorial on [Multidimensional raster analysis in ArcGIS Pro](https://doc.arcgis.com/en/imagery/workflows/tutorials/multidimensional-raster-analysis-in-arcgis-pro.htm?adumkts=product&adupro=ArcGIS_Image_Analyst&aduc=social&adum=external&utm_Source=social&aduca=Imagery&RemoteSensing&adulb=multiple&adusn=multiple&aduat=blog&sf_id=701f2000000rpWvAAI) 51 | 52 | # Challenges 53 | 1. Create a mosaic dataset from all of the **DAYMET** NetCDF files in the **tmax** folder. Using the mosaic dataset, crreate temporal charts showing the tempertature change over time from beginning of the dataset to the end for the cities of New York, Houston, Minneapolis, and Los Angeles. Do you notice any trend in the profiles other than the seasonality? **Submit the plots as graphics.** They can be saved out of ArcGIS Pro as graphics. 54 | 55 | 2. Using the arcpy API, use the mosaic dataset that you creates and create a temperature profile using Python over Houston, TX. **Submit your Notebook.** You can get the pixel values using ```arcpy.GetCellValue_management()```, for example: 56 | ``` 57 | for i in range(12): 58 | out_raster_subset = arcpy.ia.Subset(myRaster, 59 | variables='tmin', 60 | dimension_definitions = {'stdTime': myRaster.getDimensionValues('tmin', 'StdTime')[i]}) 61 | 62 | print(arcpy.GetCellValue_management(out_raster_subset, location_point="0 0")) 63 | ``` 64 | 65 | 3. Using **xarray** and the [multidimensional_data_with_xarray.ipynb](https://github.com/gbrunner/developing-with-imagery/blob/master/Week%205/multidimensional_data_using_xarray.ipynb) Notebook as a template, create a temperature profile over a specific location for at least 3 years from the **tmin** data. Wich approach to you like more, ArcGIS Pro, arcpy, or xarray? **Submit your notebook**. If you are bold, install **dask** and try to load the datasets using the following code. 66 | ``` 67 | # OR multiple files - this require DASK 68 | mfdataDIR = '../data/ARM/twparmbeatmC1.c1.*.000000.cdf' 69 | DS = xr.open_mfdataset(mfdataDIR) 70 | ``` 71 | 72 | # Interesting Links 73 | 74 | [DAYMET Climate Data](https://daac.ornl.gov/cgi-bin/dataset_lister.pl?p=32) 75 | 76 | [Digital Earth Africa](https://www.africageoportal.com/pages/digital-earth-africa) 77 | 78 | -------------------------------------------------------------------------------- /Unit 15/README.md: -------------------------------------------------------------------------------- 1 | This week, students will present their final projects. Please try to keep your presentations to 2 | under five minutes. -------------------------------------------------------------------------------- /Unit 2/README.md: -------------------------------------------------------------------------------- 1 | # This Week's Reading 2 | 3 | Please read Chapters 2 and 3 of [Python Scripting for ArcGIS Pro](https://esripress.esri.com/display/index.cfm?fuseaction=display&websiteID=384&moduleID=12). 4 | These two chapters cover Python IDEs and Geoprocessing in ArcGIS Pro. 5 | This will set a foundation for much of what we do. 6 | 7 | # Presentations 8 | Here are the slides introducing geoprocessing and the Python Window in ArcGIS Pro. 9 | Attached Files: 10 | 11 | File Lecture_1_Geoprocessing_and_Python_Window.pptx Click for more options (2.341 MB) 12 | 13 | # Data and Notebooks 14 | This week's lecture notebooks can be found 15 | at on ArcGIS Online in the [ 16 | GIS 4090\5090 Unit 2 Notebooks](https://slustl.maps.arcgis.com/home/group.html?id=724c1bfb085843debf8f1020b3654045#overview). 17 | 18 | There is an [ArcGIS Pro package](https://slustl.maps.arcgis.com/home/item.html?id=3179070f893247d6bc7be395ee9ff9c8) there that you can download that 19 | I will use for the lecture. 20 | 21 | I also plan to use the [blocks_shape](https://slustl.maps.arcgis.com/home/item.html?id=f9d83ef4e16b4eae862cf0301b59ae2e) data there. 22 | Attached Files: 23 | 24 | File unit_2_lesson_1_geoprocessing_in_arcgis_pro.ipynb Click for more options (8.834 KB) 25 | File unit_2_lesson_1_geoprocessing_in_arcmap.ipynb Click for more options (8.57 KB) 26 | File unit_2_lesson_2_arcpy_in_arcgis_notebooks.ipynb Click for more options (26.66 KB) 27 | File unit_2_lesson_2_arcpy_in_arcgis_pro.ipynb Click for more options (21.771 KB) 28 | File unit_1_lesson_2_more_python.ipynb Click for more options (19.851 KB) 29 | File Missouri.gdb.zip Click for more options (10.712 MB) 30 | 31 | 32 | # Last Year's Week 2 Lecture Recording 33 | Last year's Week 2 lectures: 34 | 35 | Part 1: https://slu.hosted.panopto.com/Panopto/Pages/Viewer.aspx?id=d4e94b2a-8e89-47c0-bd5e-ab4f016ea1f8 36 | Part 2: https://slu.hosted.panopto.com/Panopto/Pages/Viewer.aspx?id=fc541dcd-68e9-4a2c-8f7a-ab4f017f8ed7 37 | Part 3: https://slu.hosted.panopto.com/Panopto/Pages/Viewer.aspx?id=81b0afd2-d392-4713-8f09-ab50000572f1 38 | 39 | # Unit 2 Exercise and Discussion Questions 40 | ## Exercise 41 | Please complete the following exercises. 42 | You do not need to submit anything, but it is recommended that you complete these. 43 | 44 | - [Getting Started with Python in ArcGIS Pro](https://learn.arcgis.com/en/projects/get-started-with-python-in-arcgis-pro/) 45 | - [Please Complete Python Scripting Exercise 3](https://learngis.maps.arcgis.com/home/item.html?id=3978b52f1e5847c69ef7eaded85780b2). You can find the data [here](https://learngis.maps.arcgis.com/home/item.html?id=d7c05cf515c046c2bedacb2e8e24722c). 46 | - [(Optional) Beginner's guide to Python in ArcGIS Pro, Part 3: Tutorial](https://www.esri.com/arcgis-blog/products/arcgis-pro/uncategorized/beginners-guide-to-python-in-arcgis-pro-part-3-tutorial/) 47 | - (Optional) Please run through the ArcGIS Notebook sample for [Forest-based Classification: Predict asthma rates.](https://slustl.maps.arcgis.com/home/item.html?id=56f418e2fd4f4030917d048fd87c078f) 48 | This is both an exelent example of how to work with ```arcpy``` in ArcGIS Notebooks and using GIS to perform predictive analysis 49 | 50 | ## Questions 51 | Please submit a text file or word document answering the following questions. 52 | 53 | 54 | What does IDE stand for? 55 | What is the extension of a Python script file? 56 | What is the extension of a Jupyter notebook (or ArcGIS Notebook) file? Hint: Download an ArcGIS Notebook. 57 | 58 | 59 | # Unit 2 Assignment 60 | Attached Files: 61 | 62 | File blocks_shape.zip Click for more options (6.165 MB) 63 | 64 | Following from today's lecture, I want you to perform the same analysis in 65 | two different ways: 66 | 1. In the ArcGIS Pro Python Window, find the number of St. Louis City blocks that are found 67 | in the blocks shapefile (blocks.shp) using [get count](https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/get-count.htm). 68 | Then, create a [minimum bounding geometry](https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/minimum-bounding-geometry.htm) 69 | polygon of the same blocks shapefile. 70 | 2. Add that polygon to the map, take a screenshot, and submit the screenshot. 71 | Using an ArcGIS Notebook, perform the same analysis. First, unzip the blocks_shape.zip. 72 | Upload all of the files from blocks.zip to the ArcGIS Notebooks Files 73 | so that it looks similar to this: 74 | ![](blocks_files.png) 75 | 76 | In the ArcGIS Notebook, find the number of St. Louis City blocks that are found 77 | in the blocks shapefile (blocks.shp) using get count. 78 | Then, create a minimum bounding geometry polygon of the same blocks shapefile. 79 | Submit a link to the notebook. 80 | 81 | If you can't get this working in an ArcGIS Notebook, 82 | try doing this using Jupyter on your local computer. 83 | 84 | 85 | -------------------------------------------------------------------------------- /Unit 2/blocks_files.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gbrunner/programming-for-gis-and-rs/e623312548ca5807730f37e625a304ca93e6c36e/Unit 2/blocks_files.png -------------------------------------------------------------------------------- /Unit 2/unit_1_lesson_2_more_python.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# More Python Fundamentals" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "In these excercises, we will address more of what I consider Python fundamentals." 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "## File Paths" 22 | ] 23 | }, 24 | { 25 | "cell_type": "markdown", 26 | "metadata": {}, 27 | "source": [ 28 | "File paths in Python can seem very peculiar to newcomers to programming. Typically, we see a filpath represented as something like C:\\Documents\\my_document.docx. In Python, we can not just reference a file this way. Let's walk through the 3 ways we can reference file names in Python using the week 1 or week 2 excercise data." 29 | ] 30 | }, 31 | { 32 | "cell_type": "code", 33 | "execution_count": null, 34 | "metadata": { 35 | "collapsed": true 36 | }, 37 | "outputs": [], 38 | "source": [ 39 | "input_fc = \"C:\\\\Users\\\\greg6750\\\\Documents\\\\IPython Notebooks\\\\Python_for_GIS_and_RS\\\\Week_1\\\\data\\\\Missouri.gdb\\\\County\"" 40 | ] 41 | }, 42 | { 43 | "cell_type": "markdown", 44 | "metadata": {}, 45 | "source": [ 46 | "Let's print out input_fc to see how Python interprets that." 47 | ] 48 | }, 49 | { 50 | "cell_type": "code", 51 | "execution_count": null, 52 | "metadata": {}, 53 | "outputs": [], 54 | "source": [ 55 | "print(input_fc)" 56 | ] 57 | }, 58 | { 59 | "cell_type": "markdown", 60 | "metadata": {}, 61 | "source": [ 62 | "Notice that Python has removed the double backslashes. Rather than using double backslashes, we could use single forward slashes as follows." 63 | ] 64 | }, 65 | { 66 | "cell_type": "code", 67 | "execution_count": null, 68 | "metadata": { 69 | "collapsed": true 70 | }, 71 | "outputs": [], 72 | "source": [ 73 | "input_fc = \"C:/Users/greg6750/Documents/IPython Notebooks/Python_for_GIS_and_RS/Week_1/data/Missouri.gdb/County\"" 74 | ] 75 | }, 76 | { 77 | "cell_type": "markdown", 78 | "metadata": {}, 79 | "source": [ 80 | "Now, when we print that out we see that Python shows a single forward slash." 81 | ] 82 | }, 83 | { 84 | "cell_type": "code", 85 | "execution_count": null, 86 | "metadata": {}, 87 | "outputs": [], 88 | "source": [ 89 | "print(input_fc)" 90 | ] 91 | }, 92 | { 93 | "cell_type": "markdown", 94 | "metadata": {}, 95 | "source": [ 96 | "The final way to reference file path is by placeing the letter _r_ in front of the string. This indicates to Python that the single backslash not be read as an escape character." 97 | ] 98 | }, 99 | { 100 | "cell_type": "code", 101 | "execution_count": null, 102 | "metadata": { 103 | "collapsed": true 104 | }, 105 | "outputs": [], 106 | "source": [ 107 | "input_fc = r\"C:\\Users\\greg6750\\Documents\\IPython Notebooks\\Python_for_GIS_and_RS\\Week_1\\data\\Missouri.gdb\\County\"" 108 | ] 109 | }, 110 | { 111 | "cell_type": "markdown", 112 | "metadata": {}, 113 | "source": [ 114 | "Now, when we print this string out, we should see single backslashes." 115 | ] 116 | }, 117 | { 118 | "cell_type": "code", 119 | "execution_count": null, 120 | "metadata": {}, 121 | "outputs": [], 122 | "source": [ 123 | "print(input_fc)" 124 | ] 125 | }, 126 | { 127 | "cell_type": "markdown", 128 | "metadata": {}, 129 | "source": [ 130 | "## Modules" 131 | ] 132 | }, 133 | { 134 | "cell_type": "markdown", 135 | "metadata": { 136 | "collapsed": true 137 | }, 138 | "source": [ 139 | "Modules are functionality that can be imported into Python to extend its capabilities. Here, we will import and examine a few modules that we will use in the future." 140 | ] 141 | }, 142 | { 143 | "cell_type": "code", 144 | "execution_count": null, 145 | "metadata": { 146 | "collapsed": true 147 | }, 148 | "outputs": [], 149 | "source": [ 150 | "import arcpy" 151 | ] 152 | }, 153 | { 154 | "cell_type": "markdown", 155 | "metadata": {}, 156 | "source": [ 157 | "Let's see what version of arcpy we're using." 158 | ] 159 | }, 160 | { 161 | "cell_type": "code", 162 | "execution_count": null, 163 | "metadata": {}, 164 | "outputs": [], 165 | "source": [ 166 | "arcpy.GetInstallInfo()" 167 | ] 168 | }, 169 | { 170 | "cell_type": "markdown", 171 | "metadata": {}, 172 | "source": [ 173 | "## Question 1: What is the version number of arcpy?" 174 | ] 175 | }, 176 | { 177 | "cell_type": "markdown", 178 | "metadata": {}, 179 | "source": [ 180 | "You can also print out the help for each function using the __doc__ command. Let's see what the ArcGIS Documentation says about the [Clip function](http://pro.arcgis.com/en/pro-app/tool-reference/analysis/clip.htm)" 181 | ] 182 | }, 183 | { 184 | "cell_type": "code", 185 | "execution_count": null, 186 | "metadata": {}, 187 | "outputs": [], 188 | "source": [ 189 | "arcpy.Clip_analysis.__doc__" 190 | ] 191 | }, 192 | { 193 | "cell_type": "markdown", 194 | "metadata": {}, 195 | "source": [ 196 | "We can also list out all of the functions within the arcpy library using the __dir__ command." 197 | ] 198 | }, 199 | { 200 | "cell_type": "code", 201 | "execution_count": null, 202 | "metadata": {}, 203 | "outputs": [], 204 | "source": [ 205 | "dir(arcpy)" 206 | ] 207 | }, 208 | { 209 | "cell_type": "markdown", 210 | "metadata": {}, 211 | "source": [ 212 | "We can count the number of functions in the arcpy module using the __len__ function," 213 | ] 214 | }, 215 | { 216 | "cell_type": "code", 217 | "execution_count": null, 218 | "metadata": {}, 219 | "outputs": [], 220 | "source": [ 221 | "len(dir(arcpy))" 222 | ] 223 | }, 224 | { 225 | "cell_type": "markdown", 226 | "metadata": {}, 227 | "source": [ 228 | "## Question 2: How many functions are there in arcpy?" 229 | ] 230 | }, 231 | { 232 | "cell_type": "markdown", 233 | "metadata": {}, 234 | "source": [ 235 | "Another module that we'll be using is the _time_ module. This will help us track how long processes take to run, how to manipulate strings that contain time or data information, and much more. Let's import _time_." 236 | ] 237 | }, 238 | { 239 | "cell_type": "code", 240 | "execution_count": null, 241 | "metadata": { 242 | "collapsed": true 243 | }, 244 | "outputs": [], 245 | "source": [ 246 | "import time" 247 | ] 248 | }, 249 | { 250 | "cell_type": "markdown", 251 | "metadata": {}, 252 | "source": [ 253 | "We can get the locatime using this time object module." 254 | ] 255 | }, 256 | { 257 | "cell_type": "code", 258 | "execution_count": null, 259 | "metadata": {}, 260 | "outputs": [], 261 | "source": [ 262 | "time.localtime()" 263 | ] 264 | }, 265 | { 266 | "cell_type": "markdown", 267 | "metadata": {}, 268 | "source": [ 269 | "This function returned a tuple containing year, month, day, hour, min, sec, etc. describing the local time. An easier way to represent time would be as asctime." 270 | ] 271 | }, 272 | { 273 | "cell_type": "code", 274 | "execution_count": null, 275 | "metadata": {}, 276 | "outputs": [], 277 | "source": [ 278 | "time.asctime()" 279 | ] 280 | }, 281 | { 282 | "cell_type": "markdown", 283 | "metadata": {}, 284 | "source": [ 285 | "## Conditoinal Statements" 286 | ] 287 | }, 288 | { 289 | "cell_type": "markdown", 290 | "metadata": {}, 291 | "source": [ 292 | "Conditional statements, also knows as if/else statements, are common to all programming languages. COnditional statements evaluate data, and make a decision based on the result. Let's write a few if/else statements.\n", 293 | "\n", 294 | "Python has a module called _random_ which can be used to generate random numbers. Here we can similate a coinflip using random. Import random." 295 | ] 296 | }, 297 | { 298 | "cell_type": "code", 299 | "execution_count": null, 300 | "metadata": { 301 | "collapsed": true 302 | }, 303 | "outputs": [], 304 | "source": [ 305 | "import random" 306 | ] 307 | }, 308 | { 309 | "cell_type": "markdown", 310 | "metadata": {}, 311 | "source": [ 312 | "We can generate a random number that is either 1 or 2 using the _randint_ function. If the number is 1, we say the number is odd. If the number is 2 we say the number is even. Try the following code." 313 | ] 314 | }, 315 | { 316 | "cell_type": "code", 317 | "execution_count": null, 318 | "metadata": {}, 319 | "outputs": [], 320 | "source": [ 321 | "random_val = random.randint(1, 2)\n", 322 | "if random_val == 1:\n", 323 | " print(str(random_val) + \" is Odd\")\n", 324 | "else: \n", 325 | " print(str(random_val) + \" is Even\")" 326 | ] 327 | }, 328 | { 329 | "cell_type": "markdown", 330 | "metadata": {}, 331 | "source": [ 332 | "Let's write a conditional statement that evaluates a list of data. Type and execute the following code." 333 | ] 334 | }, 335 | { 336 | "cell_type": "code", 337 | "execution_count": null, 338 | "metadata": {}, 339 | "outputs": [], 340 | "source": [ 341 | "data = [1,2,3,4,5,6,7,8,9,10]\n", 342 | "for val in data:\n", 343 | " if val % 2 == 0:\n", 344 | " print(val,\"No remainder\") # the % sign is the modulus operator and tests for a remainder\n", 345 | " elif val % 3 == 2:\n", 346 | " print(val,\"Remainder of Two\")\n", 347 | " else:\n", 348 | " print(\"Final Case\")" 349 | ] 350 | }, 351 | { 352 | "cell_type": "markdown", 353 | "metadata": {}, 354 | "source": [ 355 | "COnditional statements are very powerful. You will be using the a lot! [Check out this site to learn more about the comparison operators and logical operators n Python](https://www.tutorialspoint.com/python/python_basic_operators.htm)" 356 | ] 357 | }, 358 | { 359 | "cell_type": "markdown", 360 | "metadata": {}, 361 | "source": [ 362 | "## Loops" 363 | ] 364 | }, 365 | { 366 | "cell_type": "markdown", 367 | "metadata": {}, 368 | "source": [ 369 | "### While Loops" 370 | ] 371 | }, 372 | { 373 | "cell_type": "markdown", 374 | "metadata": {}, 375 | "source": [ 376 | "Truth be told, I never use while loops! This might actually be the first one I've written in Python. This is because I find _for_ loops and conditional statements more intuitive. That being said, let's take our random number generator example and run it 10 times using a while loop and see what answers we get." 377 | ] 378 | }, 379 | { 380 | "cell_type": "code", 381 | "execution_count": null, 382 | "metadata": {}, 383 | "outputs": [], 384 | "source": [ 385 | "import random\n", 386 | "\n", 387 | "i = 1\n", 388 | "while i <= 10:\n", 389 | " random_val = random.randint(1, 2)\n", 390 | " if random_val == 1:\n", 391 | " print(\"Trial \" + str(i) + \": \" + str(random_val) + \" is Odd\")\n", 392 | " else: \n", 393 | " print(\"Trial \" + str(i) + \": \" + str(random_val) + \" is Even\")\n", 394 | " i += 1" 395 | ] 396 | }, 397 | { 398 | "cell_type": "markdown", 399 | "metadata": {}, 400 | "source": [ 401 | "## Question 3: How many odd and how many even results did you get over 10 Trials?" 402 | ] 403 | }, 404 | { 405 | "cell_type": "markdown", 406 | "metadata": {}, 407 | "source": [ 408 | "In the example above, the trials are run while the value of _i_ is less than 10. Once the 10th trial is hit, Python exits out of the loop." 409 | ] 410 | }, 411 | { 412 | "cell_type": "markdown", 413 | "metadata": {}, 414 | "source": [ 415 | "### For Loops" 416 | ] 417 | }, 418 | { 419 | "cell_type": "markdown", 420 | "metadata": {}, 421 | "source": [ 422 | "Like I mentioned above, I prefer using for loops to while loops. For loops repeat parts of your code but are not tied to a specific condition. We will encounter for loops throughout our programming careers and understanding them will be key to your growth as a programmer or developer. Let's write a few for loops." 423 | ] 424 | }, 425 | { 426 | "cell_type": "code", 427 | "execution_count": null, 428 | "metadata": { 429 | "collapsed": true 430 | }, 431 | "outputs": [], 432 | "source": [ 433 | "top_five = [\"Patriots\", \"Seahawks\", \"Cowboys\", \"Chiefs\", \"Steelers\"]" 434 | ] 435 | }, 436 | { 437 | "cell_type": "markdown", 438 | "metadata": {}, 439 | "source": [ 440 | "Here we've created a list of the top 5 teams in the NFL (hypothetical). We can print out each team name using a for loop." 441 | ] 442 | }, 443 | { 444 | "cell_type": "code", 445 | "execution_count": null, 446 | "metadata": {}, 447 | "outputs": [], 448 | "source": [ 449 | "for team in top_five:\n", 450 | " print(team)" 451 | ] 452 | }, 453 | { 454 | "cell_type": "markdown", 455 | "metadata": {}, 456 | "source": [ 457 | "We can print out each team name in all caps using the _upper_ function." 458 | ] 459 | }, 460 | { 461 | "cell_type": "code", 462 | "execution_count": null, 463 | "metadata": {}, 464 | "outputs": [], 465 | "source": [ 466 | "for team in top_five:\n", 467 | " print(team.upper())" 468 | ] 469 | }, 470 | { 471 | "cell_type": "markdown", 472 | "metadata": {}, 473 | "source": [ 474 | "A practical application of for loops is that we can list all datasets in a folder or geodatabase. Packaged in the Week 2 folder we have a census dataset. Let's import the census dataset using arcpy and list all of the feature classes in the census geodatabase. " 475 | ] 476 | }, 477 | { 478 | "cell_type": "code", 479 | "execution_count": null, 480 | "metadata": {}, 481 | "outputs": [], 482 | "source": [ 483 | "import arcpy\n", 484 | "\n", 485 | "arcpy.env.workspace = r'C:\\Users\\greg6750\\Documents\\IPython Notebooks\\Python_for_GIS_and_RS\\Week_2\\data\\tlgdb_2016_a_44_ri.gdb'\n", 486 | "\n", 487 | "fcs = arcpy.ListFeatureClasses()\n", 488 | "\n", 489 | "for fc in fcs:\n", 490 | " print(fc)" 491 | ] 492 | }, 493 | { 494 | "cell_type": "markdown", 495 | "metadata": {}, 496 | "source": [ 497 | "Here, we imported arcpy. We set the arcpy environment to be the census geodatabase. We used ListFeatureClasses to create a list of feature classes in the geodatabase, and we printed out the names of each feature class. We can also print out the number of features in the geodatabase." 498 | ] 499 | }, 500 | { 501 | "cell_type": "code", 502 | "execution_count": null, 503 | "metadata": {}, 504 | "outputs": [], 505 | "source": [ 506 | "print(len(fcs))" 507 | ] 508 | }, 509 | { 510 | "cell_type": "markdown", 511 | "metadata": {}, 512 | "source": [ 513 | "## Question 4: How many feature classes are in that geodatabase?" 514 | ] 515 | }, 516 | { 517 | "cell_type": "markdown", 518 | "metadata": {}, 519 | "source": [ 520 | "## OS" 521 | ] 522 | }, 523 | { 524 | "cell_type": "markdown", 525 | "metadata": {}, 526 | "source": [ 527 | "The [_os_ module](https://docs.python.org/2/library/os.html) allows Python users to interact with their computer's operating system. This includes accessing directories, files, and other data on the OS. It is a library that you will use very often to find files, move files, create file path, and more. Here, we'll introduce you to a few ways to use OS." 528 | ] 529 | }, 530 | { 531 | "cell_type": "code", 532 | "execution_count": null, 533 | "metadata": { 534 | "collapsed": true 535 | }, 536 | "outputs": [], 537 | "source": [ 538 | "import os" 539 | ] 540 | }, 541 | { 542 | "cell_type": "markdown", 543 | "metadata": {}, 544 | "source": [ 545 | "Let's take one of the filenames that we've used above." 546 | ] 547 | }, 548 | { 549 | "cell_type": "code", 550 | "execution_count": null, 551 | "metadata": { 552 | "collapsed": true 553 | }, 554 | "outputs": [], 555 | "source": [ 556 | "missouri_gdb = r\"C:\\Users\\greg6750\\Documents\\IPython Notebooks\\Python_for_GIS_and_RS\\Week_1\\data\\Missouri.gdb\"" 557 | ] 558 | }, 559 | { 560 | "cell_type": "markdown", 561 | "metadata": {}, 562 | "source": [ 563 | "We can use os to split that path into geodatabase and the path to the geodatabase as follows:" 564 | ] 565 | }, 566 | { 567 | "cell_type": "code", 568 | "execution_count": null, 569 | "metadata": {}, 570 | "outputs": [], 571 | "source": [ 572 | "os.path.basename(missouri_gdb) #returns the geodatabase" 573 | ] 574 | }, 575 | { 576 | "cell_type": "code", 577 | "execution_count": null, 578 | "metadata": {}, 579 | "outputs": [], 580 | "source": [ 581 | "os.path.dirname(missouri_gdb) #returns the directory" 582 | ] 583 | }, 584 | { 585 | "cell_type": "markdown", 586 | "metadata": {}, 587 | "source": [ 588 | "You could also use:" 589 | ] 590 | }, 591 | { 592 | "cell_type": "code", 593 | "execution_count": null, 594 | "metadata": {}, 595 | "outputs": [], 596 | "source": [ 597 | "path, gdb = os.path.split(missouri_gdb)\n", 598 | "print(path) #returns the path\n", 599 | "print(gdb) #returns the geodatabase" 600 | ] 601 | }, 602 | { 603 | "cell_type": "markdown", 604 | "metadata": {}, 605 | "source": [ 606 | "Another cool function in _os_ is _walk_. Walk can be used to list all of the files in a directory. Choose a directory on your machine and try it!" 607 | ] 608 | }, 609 | { 610 | "cell_type": "code", 611 | "execution_count": null, 612 | "metadata": {}, 613 | "outputs": [], 614 | "source": [ 615 | "folder = r'C:\\Users\\greg6750\\Documents\\IPython Notebooks\\Python_for_GIS_and_RS\\Week_1'\n", 616 | "for (path, dirs, files) in os.walk(folder):\n", 617 | " print(path)\n", 618 | " print(dirs)\n", 619 | " print(files)" 620 | ] 621 | }, 622 | { 623 | "cell_type": "markdown", 624 | "metadata": {}, 625 | "source": [ 626 | "This should list everything you find in the folder, including subsolders!" 627 | ] 628 | }, 629 | { 630 | "cell_type": "markdown", 631 | "metadata": {}, 632 | "source": [ 633 | "## SYS" 634 | ] 635 | }, 636 | { 637 | "cell_type": "markdown", 638 | "metadata": {}, 639 | "source": [ 640 | "The [_sys_ module](https://docs.python.org/2/library/sys.html) provides access to some variables used or maintained by the interpreter and to functions that interact strongly with the interpreter. Here, we'll learn a few common ways that you might use _sys_." 641 | ] 642 | }, 643 | { 644 | "cell_type": "code", 645 | "execution_count": null, 646 | "metadata": { 647 | "collapsed": true 648 | }, 649 | "outputs": [], 650 | "source": [ 651 | "import sys" 652 | ] 653 | }, 654 | { 655 | "cell_type": "markdown", 656 | "metadata": {}, 657 | "source": [ 658 | "You can use _sys.path_ to look at your Windows path variable." 659 | ] 660 | }, 661 | { 662 | "cell_type": "code", 663 | "execution_count": null, 664 | "metadata": {}, 665 | "outputs": [], 666 | "source": [ 667 | "print(sys.path)" 668 | ] 669 | }, 670 | { 671 | "cell_type": "markdown", 672 | "metadata": {}, 673 | "source": [ 674 | "We can search for Python in our system path variable. If it is in there, we should be able to execute python from the Windows command prompt." 675 | ] 676 | }, 677 | { 678 | "cell_type": "code", 679 | "execution_count": null, 680 | "metadata": {}, 681 | "outputs": [], 682 | "source": [ 683 | "path = sys.path\n", 684 | "for element in path:\n", 685 | " if 'python' in element:\n", 686 | " print(\"Python is in our Path variable!\")" 687 | ] 688 | }, 689 | { 690 | "cell_type": "markdown", 691 | "metadata": {}, 692 | "source": [ 693 | "## Question 5: Is Python in your path variable?" 694 | ] 695 | }, 696 | { 697 | "cell_type": "markdown", 698 | "metadata": {}, 699 | "source": [ 700 | "If Python is in your path, you should be able to run python from your command prompt as follows: ![](https://cdn.rawgit.com/gbrunner/Python_for_GIS_and_RS/master/Week_2/images/command_prompt.png)\n", 701 | "\n", 702 | "If it's not, we can add Python to our system path as follows.\n", 703 | "1. Go to your system properties.![](https://cdn.rawgit.com/gbrunner/Python_for_GIS_and_RS/master/Week_2/images/sys_properties.png)\n", 704 | "\n", 705 | "2. Open your environment variables.![](https://cdn.rawgit.com/gbrunner/Python_for_GIS_and_RS/master/Week_2/images/env_variables.png)\n", 706 | "\n", 707 | "3. Select Path and click 'Edit'.![](https://cdn.rawgit.com/gbrunner/Python_for_GIS_and_RS/master/Week_2/images/edit_vars.png)\n", 708 | "\n", 709 | "4. Add the location of the python.exe file (usually something like C:\\Python27\\ArcGIS10.3\\python.exe) to your path.\n", 710 | "\n", 711 | "Now, you should be able to type 'python' at the command prompt and enter a python session. " 712 | ] 713 | }, 714 | { 715 | "cell_type": "markdown", 716 | "metadata": {}, 717 | "source": [ 718 | "## Getting User Input" 719 | ] 720 | }, 721 | { 722 | "cell_type": "markdown", 723 | "metadata": {}, 724 | "source": [ 725 | "A common way for python scripts to take user input is to use the sys module. In the Week 2 materials, you should see a addition.py file. The only code in that file is the following." 726 | ] 727 | }, 728 | { 729 | "cell_type": "code", 730 | "execution_count": null, 731 | "metadata": {}, 732 | "outputs": [], 733 | "source": [ 734 | "import sys\n", 735 | "\n", 736 | "var1 = int(sys.argv[1])\n", 737 | "var2 = int(sys.argv[2])\n", 738 | "\n", 739 | "print('The answer is ' + str(var1+var2))" 740 | ] 741 | }, 742 | { 743 | "cell_type": "markdown", 744 | "metadata": { 745 | "collapsed": true 746 | }, 747 | "source": [ 748 | "If this code is run at the command line as follows.![](https://cdn.rawgit.com/gbrunner/Python_for_GIS_and_RS/master/Week_2/images/addition.png)\n", 749 | "\n", 750 | "Notice that the command line arguments get entered immediately after the script name and they are separated by spaces. Try is out!" 751 | ] 752 | }, 753 | { 754 | "cell_type": "markdown", 755 | "metadata": {}, 756 | "source": [ 757 | "## Guidenlines for Python Coding" 758 | ] 759 | }, 760 | { 761 | "cell_type": "markdown", 762 | "metadata": {}, 763 | "source": [ 764 | "First things first:" 765 | ] 766 | }, 767 | { 768 | "cell_type": "code", 769 | "execution_count": null, 770 | "metadata": {}, 771 | "outputs": [], 772 | "source": [ 773 | "import this" 774 | ] 775 | }, 776 | { 777 | "cell_type": "markdown", 778 | "metadata": {}, 779 | "source": [ 780 | "Take these recommendations into account while coding!\n", 781 | "\n", 782 | "Additionally, Python has what is called [PEP 8 - Style Guide for Python Code](https://www.python.org/dev/peps/pep-0008/). The '8' is becuase this is version 8. Let's check it out. Not every recommendation here is madatory, but they should definately be considered best pratices." 783 | ] 784 | } 785 | ], 786 | "metadata": { 787 | "anaconda-cloud": {}, 788 | "kernelspec": { 789 | "display_name": "Python 3", 790 | "language": "python", 791 | "name": "python3" 792 | }, 793 | "language_info": { 794 | "codemirror_mode": { 795 | "name": "ipython", 796 | "version": 3 797 | }, 798 | "file_extension": ".py", 799 | "mimetype": "text/x-python", 800 | "name": "python", 801 | "nbconvert_exporter": "python", 802 | "pygments_lexer": "ipython3", 803 | "version": "3.6.9" 804 | } 805 | }, 806 | "nbformat": 4, 807 | "nbformat_minor": 1 808 | } 809 | -------------------------------------------------------------------------------- /Unit 2/unit_2_lesson_1_geoprocessing_in_arcgis_pro.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Introduction to Python in ArcGIS Pro" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "## The Python Window in ArcGIS Pro" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "Our introduction to Python will be through using the Python Window in ArcGIS Pro. The Python Window was introduced at ArcGIS 10.0 and replaced what was known as the command line window in ArcGIS 9." 22 | ] 23 | }, 24 | { 25 | "cell_type": "markdown", 26 | "metadata": {}, 27 | "source": [ 28 | "1. Open ArcGIS Pro.\n", 29 | "2. Create a new Map project.\n", 30 | "2. Select the Analysis tab at the top of ArcGIS Pro. \n", 31 | "3. Select _Python_ to open the Python Window. ![](https://raw.githubusercontent.com/gbrunner/intro-prog-for-gis-rs/master/images/python_window_in_pro.png) \n", 32 | "4. In the Python Window, type the following:" 33 | ] 34 | }, 35 | { 36 | "cell_type": "code", 37 | "execution_count": 1, 38 | "metadata": {}, 39 | "outputs": [ 40 | { 41 | "name": "stdout", 42 | "output_type": "stream", 43 | "text": [ 44 | "Hello World!\n" 45 | ] 46 | } 47 | ], 48 | "source": [ 49 | "print(\"Hello World!\")" 50 | ] 51 | }, 52 | { 53 | "cell_type": "markdown", 54 | "metadata": {}, 55 | "source": [ 56 | "This is what you should see. ![](https://raw.githubusercontent.com/gbrunner/intro-prog-for-gis-rs/master/images/hello_world.png)" 57 | ] 58 | }, 59 | { 60 | "cell_type": "markdown", 61 | "metadata": {}, 62 | "source": [ 63 | "Congratulations! This is your first line fo Python code!" 64 | ] 65 | }, 66 | { 67 | "cell_type": "markdown", 68 | "metadata": {}, 69 | "source": [ 70 | "## Using Python for Geoprocessing" 71 | ] 72 | }, 73 | { 74 | "cell_type": "markdown", 75 | "metadata": {}, 76 | "source": [ 77 | "A large part of what you'll be learning in this class is how to use Python to solve spatial problems. This will involve stringing together common geoprocessing tools from ArcGIS to perform larger tasks. You may have done this before in [Model Builder](http://pro.arcgis.com/en/pro-app/help/analysis/geoprocessing/modelbuilder/what-is-modelbuilder-.htm). Through this class, I hope you find it beneficial to start creating these types of tools with Python rather than Model Builder.\n", 78 | "\n", 79 | "To introduce you to some of the processing and analysis capabilities exposed by ArcGIS through Python, let's walk through a few examples of what you can do. These are just introductory examples. We will dive deeper into these tools throughout the class.\n", 80 | "\n", 81 | "On blackboard, you can find this week's materials. I have also posted them on ArcGIS Online. Inside the course materials for Week 1, you should see a data folder containing a [Pro Project](https://slustl.maps.arcgis.com/home/item.html?id=3179070f893247d6bc7be395ee9ff9c8). Open the ArcGIS Pro project named unit_2_lesson_1.\n", 82 | "\n", 83 | "When you open it, you should see three layers:\n", 84 | "- Roads\n", 85 | "- Saint_Charles\n", 86 | "- County\n", 87 | "\n", 88 | "If those layers don't show up or the paths are broken, just remove the layers from ArcMap and add them again directly from the Missouri.gdb in the Week_1\\data folder.\n", 89 | "\n", 90 | "The first thing we're going to do is use Python to determine how many counties are in Missouri. This can be done by entering the following in the Python Window:" 91 | ] 92 | }, 93 | { 94 | "cell_type": "code", 95 | "execution_count": null, 96 | "metadata": {}, 97 | "outputs": [], 98 | "source": [ 99 | "arcpy.GetCount_management(\"County\")" 100 | ] 101 | }, 102 | { 103 | "cell_type": "markdown", 104 | "metadata": {}, 105 | "source": [ 106 | "This should look like:![](https://raw.githubusercontent.com/gbrunner/intro-prog-for-gis-rs/master/images/get_count.png)" 107 | ] 108 | }, 109 | { 110 | "cell_type": "markdown", 111 | "metadata": {}, 112 | "source": [ 113 | "## Question 1: What is the result of the GetCount operation?" 114 | ] 115 | }, 116 | { 117 | "cell_type": "markdown", 118 | "metadata": {}, 119 | "source": [ 120 | "## Question 2: This value is not the number of counties in Missouri. The number of counties in Missouri is 114. Can you explain the discrepancy between the count and the true number of counties in Missouri?" 121 | ] 122 | }, 123 | { 124 | "cell_type": "markdown", 125 | "metadata": {}, 126 | "source": [ 127 | "## Geoprocessing with Python: Clip" 128 | ] 129 | }, 130 | { 131 | "cell_type": "markdown", 132 | "metadata": {}, 133 | "source": [ 134 | "ArcGIS exposes all of its geoprocessing (GP) tools as Python functions. For example, let's take a look at ArcToolbox. In the Analysis toolbox, there is a Clip tool. Open that up.![](https://raw.githubusercontent.com/gbrunner/intro-prog-for-gis-rs/master/images/clip_analysis_tool.png)" 135 | ] 136 | }, 137 | { 138 | "cell_type": "markdown", 139 | "metadata": {}, 140 | "source": [ 141 | "The Clip tool takes 3 required inputs (Input Features, Clip Features, Output Feature Class) and 1 optional input (XY Tolerance). This tool is exposed through Python and can be accessed through the Python Window. In the Python Window, type:" 142 | ] 143 | }, 144 | { 145 | "cell_type": "code", 146 | "execution_count": null, 147 | "metadata": { 148 | "collapsed": true 149 | }, 150 | "outputs": [], 151 | "source": [ 152 | "arcpy.Clip_analysis(\"Roads\", \"Saint_Charles\", \"Saint_Charles_Roads\")" 153 | ] 154 | }, 155 | { 156 | "cell_type": "markdown", 157 | "metadata": {}, 158 | "source": [ 159 | "![](https://raw.githubusercontent.com/gbrunner/intro-prog-for-gis-rs/master/images/clip_analysis_python_window.png)\n", 160 | "\n", 161 | "Here we're seeing \"Roads\" as the Input Features, \"Saint_Charles\" as the Clip Features, and \"Saint_Charles_Roads\" as the Output Features. Run the code." 162 | ] 163 | }, 164 | { 165 | "cell_type": "markdown", 166 | "metadata": {}, 167 | "source": [ 168 | "## Question 3: What was the result?" 169 | ] 170 | }, 171 | { 172 | "cell_type": "markdown", 173 | "metadata": {}, 174 | "source": [ 175 | "Notice as you are typing in the Python window, on the right hand side, the help shows up and the parameter that you are currently entering is highlighted in yellow. This capability is very helpful and can generally be found in any good Python IDE. ![](https://raw.githubusercontent.com/gbrunner/intro-prog-for-gis-rs/master/images/clip_analysis_python_window_help.png)" 176 | ] 177 | }, 178 | { 179 | "cell_type": "markdown", 180 | "metadata": {}, 181 | "source": [ 182 | "## Describing Data with Python" 183 | ] 184 | }, 185 | { 186 | "cell_type": "markdown", 187 | "metadata": {}, 188 | "source": [ 189 | "Python can be used to access metadata belonging to a feature class. We will learn more about this is a few weeks. While we have the Pro Project open, let's learn a little bit about the data in the Table of Contents. In the Python Window, execute the following code:" 190 | ] 191 | }, 192 | { 193 | "cell_type": "code", 194 | "execution_count": null, 195 | "metadata": { 196 | "collapsed": true 197 | }, 198 | "outputs": [], 199 | "source": [ 200 | "desc = arcpy.Describe(\"County\")\n", 201 | "desc.spatialReference.name\n", 202 | "desc.path" 203 | ] 204 | }, 205 | { 206 | "cell_type": "markdown", 207 | "metadata": {}, 208 | "source": [ 209 | "That willl look like this: \n", 210 | "\n", 211 | "![](https://raw.githubusercontent.com/gbrunner/intro-prog-for-gis-rs/master/images/describe.png)" 212 | ] 213 | }, 214 | { 215 | "cell_type": "markdown", 216 | "metadata": {}, 217 | "source": [ 218 | "## Question 4: What is the spatial reference of the County layer?" 219 | ] 220 | }, 221 | { 222 | "cell_type": "markdown", 223 | "metadata": {}, 224 | "source": [ 225 | "## Listing Data with Python" 226 | ] 227 | }, 228 | { 229 | "cell_type": "markdown", 230 | "metadata": {}, 231 | "source": [ 232 | "For our last example, we'll show how you can use Python to get a list of datasets in a geodatabase. using the same desc.path variable that we just created. Continuing in the same Python Window, execute the following:" 233 | ] 234 | }, 235 | { 236 | "cell_type": "code", 237 | "execution_count": null, 238 | "metadata": { 239 | "collapsed": true 240 | }, 241 | "outputs": [], 242 | "source": [ 243 | "arcpy.env.workspace = desc.path\n", 244 | "fcs = arcpy.ListFeatureClasses()\n", 245 | "print(fcs)" 246 | ] 247 | }, 248 | { 249 | "cell_type": "markdown", 250 | "metadata": {}, 251 | "source": [ 252 | "That will look like this: ![](https://raw.githubusercontent.com/gbrunner/intro-prog-for-gis-rs/master/images/list_feature_classes.png)" 253 | ] 254 | }, 255 | { 256 | "cell_type": "markdown", 257 | "metadata": {}, 258 | "source": [ 259 | "## Question 5: What is the result of print(fcs)?" 260 | ] 261 | }, 262 | { 263 | "cell_type": "markdown", 264 | "metadata": {}, 265 | "source": [ 266 | "That concludes Excercise 1. You can close ArcMap. For the next Excercise, we will be writing our Python code in a stand alone Python interpreter such as IDLE or PyScripter." 267 | ] 268 | }, 269 | { 270 | "cell_type": "code", 271 | "execution_count": null, 272 | "metadata": { 273 | "collapsed": true 274 | }, 275 | "outputs": [], 276 | "source": [] 277 | } 278 | ], 279 | "metadata": { 280 | "anaconda-cloud": {}, 281 | "kernelspec": { 282 | "display_name": "Python 3", 283 | "language": "python", 284 | "name": "python3" 285 | }, 286 | "language_info": { 287 | "codemirror_mode": { 288 | "name": "ipython", 289 | "version": 3 290 | }, 291 | "file_extension": ".py", 292 | "mimetype": "text/x-python", 293 | "name": "python", 294 | "nbconvert_exporter": "python", 295 | "pygments_lexer": "ipython3", 296 | "version": "3.6.9" 297 | } 298 | }, 299 | "nbformat": 4, 300 | "nbformat_minor": 1 301 | } 302 | -------------------------------------------------------------------------------- /Unit 2/unit_2_lesson_1_geoprocessing_in_arcmap.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Introduction to Python in ArcMap" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "## The Python Window in ArcMap" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "Our introduction to Python will be through using the Python Window in ArcMap. The Python Window was introduced at ArcGIS 10.0 and replaced what was known as the command line window in ArcGIS 9." 22 | ] 23 | }, 24 | { 25 | "cell_type": "markdown", 26 | "metadata": {}, 27 | "source": [ 28 | "1. Open ArcMap.\n", 29 | "2. Select the Geoprocessing tab at the top of ArcMap. \n", 30 | "3. Select _Python_ to open the Python Window. ![](https://cdn.rawgit.com/gbrunner/Python_for_GIS_and_RS/master/Week_1/images/open_python_window.png) \n", 31 | "4. In the Python Window, type the following:" 32 | ] 33 | }, 34 | { 35 | "cell_type": "code", 36 | "execution_count": null, 37 | "metadata": {}, 38 | "outputs": [], 39 | "source": [ 40 | "print(\"Hello World!\")" 41 | ] 42 | }, 43 | { 44 | "cell_type": "markdown", 45 | "metadata": {}, 46 | "source": [ 47 | "This is what you should see. ![](https://cdn.rawgit.com/gbrunner/Python_for_GIS_and_RS/master/Week_1/images/hello_world.png)" 48 | ] 49 | }, 50 | { 51 | "cell_type": "markdown", 52 | "metadata": {}, 53 | "source": [ 54 | "Congratulations! This is your first line fo Python code!" 55 | ] 56 | }, 57 | { 58 | "cell_type": "markdown", 59 | "metadata": {}, 60 | "source": [ 61 | "## Using Python for Geoprocessing" 62 | ] 63 | }, 64 | { 65 | "cell_type": "markdown", 66 | "metadata": {}, 67 | "source": [ 68 | "A large part of what you'll be learning in this class is how to use Python to solve spatial problems. This will involve strginging together common geoprocessing tools from ArcGIS to perform larger tasks. You may have done this before in [Model Builder](http://pro.arcgis.com/en/pro-app/help/analysis/geoprocessing/modelbuilder/what-is-modelbuilder-.htm). Through this class, I hope you find it beneficial to start creating these types of tools with Python rather than Model Builder.\n", 69 | "\n", 70 | "To introduce you to some of the processing and analysis capabilities exposed by ArcGIS through Python, let's walk through a few examples of what you can do. These are just introductory examples. We will dive deeper into these tools throughout the class.\n", 71 | "\n", 72 | "If you have not already done so, go to https://github.com/gbrunner/Python_for_GIS_and_RS and download today's course materials. Inside the course materials for Week 1, you should see a data folder containing a Map Document (mxd) and a geodatabase (.gdb file). Open the Map Document titled Excercise1.mxd.\n", 73 | "\n", 74 | "When you open it, you should see three layers:\n", 75 | "- Roads\n", 76 | "- Saint_Charles\n", 77 | "- County\n", 78 | "\n", 79 | "If those layers don't show up or the paths are broken, just remove the layers from ArcMap and add them again directly from the Missouri.gdb in the Week_1\\data folder.\n", 80 | "\n", 81 | "The first thing we're going to do is use Python to determine how many counties are in Missouri. This can be done by entering the following in the Python Window:\n", 82 | "\n" 83 | ] 84 | }, 85 | { 86 | "cell_type": "code", 87 | "execution_count": null, 88 | "metadata": {}, 89 | "outputs": [], 90 | "source": [ 91 | "arcpy.GetCount_management(\"County\")" 92 | ] 93 | }, 94 | { 95 | "cell_type": "markdown", 96 | "metadata": {}, 97 | "source": [ 98 | "This should look like:![](https://cdn.rawgit.com/gbrunner/Python_for_GIS_and_RS/master/Week_1/images/GetCount_Counties.png)" 99 | ] 100 | }, 101 | { 102 | "cell_type": "markdown", 103 | "metadata": {}, 104 | "source": [ 105 | "## Question 1: What is the result of the GetCount operation?" 106 | ] 107 | }, 108 | { 109 | "cell_type": "markdown", 110 | "metadata": {}, 111 | "source": [ 112 | "## Question 2: This value is not the number of counties in Missouri. The number of counties in Missouri is 114. Can you explain the discrepancy between the count and the true number of counties in Missouri?" 113 | ] 114 | }, 115 | { 116 | "cell_type": "markdown", 117 | "metadata": {}, 118 | "source": [ 119 | "## Geoprocessing with Python: Clip" 120 | ] 121 | }, 122 | { 123 | "cell_type": "markdown", 124 | "metadata": {}, 125 | "source": [ 126 | "ArcGIS exposes all of its geoprocessing (GP) tools as Python functions. For example, let's take a look at ArcToolbox. In the Analysis toolbox, there is a Clip tool. Open that up.![](https://cdn.rawgit.com/gbrunner/Python_for_GIS_and_RS/master/Week_1/images/clip_analysis_tbx.png)" 127 | ] 128 | }, 129 | { 130 | "cell_type": "markdown", 131 | "metadata": {}, 132 | "source": [ 133 | "The Clip tool takes 3 required inputs (Input Features, Clip Features, Output Feature Class) and 1 optional input (XY Tolerance). This tool is exposed through Python and can be accessed through the Python Window. In the Python Window, type:" 134 | ] 135 | }, 136 | { 137 | "cell_type": "code", 138 | "execution_count": null, 139 | "metadata": { 140 | "collapsed": true 141 | }, 142 | "outputs": [], 143 | "source": [ 144 | "arcpy.Clip_analysis(\"Roads\", \"Saint_Charles\", \"Saint_Charles_Roads\")" 145 | ] 146 | }, 147 | { 148 | "cell_type": "markdown", 149 | "metadata": {}, 150 | "source": [ 151 | "![](https://cdn.rawgit.com/gbrunner/Python_for_GIS_and_RS/master/Week_1/images/Clip_Analysis.png). Here we're seeing \"Roads\" as the Input Features, \"Saint_Charles\" as the Clip Features, and \"Saint_Charles_Roads\" as the Output Features. Run the code." 152 | ] 153 | }, 154 | { 155 | "cell_type": "markdown", 156 | "metadata": {}, 157 | "source": [ 158 | "## Question 3: What was the result?" 159 | ] 160 | }, 161 | { 162 | "cell_type": "markdown", 163 | "metadata": {}, 164 | "source": [ 165 | "Notice as you are typing in the Python window, on the right hand side, the help shows up and the parameter that you are currently entering is highlighted in yellow. This capability is very helpful and can generally be found in any good Python IDE. ![](https://cdn.rawgit.com/gbrunner/Python_for_GIS_and_RS/master/Week_1/images/clip_code_completion.png)" 166 | ] 167 | }, 168 | { 169 | "cell_type": "markdown", 170 | "metadata": {}, 171 | "source": [ 172 | "## Describing Data with Python" 173 | ] 174 | }, 175 | { 176 | "cell_type": "markdown", 177 | "metadata": {}, 178 | "source": [ 179 | "Python can be used to access metadata belonging to a feature class. We will learn more about this is a few weeks. While we have the MXD open, let's learn a little bit about the data in the Table of Contents. In the Python Window, execute the following code:" 180 | ] 181 | }, 182 | { 183 | "cell_type": "code", 184 | "execution_count": null, 185 | "metadata": { 186 | "collapsed": true 187 | }, 188 | "outputs": [], 189 | "source": [ 190 | "desc = arcpy.Describe(\"County\")\n", 191 | "desc.spatialReference.name\n", 192 | "desc.path" 193 | ] 194 | }, 195 | { 196 | "cell_type": "markdown", 197 | "metadata": {}, 198 | "source": [ 199 | "That willl look like this: ![](https://cdn.rawgit.com/gbrunner/Python_for_GIS_and_RS/master/Week_1/images/arcpy_describe.png)" 200 | ] 201 | }, 202 | { 203 | "cell_type": "markdown", 204 | "metadata": {}, 205 | "source": [ 206 | "## Question 4: What is the spatial reference of the County layer?" 207 | ] 208 | }, 209 | { 210 | "cell_type": "markdown", 211 | "metadata": {}, 212 | "source": [ 213 | "## Listing Data with Python" 214 | ] 215 | }, 216 | { 217 | "cell_type": "markdown", 218 | "metadata": {}, 219 | "source": [ 220 | "For our last example, we'll show how you can use Python to get a list of datasets in a geodatabase. using the same desc.path variable that we just created. Continuing in the same Python Window, execute the following:" 221 | ] 222 | }, 223 | { 224 | "cell_type": "code", 225 | "execution_count": null, 226 | "metadata": { 227 | "collapsed": true 228 | }, 229 | "outputs": [], 230 | "source": [ 231 | "arcpy.env.workspace = desc.path\n", 232 | "fcs = arcpy.ListFeatureClasses()\n", 233 | "print(fcs)" 234 | ] 235 | }, 236 | { 237 | "cell_type": "markdown", 238 | "metadata": {}, 239 | "source": [ 240 | "That will look like this: ![](https://cdn.rawgit.com/gbrunner/Python_for_GIS_and_RS/master/Week_1/images/list_features.png)" 241 | ] 242 | }, 243 | { 244 | "cell_type": "markdown", 245 | "metadata": {}, 246 | "source": [ 247 | "## Question 5: What is the result of print(fcs)?" 248 | ] 249 | }, 250 | { 251 | "cell_type": "markdown", 252 | "metadata": {}, 253 | "source": [ 254 | "That concludes Excercise 1. You can close ArcMap. For the next Excercise, we will be writing our Python code in a stand alone Python interpreter such as IDLE or PyScripter." 255 | ] 256 | }, 257 | { 258 | "cell_type": "code", 259 | "execution_count": null, 260 | "metadata": { 261 | "collapsed": true 262 | }, 263 | "outputs": [], 264 | "source": [] 265 | } 266 | ], 267 | "metadata": { 268 | "anaconda-cloud": {}, 269 | "kernelspec": { 270 | "display_name": "Python 3", 271 | "language": "python", 272 | "name": "python3" 273 | }, 274 | "language_info": { 275 | "codemirror_mode": { 276 | "name": "ipython", 277 | "version": 3 278 | }, 279 | "file_extension": ".py", 280 | "mimetype": "text/x-python", 281 | "name": "python", 282 | "nbconvert_exporter": "python", 283 | "pygments_lexer": "ipython3", 284 | "version": "3.6.9" 285 | } 286 | }, 287 | "nbformat": 4, 288 | "nbformat_minor": 1 289 | } 290 | -------------------------------------------------------------------------------- /Unit 3/OSM.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gbrunner/programming-for-gis-and-rs/e623312548ca5807730f37e625a304ca93e6c36e/Unit 3/OSM.zip -------------------------------------------------------------------------------- /Unit 3/README.md: -------------------------------------------------------------------------------- 1 | # This Week's Reading 2 | 3 | - [Using the Jupyter Notebook Environment](https://developers.arcgis.com/python/guide/using-the-jupyter-notebook-environment/) 4 | - [Chapter 5 of Python Scripting for ArcGIS Pro](https://esripress.esri.com/display/index.cfm?fuseaction=display&websiteID=384&moduleID=12) 5 | - [Chapter 6 of Python Scripting for ArcGIS Pro](https://esripress.esri.com/display/index.cfm?fuseaction=display&websiteID=384&moduleID=12) 6 | 7 | # Getting Data into ArcGIS Notebooks 8 | **Move this lesson to Unit 2** 9 | 10 | [Complete this exercises to unerstand how to get data into ArcGIS Notebooks.](https://www.arcgis.com/home/item.html?id=fe8a61ca94c54e6e8e62c2faed0b68cf) 11 | 12 | # This Week's Notebooks 13 | Attached are the notebooks that we will explore this week. 14 | 15 | Attached Files: 16 | 17 | File unit_3_lesson_1_exploring_spatial_data.ipynb Click for more options (22.616 KB) 18 | File unit_3_lesson_2_environments_and_coordinates_systems.ipynb Click for more options (8.232 KB) 19 | File unit_3_lesson_3_text_files_and_csvs.ipynb Click for more options (129.387 KB) 20 | 21 | # Data for Demos 22 | Attached Files: 23 | 24 | File csv_demo_data.zip Click for more options (92.708 MB) on Google Drive. 25 | File data.zip Click for more options (2.293 MB) 26 | File describe_demo_data.zip Click for more options (2.292 MB) 27 | File dems.zip Click for more options (273.416 MB) on Google Drive. 28 | File Singapore_Data.gdb.zip Click for more options (1.433 MB) 29 | 30 | 31 | # Unit 3 Exercise and Discussion Questions 32 | ## In-Class Exercises 33 | 34 | Please complete the following exercises. You do not need to submit anything, 35 | but it is recommended that you complete these. 36 | 37 | 1. Please complete [Python Scripting for ArcGIS Pro Exercise 05](https://learngis.maps.arcgis.com/home/item.html?id=d3618832b89844dda4c0b97c44ccf151). 38 | You can download the data from [here](https://learngis.maps.arcgis.com/home/item.html?id=a944af0becbf47df98336a9e4881a6b8). Please submit the scripts that you 39 | create through the exercise. If you are doing the exercise in a Jupyter Notebook, 40 | feel free to submit the notebook instead of the script. 41 | 2. Please complete [Python Scripting for ArcGIS Pro Exercise 06](https://learngis.maps.arcgis.com/home/item.html?id=cef0aa5df9c54993a6c1cb1dfec5f553). 42 | You can download the data from [here](https://learngis.maps.arcgis.com/home/item.html?id=3df07f29a0844d62af4338c52a40fda9). If you are doing the exercise 43 | in a Jupyter Notebook, feel free to submit the notebook instead of the script. 44 | 45 | ## Questions: 46 | 47 | Please submit a text file or word document answering the following questions. 48 | 49 | 1. What are some typical environment variables that get set in a script? 50 | 2. What is the difference between required and optional parameters of 51 | geoprocessing tools and how can this impact writing a script? 52 | 3. In the [```numpy.zeros```](https://numpy.org/doc/stable/reference/generated/numpy.zeros.html) function, 53 | what are the required parameters and what are the optional parameters? 54 | 55 | # Unit 3 Assignment 56 | ## Homework Problems 57 | 58 | 1. Using the OSM.gdb as input, write a script that reads all the feature classes 59 | in a workspace and prints the name of each feature class and the geometry type of that feature class in the following format, for example: roads is a polyline feature class 60 | 2. Using the OSM.gdb as input, write a script that reads all the feature classes 61 | in a personal or file geodatabase and copies only the polygon feature classes to a new file geodatabase. You can assume there are no feature datasets in the exist-ing data, and the feature classes can keep the same name. 62 | 63 | Attached Files: 64 | 65 | File OSM.zip Click for more options (2.272 MB) 66 | -------------------------------------------------------------------------------- /Unit 3/Singapore_Data.gdb.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gbrunner/programming-for-gis-and-rs/e623312548ca5807730f37e625a304ca93e6c36e/Unit 3/Singapore_Data.gdb.zip -------------------------------------------------------------------------------- /Unit 3/data.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gbrunner/programming-for-gis-and-rs/e623312548ca5807730f37e625a304ca93e6c36e/Unit 3/data.zip -------------------------------------------------------------------------------- /Unit 3/describe_demo_data.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gbrunner/programming-for-gis-and-rs/e623312548ca5807730f37e625a304ca93e6c36e/Unit 3/describe_demo_data.zip -------------------------------------------------------------------------------- /Unit 3/unit_3_lesson_2_environments_and_coordinates_systems.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Environments and Coordinate Systems" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": 1, 13 | "metadata": {}, 14 | "outputs": [], 15 | "source": [ 16 | "import arcpy" 17 | ] 18 | }, 19 | { 20 | "cell_type": "markdown", 21 | "metadata": {}, 22 | "source": [ 23 | "## Coordinate Systems\n", 24 | "\n", 25 | "Coordinate systems can be referenced by name (as a string), well-known id, or via a projection file that describes the coordinate system. Check out [spatialreference.org](https://spatialreference.org/ref/epsg/wgs-84/) to learn more about sptial references." 26 | ] 27 | }, 28 | { 29 | "cell_type": "code", 30 | "execution_count": 2, 31 | "metadata": {}, 32 | "outputs": [ 33 | { 34 | "name": "stdout", 35 | "output_type": "stream", 36 | "text": [ 37 | "\n" 38 | ] 39 | } 40 | ], 41 | "source": [ 42 | "sr = arcpy.SpatialReference(4326)\n", 43 | "print(sr)" 44 | ] 45 | }, 46 | { 47 | "cell_type": "markdown", 48 | "metadata": {}, 49 | "source": [ 50 | "### What does that mean?\n", 51 | "\n", 52 | "In order to see the spatial reference name, you need to call the ```name``` variable." 53 | ] 54 | }, 55 | { 56 | "cell_type": "code", 57 | "execution_count": 3, 58 | "metadata": {}, 59 | "outputs": [ 60 | { 61 | "name": "stdout", 62 | "output_type": "stream", 63 | "text": [ 64 | "GCS_WGS_1984\n" 65 | ] 66 | } 67 | ], 68 | "source": [ 69 | "print(sr.name)" 70 | ] 71 | }, 72 | { 73 | "cell_type": "markdown", 74 | "metadata": {}, 75 | "source": [ 76 | "## Reference by name" 77 | ] 78 | }, 79 | { 80 | "cell_type": "code", 81 | "execution_count": 4, 82 | "metadata": {}, 83 | "outputs": [ 84 | { 85 | "name": "stdout", 86 | "output_type": "stream", 87 | "text": [ 88 | "\n" 89 | ] 90 | } 91 | ], 92 | "source": [ 93 | "sr = arcpy.SpatialReference('Hawaii Albers Equal Area Conic')\n", 94 | "print(sr)" 95 | ] 96 | }, 97 | { 98 | "cell_type": "code", 99 | "execution_count": 5, 100 | "metadata": {}, 101 | "outputs": [ 102 | { 103 | "name": "stdout", 104 | "output_type": "stream", 105 | "text": [ 106 | "Hawaii_Albers_Equal_Area_Conic\n" 107 | ] 108 | } 109 | ], 110 | "source": [ 111 | "print(sr.name)" 112 | ] 113 | }, 114 | { 115 | "cell_type": "code", 116 | "execution_count": 6, 117 | "metadata": {}, 118 | "outputs": [ 119 | { 120 | "name": "stdout", 121 | "output_type": "stream", 122 | "text": [ 123 | "102007\n" 124 | ] 125 | } 126 | ], 127 | "source": [ 128 | "print(sr.factoryCode)" 129 | ] 130 | }, 131 | { 132 | "cell_type": "markdown", 133 | "metadata": {}, 134 | "source": [ 135 | "## Try a random ```wkid```" 136 | ] 137 | }, 138 | { 139 | "cell_type": "code", 140 | "execution_count": 7, 141 | "metadata": {}, 142 | "outputs": [ 143 | { 144 | "name": "stdout", 145 | "output_type": "stream", 146 | "text": [ 147 | "NAD_1983_StatePlane_Texas_South_Central_FIPS_4204_Feet\n" 148 | ] 149 | } 150 | ], 151 | "source": [ 152 | "sr = arcpy.SpatialReference(2278)\n", 153 | "print(sr.name)" 154 | ] 155 | }, 156 | { 157 | "cell_type": "markdown", 158 | "metadata": {}, 159 | "source": [ 160 | "## Listing Spatial References" 161 | ] 162 | }, 163 | { 164 | "cell_type": "code", 165 | "execution_count": 8, 166 | "metadata": {}, 167 | "outputs": [ 168 | { 169 | "name": "stdout", 170 | "output_type": "stream", 171 | "text": [ 172 | "Projected Coordinate Systems/State Plane/NAD 1927 (US Feet)/NAD 1927 StatePlane Missouri Central FIPS 2402\n", 173 | "Projected Coordinate Systems/State Plane/NAD 1927 (US Feet)/NAD 1927 StatePlane Missouri East FIPS 2401\n", 174 | "Projected Coordinate Systems/State Plane/NAD 1927 (US Feet)/NAD 1927 StatePlane Missouri West FIPS 2403\n", 175 | "Projected Coordinate Systems/State Plane/NAD 1983 (2011) (Meters)/NAD 1983 (2011) StatePlane Missouri Central FIPS 2402 (Meters)\n", 176 | "Projected Coordinate Systems/State Plane/NAD 1983 (2011) (Meters)/NAD 1983 (2011) StatePlane Missouri East FIPS 2401 (Meters)\n", 177 | "Projected Coordinate Systems/State Plane/NAD 1983 (2011) (Meters)/NAD 1983 (2011) StatePlane Missouri West FIPS 2403 (Meters)\n", 178 | "Projected Coordinate Systems/State Plane/NAD 1983 (CORS96) (Meters)/NAD 1983 (CORS96) StatePlane Missouri Central FIPS 2402 (Meters)\n", 179 | "Projected Coordinate Systems/State Plane/NAD 1983 (CORS96) (Meters)/NAD 1983 (CORS96) StatePlane Missouri East FIPS 2401 (Meters)\n", 180 | "Projected Coordinate Systems/State Plane/NAD 1983 (CORS96) (Meters)/NAD 1983 (CORS96) StatePlane Missouri West FIPS 2403 (Meters)\n", 181 | "Projected Coordinate Systems/State Plane/NAD 1983 (Meters)/NAD 1983 StatePlane Missouri Central FIPS 2402 (Meters)\n", 182 | "Projected Coordinate Systems/State Plane/NAD 1983 (Meters)/NAD 1983 StatePlane Missouri East FIPS 2401 (Meters)\n", 183 | "Projected Coordinate Systems/State Plane/NAD 1983 (Meters)/NAD 1983 StatePlane Missouri West FIPS 2403 (Meters)\n", 184 | "Projected Coordinate Systems/State Plane/NAD 1983 (US Feet)/NAD 1983 StatePlane Missouri Central FIPS 2402 (US Feet)\n", 185 | "Projected Coordinate Systems/State Plane/NAD 1983 (US Feet)/NAD 1983 StatePlane Missouri East FIPS 2401 (US Feet)\n", 186 | "Projected Coordinate Systems/State Plane/NAD 1983 (US Feet)/NAD 1983 StatePlane Missouri West FIPS 2403 (US Feet)\n", 187 | "Projected Coordinate Systems/State Plane/NAD 1983 HARN (Meters)/NAD 1983 HARN StatePlane Missouri Central FIPS 2402 (Meters)\n", 188 | "Projected Coordinate Systems/State Plane/NAD 1983 HARN (Meters)/NAD 1983 HARN StatePlane Missouri East FIPS 2401 (Meters)\n", 189 | "Projected Coordinate Systems/State Plane/NAD 1983 HARN (Meters)/NAD 1983 HARN StatePlane Missouri West FIPS 2403 (Meters)\n", 190 | "Projected Coordinate Systems/State Plane/NAD 1983 NSRS2007 (Meters)/NAD 1983 NSRS2007 StatePlane Missouri Central FIPS 2402 (Meters)\n", 191 | "Projected Coordinate Systems/State Plane/NAD 1983 NSRS2007 (Meters)/NAD 1983 NSRS2007 StatePlane Missouri East FIPS 2401 (Meters)\n", 192 | "Projected Coordinate Systems/State Plane/NAD 1983 NSRS2007 (Meters)/NAD 1983 NSRS2007 StatePlane Missouri West FIPS 2403 (Meters)\n" 193 | ] 194 | } 195 | ], 196 | "source": [ 197 | "missouri_srs = arcpy.ListSpatialReferences('*Missouri*')\n", 198 | "for sr in missouri_srs:\n", 199 | " print(sr)" 200 | ] 201 | }, 202 | { 203 | "cell_type": "markdown", 204 | "metadata": {}, 205 | "source": [ 206 | "## Environments" 207 | ] 208 | }, 209 | { 210 | "cell_type": "markdown", 211 | "metadata": {}, 212 | "source": [ 213 | "Environments are hidden parameters that influence how a tool runs. The most common environments that I use include:\n", 214 | "- ```arcpy.env.workspace```\n", 215 | "- ```arcpy.env.overwriteOutput```\n", 216 | "- ```arcpy.env.scratchWorkspace```" 217 | ] 218 | }, 219 | { 220 | "cell_type": "code", 221 | "execution_count": 9, 222 | "metadata": {}, 223 | "outputs": [ 224 | { 225 | "name": "stdout", 226 | "output_type": "stream", 227 | "text": [ 228 | "None\n" 229 | ] 230 | } 231 | ], 232 | "source": [ 233 | "print(arcpy.env.workspace)" 234 | ] 235 | }, 236 | { 237 | "cell_type": "code", 238 | "execution_count": 10, 239 | "metadata": {}, 240 | "outputs": [ 241 | { 242 | "name": "stdout", 243 | "output_type": "stream", 244 | "text": [ 245 | "/arcgis/home\n" 246 | ] 247 | } 248 | ], 249 | "source": [ 250 | "arcpy.env.workspace = '/arcgis/home'\n", 251 | "print(arcpy.env.workspace)" 252 | ] 253 | }, 254 | { 255 | "cell_type": "code", 256 | "execution_count": 11, 257 | "metadata": {}, 258 | "outputs": [ 259 | { 260 | "name": "stdout", 261 | "output_type": "stream", 262 | "text": [ 263 | "False\n" 264 | ] 265 | } 266 | ], 267 | "source": [ 268 | "print(arcpy.env.overwriteOutput)" 269 | ] 270 | }, 271 | { 272 | "cell_type": "code", 273 | "execution_count": 12, 274 | "metadata": {}, 275 | "outputs": [ 276 | { 277 | "name": "stdout", 278 | "output_type": "stream", 279 | "text": [ 280 | "True\n" 281 | ] 282 | } 283 | ], 284 | "source": [ 285 | "arcpy.env.overwriteOutput = True\n", 286 | "print(arcpy.env.overwriteOutput)" 287 | ] 288 | }, 289 | { 290 | "cell_type": "code", 291 | "execution_count": null, 292 | "metadata": {}, 293 | "outputs": [], 294 | "source": [] 295 | }, 296 | { 297 | "cell_type": "code", 298 | "execution_count": null, 299 | "metadata": {}, 300 | "outputs": [], 301 | "source": [] 302 | } 303 | ], 304 | "metadata": { 305 | "esriNotebookRuntime": { 306 | "notebookRuntimeName": "ArcGIS Notebook Python 3 Advanced", 307 | "notebookRuntimeVersion": "4.0" 308 | }, 309 | "kernelspec": { 310 | "display_name": "Python 3", 311 | "language": "python", 312 | "name": "python3" 313 | }, 314 | "language_info": { 315 | "codemirror_mode": { 316 | "name": "ipython", 317 | "version": 3 318 | }, 319 | "file_extension": ".py", 320 | "mimetype": "text/x-python", 321 | "name": "python", 322 | "nbconvert_exporter": "python", 323 | "pygments_lexer": "ipython3", 324 | "version": "3.6.10" 325 | } 326 | }, 327 | "nbformat": 4, 328 | "nbformat_minor": 2 329 | } 330 | -------------------------------------------------------------------------------- /Unit 4/Crime.gdb.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gbrunner/programming-for-gis-and-rs/e623312548ca5807730f37e625a304ca93e6c36e/Unit 4/Crime.gdb.zip -------------------------------------------------------------------------------- /Unit 4/Cursor_Lecture_Slides.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gbrunner/programming-for-gis-and-rs/e623312548ca5807730f37e625a304ca93e6c36e/Unit 4/Cursor_Lecture_Slides.pptx -------------------------------------------------------------------------------- /Unit 4/Exercise07.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gbrunner/programming-for-gis-and-rs/e623312548ca5807730f37e625a304ca93e6c36e/Unit 4/Exercise07.zip -------------------------------------------------------------------------------- /Unit 4/README.md: -------------------------------------------------------------------------------- 1 | # Watch this video 2 | 3 | [Python: Working with Feature Data using ArcPy](https://www.youtube.com/watch?v=pDS04f5u1EY) 4 | 5 | # This week's reading 6 | 7 | 1. [Review pages 29 - 33 of Chapter 2 of Python Scripting for ArcGIS.](https://esripress.esri.com/display/index.cfm?fuseaction=display&websiteID=384&moduleID=12) 8 | 2. [Chapter 8 of Python Scripting for ArcGIS Pro.](https://esripress.esri.com/display/index.cfm?fuseaction=display&websiteID=384&moduleID=12) 9 | 10 | # Slides 11 | 12 | This week's lecture slides on cursors. 13 | Attached Files: 14 | 15 | File Cursor_Lecture_Slides.pptx Click for more options (884.519 KB) 16 | 17 | # Demos 18 | 19 | This weeks demo notebooks. 20 | Attached Files: 21 | 22 | File Crime.gdb.zip Click for more options (212.891 KB) 23 | File insert_cursor_crime.py Click for more options (540 B) 24 | File unit_4_lesson_1_cursor_demos.ipynb Click for more options (179.817 KB) 25 | File update_cursor_crime.py Click for more options (536 B) 26 | File search_cursor_crime.py Click for more options (561 B) 27 | 28 | # STL City Crime Reports 29 | 30 | - The crime mapping website: https://www.slmpd.org/crime_mapping.shtml 31 | - Crime reports as CSVs and PDFs: https://www.slmpd.org/Crimereports.shtml 32 | - Hate crimes: https://www.slmpd.org/crime_stats.shtml 33 | 34 | 35 | # Unit 4 Exercise and Discussion Questions 36 | ## In-Class Exercises 37 | 38 | 1. [Beginner's guide to Python in ArcGIS Pro, Part 4: Tutorial cont.](https://www.esri.com/arcgis-blog/products/arcgis-pro/analytics/beginners-guide-to-python-in-arcgis-pro-part-4-tutorial-cont/) 39 | 2. Please complete [Python Scripting for ArcGIS Pro Exercise 08.](https://learngis.maps.arcgis.com/home/item.html?id=0cad298208984ae4b3c3f7718195c174) 40 | The data can be found [here.](https://learngis.maps.arcgis.com/home/item.html?id=ea906d3a31d54824a1930806a0cfb59e) 41 | 42 | ## Homework Questions 43 | 44 | 1. What are the three types of cursors and what purpose does each serve? 45 | 2. What module do you import to access cursors? 46 | 3. Explain the difference between the [ArcGIS Field Calculator](https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/calculate-field.htm) 47 | and Update Cursors? How are they similar? 48 | 49 | 50 | # Unit 4 Assignment 51 | Please complete both of these problems. These problems are relevant and helpful to understanding Project 1. The data to use is in the Exercise07.zip folder. 52 | 53 | 1. Write a script that creates a 15,000-meter buffer around features in the airports.shp feature class classified as an airport ( based on the FEATURE field ) and a 7,500-meter buffer around features classified as a seaplane base. The results should be two separate feature classes, one for each airport type. 54 | 2. Write a script that adds a text field to the roads.shp feature class called FERRY and populates this field with YES and NO values, depending on the value of the FEATURE field. 55 | 56 | Attached Files: 57 | 58 | File Exercise07.zip Click for more options (959.521 KB) 59 | 60 | 61 | -------------------------------------------------------------------------------- /Unit 4/insert_cursor_crime.py: -------------------------------------------------------------------------------- 1 | import arcpy 2 | import os 3 | 4 | gdb = r"C:\Users\greg6750\Documents\IPython Notebooks\Python_for_GIS_and_RS\Week_5\Crime.gdb" 5 | feature_class = "December2017_Crime" 6 | 7 | fc = os.path.join(gdb, feature_class) 8 | 9 | fields = ['SHAPE@XY', 'ILEADSStreet', 'LocationComment'] 10 | 11 | crime_cursor = arcpy.da.InsertCursor(fc, fields) 12 | crime_1 = ((895401,1020601), 'Des Peres 204', 'This class is a crime') 13 | crime_2 = ((895409,1020610), 'Des Peres 204', None) 14 | crime_cursor.insertRow(crime_1) 15 | crime_cursor.insertRow(crime_2) 16 | 17 | del crime_cursor 18 | 19 | print("Done.") -------------------------------------------------------------------------------- /Unit 4/search_cursor_crime.py: -------------------------------------------------------------------------------- 1 | import arcpy 2 | import os 3 | 4 | gdb = r"C:\Users\greg6750\Documents\IPython Notebooks\Python_for_GIS_and_RS\Week_5\Crime.gdb" 5 | feature_class = "December2017_Crime" 6 | 7 | fc = os.path.join(gdb, feature_class) 8 | 9 | fields = ['SHAPE@XY', 'ILEADSStreet', 'LocationComment'] 10 | 11 | # For each row print the WELL_ID and WELL_TYPE fields, and the 12 | # the feature's x,y coordinates 13 | with arcpy.da.SearchCursor(fc, fields) as cursor: 14 | for row in cursor: 15 | #print row[0] 16 | if row[2] != None: 17 | print "Street: " + str(row[1]) + " with comment " + str(row[2]) -------------------------------------------------------------------------------- /Unit 4/update_cursor_crime.py: -------------------------------------------------------------------------------- 1 | import arcpy 2 | import os 3 | 4 | gdb = r"C:\Users\greg6750\Documents\IPython Notebooks\Python_for_GIS_and_RS\Week_5\Crime.gdb" 5 | feature_class = "December2017_Crime" 6 | 7 | fc = os.path.join(gdb, feature_class) 8 | 9 | fields = ['OID@', 'ILEADSStreet', 'LocationComment'] 10 | 11 | #update cursor 12 | with arcpy.da.UpdateCursor(fc, fields) as cursor: 13 | for row in cursor: 14 | if row[2] == None: 15 | row[2] = "No Comment" 16 | print "Row " + str(row[0]) + " Updated with No Comment" 17 | cursor.updateRow(row) 18 | 19 | 20 | 21 | print('Done') -------------------------------------------------------------------------------- /Unit 5/README.md: -------------------------------------------------------------------------------- 1 | # Watch this video 2 | 3 | [ArcPy: Working with Feature Data](https://www.youtube.com/watch?v=AtRfmQ5MlKo) 4 | 5 | # This week's reading 6 | 7 | [Chapter 9 of Python Scripting for ArcGIS Pro](https://esripress.esri.com/display/index.cfm?fuseaction=display&websiteID=384&moduleID=12) 8 | 9 | # This week's notebooks 10 | Attached Files: 11 | 12 | File unit_5_lesson_1_geometries.ipynb Click for more options (1.169 MB) 13 | 14 | # This week's slides 15 | Attached Files: 16 | 17 | File week_5_slides.pptx Click for more options (904.608 KB) 18 | 19 | # Terminology 20 | ## [WKT](https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry) 21 | Well-known text (WKT) is a text markup language for representing vector 22 | geometry objects on a map. A binary equivalent, known as well-known binary (WKB), 23 | is used to transfer and store the same information on databases. 24 | The formats were originally defined by the Open Geospatial Consortium (OGC) and 25 | described in their Simple Feature Access. The current standard definition is 26 | in the ISO/IEC 13249-3:2016 standard. 27 | 28 | ## [JSON](https://www.json.org/json-en.html) 29 | JSON (JavaScript Object Notation) is a lightweight data-interchange format. 30 | It is easy for humans to read and write. It is easy for machines to parse and generate. 31 | It is based on a subset of the JavaScript Programming Language 32 | Standard ECMA-262 3rd Edition - December 1999. JSON is a text format that 33 | is completely language independent but uses conventions that are familiar 34 | to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, 35 | Perl, Python, and many others. These properties make JSON an ideal 36 | data-interchange language. 37 | 38 | ## [PEP8](https://www.python.org/dev/peps/pep-0008/) 39 | This document gives coding conventions for the Python code comprising 40 | the standard library in the main Python distribution. 41 | 42 | # Unit 5 In Class Assignment 43 | ## In-Class Exercises 44 | 45 | Please complete [Exercise 9 from Python Scripting for ArcGIS Pro.](https://learngis.maps.arcgis.com/home/item.html?id=f8e466f8f2c2481f9a3c820ccfc1c35f) 46 | You can find the data [here.](https://learngis.maps.arcgis.com/home/item.html?id=ce6ad466cd064a7099ee65de7bba3a49) I recommend trying this in an Jupyter notebook 47 | rather than IDLE. Please submit the notebook if you do this in Jupyter. 48 | Submit the Python scripts if you do it in IDLE or PyCharm. 49 | 50 | -------------------------------------------------------------------------------- /Unit 5/week_5_slides.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gbrunner/programming-for-gis-and-rs/e623312548ca5807730f37e625a304ca93e6c36e/Unit 5/week_5_slides.pptx -------------------------------------------------------------------------------- /Unit 6/Exercise09.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gbrunner/programming-for-gis-and-rs/e623312548ca5807730f37e625a304ca93e6c36e/Unit 6/Exercise09.zip -------------------------------------------------------------------------------- /Unit 6/README.md: -------------------------------------------------------------------------------- 1 | # Watch this video 2 | 3 | [AWS re:Invent 2017: How Esri Optimizes Massive Image Archives for Analytics in the C (ABD402)](https://www.youtube.com/watch?v=U486YxlDoeM) 4 | 5 | # This week's reading 6 | 7 | Please read Chapter 10 of Python Scripting for ArcGIS Pro. 8 | 9 | # This week's slides, notebooks, and demos 10 | These are the slides, notebooks, and demos I will use this week. 11 | 12 | Attached Files: 13 | 14 | File Unit_6_Rasters.pptx Click for more options (607.033 KB) 15 | File unit_6_lesson_1_working_with_rasters_arcpy.ipynb Click for more options (1.303 MB) 16 | File unit_6_lesson_2_working_with_rasters_numpy.ipynb Click for more options (413.318 KB) 17 | File unit_6_lesson_3_working_with_rasters_in_the_cloud.ipynb Click for more options (1.722 MB) 18 | File working_with_rasters_arcpy.html Click for more options (1.57 MB) 19 | File working_with_rasters_in_the_cloud.html Click for more options (1.987 MB) 20 | File working_with_rasters_numpy.html Click for more options (689.53 KB) 21 | 22 | # Unit 6 Exercise and Discussion Questions 23 | ## In class exercise 24 | Compete exercises for Chapter 10 of Python Scripting for ArcGIS Pro 25 | - Exercise: https://www.arcgis.com/home/item.html?id=1372abc4fb0c4ff0a7c66e8d9c869038 26 | - Data: https://www.arcgis.com/home/item.html?id=862c63f5a50e4a29bb237369a9854838 27 | 28 | ## Questions 29 | 1. What is a "Raster" object, and why do geoprocessing operations and map algebra expressions using rasters often result in temporary outputs? 30 | 2. What are the differences between raster datasets and raster bands? 31 | 3. What is the difference between raster functions in ArcGIS Pro and their equivalent functions in arcpy.sa or arcpy.ia? 32 | 33 | # Unit 6 Assignment 34 | Attached Files: 35 | 36 | File Exercise09.zip Click for more options (21.075 MB) 37 | 38 | ## Challenge 1 39 | Create a script that determines what areas meet the following conditions: 40 | - Moderate slope — between 5 and 20 degrees 41 | - Southerly aspect — between 150 and 270 degrees 42 | - Forested — land cover types of 41, 42, or 43 43 | Be sure to use the map algebra expressions of the arcpy.sa module. 44 | 45 | ## Challenge 2 46 | Write a script that copies all the rasters in a workspace to a new file geo-database. 47 | You can use the rasters in the Exercise09 folder as an example. 48 | 49 | ### WARNGING 50 | If you do Challenge 2, you may get an error: 51 | 52 | --------------------------------------------------------------------------- 53 | AttributeError Traceback (most recent call last) 54 | c:\program files\arcgis\pro\Resources\ArcToolbox\toolboxes\Conversion Tools.tbx#RasterToGeodatabase_conversion.InitializeParameters.py in 55 | 56 | AttributeError: 'ToolValidator' object has no attribute 'isLicensed' 57 | 58 | --------------------------------------------------------------------------- 59 | AttributeError Traceback (most recent call last) 60 | c:\program files\arcgis\pro\Resources\ArcToolbox\toolboxes\Conversion Tools.tbx#RasterToGeodatabase_conversion.InitializeParameters.py in 61 | 62 | AttributeError: 'ToolValidator' object has no attribute 'isLicensed' 63 | 64 | 65 | If you get this error, check to see whether the tool worked anyway! 66 | 67 | 68 | -------------------------------------------------------------------------------- /Unit 6/Unit_6_Rasters.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gbrunner/programming-for-gis-and-rs/e623312548ca5807730f37e625a304ca93e6c36e/Unit 6/Unit_6_Rasters.pptx -------------------------------------------------------------------------------- /Unit 7/Python_GP_Tools.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gbrunner/programming-for-gis-and-rs/e623312548ca5807730f37e625a304ca93e6c36e/Unit 7/Python_GP_Tools.ppt -------------------------------------------------------------------------------- /Unit 7/README.md: -------------------------------------------------------------------------------- 1 | # Watch this video 2 | ## Teaching with ArcGIS Notebooks 3 | [Check out Convert ArcGIS Notebooks to slides. Recognize the voice?](https://s3-us-west-2.amazonaws.com/lp.esri.com/localgovt/LEARN/Videos/Notebooks2.mp4) 4 | In case that link doesn't work: https://learn.arcgis.com/en/paths/teach-with-arcgis-notebooks/ 5 | 6 | # More Imagery - GDAL and Python 7 | Attached Files: 8 | 9 | File unit_7_boto_and_azure.ipynb Click for more options (1.564 MB) 10 | File unit_7_gdal.ipynb Click for more options (2.015 MB) 11 | 12 | # This week's slides 13 | 14 | This week we will learn how to create Python geoprocessing tools for ArcGIS Pro. 15 | Attached Files: 16 | 17 | File Python_GP_Tools.ppt Click for more options (8.155 MB) 18 | 19 | # This week's demo scripts 20 | Attached Files: 21 | 22 | File problem1_script.py Click for more options (657 B) 23 | File problem2_script.py Click for more options (827 B) 24 | 25 | 26 | # Unit 7 Exercise and Discussion Questions 27 | This goes with Chapter 3 of Advanced Scripting for ArcGIS Pro. Please complete 28 | this tutorial on creating script tools: https://www.arcgis.com/home/item.html?id=cdb970479d5f4439ac5d2eb155bdd6f6 29 | 30 | Here is the data: https://www.arcgis.com/home/item.html?id=fbb1335ef10944259899a3af6206e10e 31 | 32 | Please complete the following question. Submit screen shots of the 33 | results for 1 and 2. Submit the Python script for 3: 34 | 35 | 1. Create a cloud storage connection to Landsat 8 in Amazon S3 if you 36 | haven’t already. [Download the Landsat Descending Path Row shapefile.](https://prd-wret.s3.us-west-2.amazonaws.com/assets/palladium/production/s3fs-public/atoms/files/WRS2_descending_0.zip) 37 | Unzip it and view the shapefile in ArcGIS Pro. Identify a path row that 38 | covers Northern California. Use that path row to find the imagery over 39 | California in the Landsat 8 cloud storage connection. If you are interested 40 | in a challenge, find a path row over Northern California from the early 41 | September 2020 time frame and try to identify the locations of wildfires 42 | in the Landsat 8 imagery. 43 | 2. [SpaceNet](https://registry.opendata.aws/spacenet/) is an open geospatial dataset consisting of freely available imagery. 44 | That dataset is used as a test bed for computer vision, machine learning, 45 | deep learning, and GeoAI research. Create a new ArcGIS Pro project. 46 | In that project, create a cloud storage connection to the SpaceNet dataset. 47 | You do not need to specify the region when creating the cloud storage connection. 48 | Search through the SpaceNet S3 bucket. Add a few images from the SpaceNet S3 49 | bucket to the map. What cities does SpaceNet have imagery for? 50 | 3. Make a copy of the random_sample.py script and call it random_percent.py. Modify 51 | the script so that the third parameter is a percentage of the number of input 52 | records as an integer between 1 and 100. Modify the script tool settings so 53 | that the input for this parameter is validated on the tool dialog box 54 | -------------------------------------------------------------------------------- /Unit 7/problem1_script.py: -------------------------------------------------------------------------------- 1 | import arcpy 2 | 3 | arcpy.env.workspace = arcpy.GetParameterAsText(0) 4 | #r'C:\Users\greg6750\Documents\IPython Notebooks\intro-prog-for-gis-rs\Projects\imagery' 5 | 6 | raster_list = arcpy.ListRasters() 7 | arcpy.AddMessage("There are " + str(len(raster_list)) + " rasters in the folder.") 8 | 9 | for raster in raster_list: 10 | desc = arcpy.Describe(raster) 11 | arcpy.AddMessage("Raster Name: " + raster) 12 | arcpy.AddMessage("Band Count: %d" % desc.bandCount) 13 | arcpy.AddMessage("Compression Type: %s" % desc.compressionType) 14 | arcpy.AddMessage("Raster Format: %s" % desc.format) 15 | arcpy.AddMessage("Spatial Reference: %s" % desc.SpatialReference.name) -------------------------------------------------------------------------------- /Unit 7/problem2_script.py: -------------------------------------------------------------------------------- 1 | import arcpy 2 | 3 | arcpy.env.workspace = arcpy.GetParameterAsText(0) 4 | output_file = arcpy.GetParameterAsText(1) 5 | 6 | f = open(output_file, 'w') 7 | #r'C:\Users\greg6750\Documents\IPython Notebooks\intro-prog-for-gis-rs\Projects\tlgdb_2019_a_us_school.gdb' 8 | 9 | feature_list = arcpy.ListFeatureClasses() 10 | header = f.write('Feature Class, Feature Count, Projection, Shape \n') 11 | 12 | for feature in feature_list: 13 | feature_count = arcpy.GetCount_management(feature) 14 | desc = arcpy.Describe(feature) 15 | projection = desc.SpatialReference.name 16 | shape_type = desc.shapeType 17 | seperator = ", " 18 | arcpy.AddMessage(feature + seperator + str(feature_count) + seperator + projection + seperator + shape_type) 19 | f.write(feature + seperator + str(feature_count) + seperator + projection + seperator + shape_type + '\n') 20 | 21 | f.close() -------------------------------------------------------------------------------- /Unit 8/README.md: -------------------------------------------------------------------------------- 1 | # This week's reading 2 | 3 | This week, we will cover try-except statments, functions and classes. If you 4 | have Advanced Python Scripting for ArcGIS Pro, please read Chapter 2 on functions and classes. 5 | 6 | # This week's notebooks, data, and demos 7 | Attached Files: 8 | 9 | File requests.ipynb Click for more options (246.125 KB) 10 | File try_except.ipynb Click for more options (10.719 KB) 11 | File functions_example.ipynb Click for more options (3.544 KB) 12 | File requests.html Click for more options (479.409 KB) 13 | File try_except.html Click for more options (286.755 KB) 14 | File functions_example.html Click for more options (274.772 KB) 15 | File February2020.CSV Click for more options (509.99 KB) 16 | 17 | # Unit 8 Exercise and Discussion Questions 18 | Please complete the following tutorial: https://www.maps.arcgis.com/home/item.html?id=03e58089563646b4a742a6f2cabffa03You can find the data at: https://www.arcgis.com/home/item.html?id=27de226a996946cf9885cd53b96ad53e 19 | 20 | ## Complete the following problems 21 | ### Problem 1 22 | Create a custom function called ```countstringfields``` that determines the number of fields of type 23 | string in an input feature class. Create this function in a 24 | separate script ( for example, mycount.py) that you call from 25 | another script ( for example, callingscript.py). 26 | You can use the streets.shp feature class in the Exercise12 folder. 27 | 28 | ### Problem 2 29 | You are given a feature class called parcels.shp 30 | located in the Exercise12 folder that contains the 31 | following fields: FID, Shape, Landuse, and Value. 32 | Modify the parceltax.py script so that it determines the property tax for 33 | each parcel and stores these values in a list. You should use the class 34 | created in the parcelclass.py script — the class can remain unchanged. 35 | Print the values of the final list as follows: **FID: ** 36 | -------------------------------------------------------------------------------- /Unit 8/functions_example.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Function - A block of code that performs some action on data and returns the result back to the code\n", 8 | "- a.k.a. - subroutine or proceedure\n", 9 | "- Designed to accept input data, transform it, and return it to the main program" 10 | ] 11 | }, 12 | { 13 | "cell_type": "markdown", 14 | "metadata": {}, 15 | "source": [ 16 | "# Purpose of Functions \n", 17 | "- Avoid Repeating Code\n", 18 | "- Simplify programs" 19 | ] 20 | }, 21 | { 22 | "cell_type": "markdown", 23 | "metadata": {}, 24 | "source": [ 25 | "# My first function" 26 | ] 27 | }, 28 | { 29 | "cell_type": "code", 30 | "execution_count": 1, 31 | "metadata": {}, 32 | "outputs": [], 33 | "source": [ 34 | "def firstFunction():\n", 35 | " 'a simple function returning a string'\n", 36 | " return 'My first function'" 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": 5, 42 | "metadata": {}, 43 | "outputs": [ 44 | { 45 | "name": "stdout", 46 | "output_type": "stream", 47 | "text": [ 48 | "My first function\n" 49 | ] 50 | } 51 | ], 52 | "source": [ 53 | "this_string = firstFunction()\n", 54 | "print(this_string)" 55 | ] 56 | }, 57 | { 58 | "cell_type": "markdown", 59 | "metadata": {}, 60 | "source": [ 61 | "# Function with input parameters" 62 | ] 63 | }, 64 | { 65 | "cell_type": "code", 66 | "execution_count": 9, 67 | "metadata": {}, 68 | "outputs": [], 69 | "source": [ 70 | "def secondFunction(number):\n", 71 | " 'this function multiplies numbers by 3'\n", 72 | "\n", 73 | " return number * 3" 74 | ] 75 | }, 76 | { 77 | "cell_type": "code", 78 | "execution_count": 10, 79 | "metadata": {}, 80 | "outputs": [ 81 | { 82 | "data": { 83 | "text/plain": [ 84 | "9" 85 | ] 86 | }, 87 | "execution_count": 10, 88 | "metadata": {}, 89 | "output_type": "execute_result" 90 | } 91 | ], 92 | "source": [ 93 | "secondFunction(3)" 94 | ] 95 | }, 96 | { 97 | "cell_type": "code", 98 | "execution_count": 11, 99 | "metadata": {}, 100 | "outputs": [ 101 | { 102 | "name": "stdout", 103 | "output_type": "stream", 104 | "text": [ 105 | "15\n" 106 | ] 107 | } 108 | ], 109 | "source": [ 110 | "val = secondFunction(5)\n", 111 | "print(val)" 112 | ] 113 | }, 114 | { 115 | "cell_type": "markdown", 116 | "metadata": {}, 117 | "source": [ 118 | "# Function with input parameters and defaults" 119 | ] 120 | }, 121 | { 122 | "cell_type": "code", 123 | "execution_count": 17, 124 | "metadata": {}, 125 | "outputs": [], 126 | "source": [ 127 | "def thirdFunction(number, multiplier=3):\n", 128 | " 'this multiplies two numbers. If a second number is not specified, it '\n", 129 | " 'multiplies the number by 3'\n", 130 | " if type(number) == type(1) or type(number) == type(1.0):\n", 131 | " return number * multiplier\n" 132 | ] 133 | }, 134 | { 135 | "cell_type": "code", 136 | "execution_count": 18, 137 | "metadata": {}, 138 | "outputs": [ 139 | { 140 | "name": "stdout", 141 | "output_type": "stream", 142 | "text": [ 143 | "Error\n" 144 | ] 145 | } 146 | ], 147 | "source": [ 148 | "value = thirdFunction('Greg', 5)\n", 149 | "print(value)" 150 | ] 151 | }, 152 | { 153 | "cell_type": "markdown", 154 | "metadata": {}, 155 | "source": [ 156 | "## Add in an else statement...\n", 157 | "\n", 158 | "```\n", 159 | " else:\n", 160 | " return 'Error'\n", 161 | "```" 162 | ] 163 | }, 164 | { 165 | "cell_type": "code", 166 | "execution_count": null, 167 | "metadata": {}, 168 | "outputs": [], 169 | "source": [] 170 | } 171 | ], 172 | "metadata": { 173 | "kernelspec": { 174 | "display_name": "Python 3", 175 | "language": "python", 176 | "name": "python3" 177 | }, 178 | "language_info": { 179 | "codemirror_mode": { 180 | "name": "ipython", 181 | "version": 3 182 | }, 183 | "file_extension": ".py", 184 | "mimetype": "text/x-python", 185 | "name": "python", 186 | "nbconvert_exporter": "python", 187 | "pygments_lexer": "ipython3", 188 | "version": "3.6.9" 189 | } 190 | }, 191 | "nbformat": 4, 192 | "nbformat_minor": 4 193 | } 194 | -------------------------------------------------------------------------------- /Unit 8/try_except.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# This illustrates the utility of ```try-except```\n", 8 | "\n", 9 | "The real data is at:\n", 10 | "- C:\\Users\\greg6750\\Documents\\IPython Notebooks\\intro-prog-for-gis-rs\\march_23\n", 11 | "- C:\\Users\\greg6750\\Documents\\IPython Notebooks\\intro-prog-for-gis-rs\\march_23\\crime.gdb\\feb_2020\n", 12 | "\n", 13 | "Data taken from: https://www.slmpd.org/Crimereports.shtml\n", 14 | "\n", 15 | "1. Run this so taht it works.\n", 16 | "2. The run it and it fails.\n", 17 | "3. Then run the next cell." 18 | ] 19 | }, 20 | { 21 | "cell_type": "code", 22 | "execution_count": 5, 23 | "metadata": {}, 24 | "outputs": [ 25 | { 26 | "name": "stdout", 27 | "output_type": "stream", 28 | "text": [ 29 | "Creating File GDB\n" 30 | ] 31 | }, 32 | { 33 | "ename": "ExecuteError", 34 | "evalue": "ERROR 000258: Output C:\\Users\\greg6750\\Documents\\IPython Notebooks\\intro-prog-for-gis-rs\\march_23\\crime.gdb already exists\nFailed to execute (CreateFileGDB).\n", 35 | "output_type": "error", 36 | "traceback": [ 37 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", 38 | "\u001b[1;31mExecuteError\u001b[0m Traceback (most recent call last)", 39 | "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 19\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Creating File GDB\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 20\u001b[0m arcpy.CreateFileGDB_management(os.path.dirname(gdb_name),\n\u001b[1;32m---> 21\u001b[1;33m os.path.basename(gdb_name))\n\u001b[0m\u001b[0;32m 22\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 23\u001b[0m \u001b[1;31m##Create table from csv file\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", 40 | "\u001b[1;32mC:\\Program Files\\ArcGIS\\Pro\\Resources\\ArcPy\\arcpy\\management.py\u001b[0m in \u001b[0;36mCreateFileGDB\u001b[1;34m(out_folder_path, out_name, out_version)\u001b[0m\n\u001b[0;32m 21591\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mretval\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 21592\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mException\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m> 21593\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0me\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 21594\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 21595\u001b[0m \u001b[1;33m@\u001b[0m\u001b[0mgptooldoc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'CreateFolder_management'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", 41 | "\u001b[1;32mC:\\Program Files\\ArcGIS\\Pro\\Resources\\ArcPy\\arcpy\\management.py\u001b[0m in \u001b[0;36mCreateFileGDB\u001b[1;34m(out_folder_path, out_name, out_version)\u001b[0m\n\u001b[0;32m 21588\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[0marcpy\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0marcobjects\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0marcobjectconversion\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mconvertArcObjectToPythonObject\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 21589\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m> 21590\u001b[1;33m \u001b[0mretval\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mconvertArcObjectToPythonObject\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mgp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mCreateFileGDB_management\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0mgp_fixargs\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mout_folder_path\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mout_name\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mout_version\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;32mTrue\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 21591\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mretval\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 21592\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mException\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", 42 | "\u001b[1;32mC:\\Program Files\\ArcGIS\\Pro\\Resources\\ArcPy\\arcpy\\geoprocessing\\_base.py\u001b[0m in \u001b[0;36m\u001b[1;34m(*args)\u001b[0m\n\u001b[0;32m 509\u001b[0m \u001b[0mval\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mgetattr\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_gp\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mattr\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 510\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mcallable\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mval\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 511\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[1;32mlambda\u001b[0m \u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mval\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0mgp_fixargs\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;32mTrue\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 512\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 513\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mconvertArcObjectToPythonObject\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mval\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", 43 | "\u001b[1;31mExecuteError\u001b[0m: ERROR 000258: Output C:\\Users\\greg6750\\Documents\\IPython Notebooks\\intro-prog-for-gis-rs\\march_23\\crime.gdb already exists\nFailed to execute (CreateFileGDB).\n" 44 | ] 45 | } 46 | ], 47 | "source": [ 48 | "import os\n", 49 | "import arcpy\n", 50 | "from arcpy import env\n", 51 | "\n", 52 | "#arcpy.env.overwriteOutput = True\n", 53 | "\n", 54 | "#input_table = r\"C:\\Answers\\fakelocation\\January2018.CSV\"\n", 55 | "input_table = r'C:\\Users\\greg6750\\Documents\\IPython Notebooks\\intro-prog-for-gis-rs\\march_23\\February2020.CSV'\n", 56 | "#output_fc = r\"C:\\Answers\\crime.gdb\\January2018_Crime\"\n", 57 | "output_fc = r'C:\\Users\\greg6750\\Documents\\IPython Notebooks\\intro-prog-for-gis-rs\\march_23\\crime.gdb\\feb_2020'\n", 58 | "spRef = arcpy.SpatialReference(\"NAD 1983 StatePlane Missouri East FIPS 2401 (US Feet)\")\n", 59 | "\n", 60 | "gdb_name = os.path.dirname(output_fc)\n", 61 | "fc_name = os.path.basename(output_fc)\n", 62 | "\n", 63 | "#env.overwriteOutput = True\n", 64 | "\n", 65 | "#try:\n", 66 | "print(\"Creating File GDB\")\n", 67 | "arcpy.CreateFileGDB_management(os.path.dirname(gdb_name),\n", 68 | " os.path.basename(gdb_name))\n", 69 | "\n", 70 | "##Create table from csv file\n", 71 | "print(gdb_name)\n", 72 | "table_name = \"January2018_Table\"\n", 73 | "out_table = os.path.join(gdb_name, table_name)\n", 74 | "print(\"Converting CSV to GDB Table\")\n", 75 | "arcpy.TableToTable_conversion(input_table, gdb_name, table_name, \"\", \"\", \"\")\n", 76 | "\n", 77 | "##Make XY events layer\n", 78 | "events_layer = \"crime_points\"\n", 79 | "print(\"Make FC Layer\")\n", 80 | "arcpy.MakeXYEventLayer_management(out_table, \"xcoord\", \"ycoord\", events_layer, \"\", \"\")\n", 81 | "\n", 82 | "##Output events layer to feature class\n", 83 | "print(\"FC to FC\")\n", 84 | "arcpy.FeatureClassToFeatureClass_conversion(events_layer, gdb_name, fc_name, \"\", \"\", \"\")\n", 85 | "\n", 86 | "##Define projection\n", 87 | "print(\"Defining Projection.\")\n", 88 | "arcpy.DefineProjection_management(output_fc, spRef)\n", 89 | "\n", 90 | "#except:\n", 91 | "# print \"An Error Occured\"\n", 92 | "\n", 93 | "\n", 94 | "print(\"Done.\")\n" 95 | ] 96 | }, 97 | { 98 | "cell_type": "code", 99 | "execution_count": 3, 100 | "metadata": {}, 101 | "outputs": [ 102 | { 103 | "name": "stdout", 104 | "output_type": "stream", 105 | "text": [ 106 | "Creating File GDB\n", 107 | "An Error Occured\n", 108 | "Done.\n" 109 | ] 110 | } 111 | ], 112 | "source": [ 113 | "import os\n", 114 | "import arcpy\n", 115 | "from arcpy import env\n", 116 | "\n", 117 | "input_table = r\"C:\\Answers\\fakelocation\\January2018.CSV\"\n", 118 | "output_fc = r\"C:\\Answers\\crime.gdb\\January2018_Crime\"\n", 119 | "spRef = arcpy.SpatialReference(\"NAD 1983 StatePlane Missouri East FIPS 2401 (US Feet)\")\n", 120 | "\n", 121 | "gdb_name = os.path.dirname(output_fc)\n", 122 | "fc_name = os.path.basename(output_fc)\n", 123 | "\n", 124 | "#env.overwriteOutput = True\n", 125 | "\n", 126 | "try:\n", 127 | " print(\"Creating File GDB\")\n", 128 | " arcpy.CreateFileGDB_management(os.path.dirname(gdb_name),\n", 129 | " os.path.basename(gdb_name))\n", 130 | "\n", 131 | " ##Create table from csv file\n", 132 | " print(gdb_name)\n", 133 | " table_name = \"January2018_Table\"\n", 134 | " out_table = os.path.join(gdb_name, table_name)\n", 135 | " print(\"Converting CSV to GDB Table\")\n", 136 | " arcpy.TableToTable_conversion(input_table, gdb_name, table_name, \"\", \"\", \"\")\n", 137 | "\n", 138 | " ##Make XY events layer\n", 139 | " events_layer = \"crime_points\"\n", 140 | " print(\"Make FC Layer\")\n", 141 | " arcpy.MakeXYEventLayer_management(out_table, \"xcoord\", \"ycoord\", events_layer, \"\", \"\")\n", 142 | "\n", 143 | " ##Output events layer to feature class\n", 144 | " print(\"FC to FC\")\n", 145 | " arcpy.FeatureClassToFeatureClass_conversion(events_layer, gdb_name, fc_name, \"\", \"\", \"\")\n", 146 | "\n", 147 | " ##Define projection\n", 148 | " print(\"Defining Projection.\")\n", 149 | " arcpy.DefineProjection_management(output_fc, spRef)\n", 150 | "\n", 151 | "except:\n", 152 | " print(\"An Error Occured\")\n", 153 | "\n", 154 | "\n", 155 | "print(\"Done.\")\n" 156 | ] 157 | }, 158 | { 159 | "cell_type": "code", 160 | "execution_count": null, 161 | "metadata": {}, 162 | "outputs": [], 163 | "source": [] 164 | } 165 | ], 166 | "metadata": { 167 | "kernelspec": { 168 | "display_name": "Python 3", 169 | "language": "python", 170 | "name": "python3" 171 | }, 172 | "language_info": { 173 | "codemirror_mode": { 174 | "name": "ipython", 175 | "version": 3 176 | }, 177 | "file_extension": ".py", 178 | "mimetype": "text/x-python", 179 | "name": "python", 180 | "nbconvert_exporter": "python", 181 | "pygments_lexer": "ipython3", 182 | "version": "3.6.9" 183 | } 184 | }, 185 | "nbformat": 4, 186 | "nbformat_minor": 4 187 | } 188 | -------------------------------------------------------------------------------- /Unit 9/Oklahoma_City_Thunder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gbrunner/programming-for-gis-and-rs/e623312548ca5807730f37e625a304ca93e6c36e/Unit 9/Oklahoma_City_Thunder.png -------------------------------------------------------------------------------- /Unit 9/README.md: -------------------------------------------------------------------------------- 1 | # Watch these videos 2 | 1. [ArcGIS API for Python: Introduction to Scripting Your Web GIS](https://www.youtube.com/watch?v=RRXKbT7fyaI) 3 | 2. [ArcGIS API for Python: Advanced Scripting](https://www.youtube.com/watch?v=6hx0EpIKIj8) 4 | 3. [ArcGIS API for Python: Mapping, Visualization, and Analysis](https://www.youtube.com/watch?v=mKjyeesUr80) 5 | 6 | # This week's notebooks 7 | At this point, let's use ArcGIS Notebooks for our lessons. You can find this week's 8 | notebooks in ArcGIS Online at [GIS 5090\5090 Unit 9 Notebooks](https://slustl.maps.arcgis.com/home/group.html?id=ac0ae1633bbf4d06bb07c68ce4eb55ec#overview) 9 | 10 | # Data for this weeks lectures 11 | Attached Files: 12 | 13 | File all_week_aug_13_20.csv Click for more options (512.421 KB) 14 | File chennai-rainfall.csv Click for more options (4.484 KB) 15 | File me.gif Click for more options (497.424 KB) 16 | File Oklahoma_City_Thunder.png Click for more options (152.967 KB) 17 | File profile_pic.jpg Click for more options (14.547 KB) 18 | 19 | # Supplemental notebook 20 | [Chennai Floods 2015 - A Geographic Analysis](https://developers.arcgis.com/python/sample-notebooks/chennai-floods-analysis/) 21 | 22 | # Unit 9 Exercise and Discussion Questions 23 | [Please complete this tutorial from Teach Web GIS with ArcGIS Notebooks.](https://www.arcgis.com/home/item.html?id=a25c49feb0564827a506ee8ae541a6fd#) 24 | 25 | If you need help getting started, take a look at [Hello, Notebook!](https://www.arcgis.com/home/item.html?id=282e3eb54e844e25b2687d66f59b91be) 26 | which was assigned during week 1. 27 | 28 | 29 | -------------------------------------------------------------------------------- /Unit 9/chennai-rainfall.csv: -------------------------------------------------------------------------------- 1 | WEATHER STATION,LOCATION,RAINFALL 2 | TAMBARAM,"TAMBARAM, TAMIL NADU",49 3 | CHEMBARABAKKAM,"CHEMBARABAKKAM, TAMIL NADU",47 4 | MARAKKANAM,"MARAKKANAM, TAMIL NADU",42 5 | CHENGALPATTU,"CHENGALPATTU, TAMIL NADU",39 6 | PONNERI,"PONNERI, TAMIL NADU",39 7 | SRIPERUMBUDUR,"SRIPERUMBUDUR, TAMIL NADU",38 8 | CHEYYUR,"CHEYYUR, TAMIL NADU",38 9 | CHENNAI AP,"CHENNAI AP, TAMIL NADU",35 10 | MAHABALIPURAM,"MAHABALIPURAM, TAMIL NADU",34 11 | POONAMALLEE,"POONAMALLEE, TAMIL NADU",34 12 | RED HILLS,"RED HILLS, TAMIL NADU",32 13 | ANNA UTY ARG,"ANNA UTY ARG, TAMIL NADU",32 14 | TARAMANI ARG,"TARAMANI ARG, TAMIL NADU",30 15 | CHOLAVARAM,"CHOLAVARAM, TAMIL NADU",29 16 | CHENNAI(N),"CHENNAI(N), TAMIL NADU",29 17 | THAMARAIPAKKAM,"THAMARAIPAKKAM, TAMIL NADU",28 18 | MADURANTHAGAM,"MADURANTHAGAM, TAMIL NADU",28 19 | DGP OFFICE,"DGP OFFICE, TAMIL NADU",27 20 | TIRUVALLUR,"TIRUVALLUR, TAMIL NADU",22 21 | ANNA,"ANNA, TAMIL NADU",22 22 | UNIVERSITY,"UNIVERSITY, TAMIL NADU",22 23 | PONDICHERRY,"PONDICHERRY, TAMIL NADU",22 24 | POONDI,"POONDI, TAMIL NADU",19 25 | UTHIRAMERUR,"UTHIRAMERUR, TAMIL NADU",19 26 | KANCHEEPURAM,"KANCHEEPURAM, TAMIL NADU",17 27 | THIRUVALANGADU,"THIRUVALANGADU, TAMIL NADU",15 28 | CHEYYAR,"CHEYYAR, TAMIL NADU",14 29 | VANUR,"VANUR, TAMIL NADU",14 30 | VEDARANYAM,"VEDARANYAM, TAMIL NADU",14 31 | CUDDALORE,"CUDDALORE, TAMIL NADU",13 32 | VILUPURAM,"VILUPURAM, TAMIL NADU",13 33 | TINDIVANAM,"TINDIVANAM, TAMIL NADU",12 34 | ARAKONAM,"ARAKONAM, TAMIL NADU",11 35 | VANDAVASI,"VANDAVASI, TAMIL NADU",11 36 | TIRUTTANI,"TIRUTTANI, TAMIL NADU",9 37 | GINGEE,"GINGEE, TAMIL NADU",9 38 | KAVERIPAKKAM,"KAVERIPAKKAM, TAMIL NADU",8 39 | THIRUTHURAIPOONDI,"THIRUTHURAIPOONDI, TAMIL NADU",8 40 | PALLIPATTU,"PALLIPATTU, TAMIL NADU",8 41 | NAGAPATTINAM,"NAGAPATTINAM, TAMIL NADU",7 42 | POLUR,"POLUR, TAMIL NADU",7 43 | PARANGIPETTAI,"PARANGIPETTAI, TAMIL NADU",7 44 | NEYVELI AWS,"NEYVELI AWS, TAMIL NADU",6 45 | R.K.PET,"R.K.PET, TAMIL NADU",6 46 | MANNARGUDI,"MANNARGUDI, TAMIL NADU",6 47 | ULUNDURPET,"ULUNDURPET, TAMIL NADU",6 48 | ARANI,"ARANI, TAMIL NADU",6 49 | VALANGAIMAN,"VALANGAIMAN, TAMIL NADU",6 50 | TRANGAMBADI/TRANQUEB,"TRANGAMBADI/TRANQUEB, TAMIL NADU",6 51 | NEEDAMANGALAM,"NEEDAMANGALAM, TAMIL NADU",6 52 | VELLORE,"VELLORE, TAMIL NADU",5 53 | MADUKKUR,"MADUKKUR, TAMIL NADU",5 54 | KODAVASAL,"KODAVASAL, TAMIL NADU",5 55 | SHOLINGUR,"SHOLINGUR, TAMIL NADU",5 56 | KARAIKAL,"KARAIKAL, TAMIL NADU",5 57 | PERAVURANI,"PERAVURANI, TAMIL NADU",4 58 | SIRKALI,"SIRKALI, TAMIL NADU",4 59 | WALLAJAH,"WALLAJAH, TAMIL NADU",4 60 | VIRUDACHALAM,"VIRUDACHALAM, TAMIL NADU",4 61 | SRIMUSHNAM,"SRIMUSHNAM, TAMIL NADU",4 62 | CHIDAMBARAM,"CHIDAMBARAM, TAMIL NADU",3 63 | TIRUKOILUR,"TIRUKOILUR, TAMIL NADU",3 64 | PATTUKOTTAI,"PATTUKOTTAI, TAMIL NADU",3 65 | UTTAMAPALAYAM,"UTTAMAPALAYAM, TAMIL NADU",3 66 | TIRUVARUR,"TIRUVARUR, TAMIL NADU",3 67 | AYIKUDI,"AYIKUDI, TAMIL NADU",3 68 | MELALATHUR,"MELALATHUR, TAMIL NADU",3 69 | MUTHUPET,"MUTHUPET, TAMIL NADU",3 70 | SENDURAI,"SENDURAI, TAMIL NADU",3 71 | ADIRAMPATNAM,"ADIRAMPATNAM, TAMIL NADU",3 72 | TIRUVANNAMALAI,"TIRUVANNAMALAI, TAMIL NADU",3 73 | SANKARAPURAM,"SANKARAPURAM, TAMIL NADU",3 74 | MAYILADUTHURAI,"MAYILADUTHURAI, TAMIL NADU",3 75 | NANNILAM,"NANNILAM, TAMIL NADU",3 76 | SETHIATHOPE,"SETHIATHOPE, TAMIL NADU",3 77 | ANAIKARANCHATRAM,"ANAIKARANCHATRAM, TAMIL NADU",3 78 | ORTHANAD,"ORTHANAD, TAMIL NADU",3 79 | OMALUR,"OMALUR, TAMIL NADU",3 80 | HARUR,"HARUR, TAMIL NADU",2 81 | SATHANUR DAM,"SATHANUR DAM, TAMIL NADU",2 82 | ALANGUDI,"ALANGUDI, TAMIL NADU",2 83 | PANDAVAIYAR HEAD,"PANDAVAIYAR HEAD, TAMIL NADU",2 84 | TOZHUDUR,"TOZHUDUR, TAMIL NADU",2 85 | PANRUTI,"PANRUTI, TAMIL NADU",2 86 | GUDIYATHAM,"GUDIYATHAM, TAMIL NADU",2 87 | CHENGAM,"CHENGAM, TAMIL NADU",2 88 | TIRUKATTUPALLI,"TIRUKATTUPALLI, TAMIL NADU",2 89 | BARUR,"BARUR, TAMIL NADU",2 90 | SALEM,"SALEM, TAMIL NADU",2 91 | PAPANASAM,"PAPANASAM, TAMIL NADU",2 92 | THIRUMANUR,"THIRUMANUR, TAMIL NADU",2 93 | KALLAKURICHI,"KALLAKURICHI, TAMIL NADU",2 94 | YERCAUD,"YERCAUD, TAMIL NADU",1 95 | ARIYALUR,"ARIYALUR, TAMIL NADU",1 96 | ALANGAYAM,"ALANGAYAM, TAMIL NADU",1 97 | THIRUVIDAIMARUTHUR,"THIRUVIDAIMARUTHUR, TAMIL NADU",1 98 | K.M.KOIL,"K.M.KOIL, TAMIL NADU",1 99 | GANDARVAKOTTAI,"GANDARVAKOTTAI, TAMIL NADU",1 100 | MANAMELKUDI,"MANAMELKUDI, TAMIL NADU",1 101 | PAMBAN,"PAMBAN, TAMIL NADU",1 102 | DHARMAPURI PTO,"DHARMAPURI PTO, TAMIL NADU",1 103 | AMBUR,"AMBUR, TAMIL NADU",1 104 | ARIMALAM,"ARIMALAM, TAMIL NADU",1 105 | DHARAMAPURI,"DHARAMAPURI, TAMIL NADU",1 106 | UTHANGARAI,"UTHANGARAI, TAMIL NADU",1 107 | PAPPIREDDIPATTI,"PAPPIREDDIPATTI, TAMIL NADU",1 108 | MARANDAHALLI,"MARANDAHALLI, TAMIL NADU",1 109 | PENNAGARAM,"PENNAGARAM, TAMIL NADU",1 110 | PERUNGALUR,"PERUNGALUR, TAMIL NADU",1 111 | TIRUVAIYARU,"TIRUVAIYARU, TAMIL NADU",1 112 | VALLAM,"VALLAM, TAMIL NADU",1 113 | VANIAYMBADI,"VANIAYMBADI, TAMIL NADU",1 114 | THANJAVUR PTO,"THANJAVUR PTO, TAMIL NADU",1 115 | ANJATTI,"ANJATTI, TAMIL NADU",1 116 | KRISHNAGIRI,"KRISHNAGIRI, TAMIL NADU",1 117 | KUMBAKONAM,"KUMBAKONAM, TAMIL NADU",1 118 | PALACODE,"PALACODE, TAMIL NADU",1 119 | VAZHAPADI,"VAZHAPADI, TAMIL NADU",1 120 | TIRUPATHUR PTO,"TIRUPATHUR PTO, TAMIL NADU",1 121 | -------------------------------------------------------------------------------- /Unit 9/me.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gbrunner/programming-for-gis-and-rs/e623312548ca5807730f37e625a304ca93e6c36e/Unit 9/me.gif -------------------------------------------------------------------------------- /Unit 9/profile_pic.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gbrunner/programming-for-gis-and-rs/e623312548ca5807730f37e625a304ca93e6c36e/Unit 9/profile_pic.jpg -------------------------------------------------------------------------------- /Welcome.md: -------------------------------------------------------------------------------- 1 | Hi Class, 2 | 3 | My name is Greg Brunner and I am the instructor for **GIS 4090\5090 – Programming for GIS 4 | and Remote Sensing**. I will be using Blackboard for course content management 5 | this semester. Please find the syllabus and relevant links here. 6 | 7 | I currently plan to use the Des Peres 204 lab for each lecture. 8 | If you are not comfortable with attending class in-person, 9 | I intend to record every lecture and post them to Blackboard 10 | immediately following the lecture. If you plan on taking the course remotely, 11 | please let me know as I currently don’t have a record of that. 12 | 13 | This semester presents some logistical challenges 14 | that previous semesters have not. In order to get as much out of the 15 | course as possible this semester, I highly recommend the following: 16 | 17 | 1. Attend the lectures or watch the lecture recordings. 18 | 2. If you do not want to work in the Des Peres 204 lab, have a 19 | good laptop that can support ArcGIS Pro. I will share the 20 | software with you and get you licensed. 21 | 3. Order and read the textbook, [Python Scripting for ArcGIS Pro by Paul A. Zandbergen.](https://www.amazon.com/Python-Scripting-ArcGIS-Paul-Zandbergen/dp/1589484991/ref=sr_1_2?dchild=1&gclid=Cj0KCQjw7Nj5BRCZARIsABwxDKILofmhG-3-PbbnlMNQ5vUN_UOizfO_k7kX4_i4ky76Z1n8YHAjMjAaAnh9EALw_wcB&hvadid=414477414204&hvdev=c&hvlocphy=1020519&hvnetw=g&hvqmt=e&hvrand=1731959480817667638&hvtargid=kwd-867877224600&hydadcr=24602_9648846&keywords=python+scripting+for+arcgis+pro&qid=1597413221&sr=8-2&tag=googhydr-20) 22 | 4. Do all the exercises, homework, and projects and complete them on time. 23 | 5. Communicate with me when you have a challenge or problem that you can not overcome. 24 | 25 | In preparation for class on Wednesday, please log into SLU’s 26 | [ArcGIS Online site](https://slustl.maps.arcgis.com/home/index.html). 27 | Along the top of the landing page, you 28 | should see “Home”, “Gallery”, “Map”, “Scene”, “Notebook”, etc. 29 | Please make sure you see “Notebook” listed there. 30 | If you do not, please let me know before we meet on Wednesday. 31 | 32 | I’m looking forward to working with you this semester! 33 | 34 | Greg -------------------------------------------------------------------------------- /utilities/final_project_order.py: -------------------------------------------------------------------------------- 1 | import random 2 | def randomList(a): 3 | b = [] 4 | for i in range(len(a)): 5 | element = random.choice(a) 6 | a.remove(element) 7 | b.append(element) 8 | return b 9 | 10 | students = ['Dennis Campbell', 11 | 'Govind Chadalawada', 12 | 'Carlissa Cole', 13 | 'Allison Davis', 14 | 'Emily Deeba', 15 | 'John Hamill', 16 | 'Grace Kenney', 17 | 'Jiulin Li', 18 | 'Mason Maimaitijiang', 19 | 'Bethany Marshall', 20 | 'Will McWay', 21 | 'Amy Morris', 22 | 'David Nixon', 23 | 'Kyle Peterson', 24 | 'Nicole Schaeg', 25 | 'Steven Spiegel', 26 | 'Jennifer Thomas', 27 | 'Justin Vilbig'] 28 | 29 | print "There will be " + str(len(students)) + " presentations." 30 | print "Students will present in the following order:" 31 | print randomList(students) -------------------------------------------------------------------------------- /~$S 4090-5090 Programming for GIS&RS Syllabus Fall 2020.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gbrunner/programming-for-gis-and-rs/e623312548ca5807730f37e625a304ca93e6c36e/~$S 4090-5090 Programming for GIS&RS Syllabus Fall 2020.docx --------------------------------------------------------------------------------