From the course: Learning ArcGIS Python Scripting
Where Python is used in ArcGIS - ArcGIS Pro Tutorial
From the course: Learning ArcGIS Python Scripting
Where Python is used in ArcGIS
- [Instructor] Now that we understand the basics of scripting, let's take a look at the different languages used in ArcGIS. There are several languages used and each has its purpose. SQL, also called sequel, is for querying or filtering data, which you do in select by attributes, definition queries, and when you're creating label classes. VB Script can be used for label expressions and field calculations. Arcade can also be used for label expressions and field calculations, so there's some overlap there, but Arcade is cross platform, meaning it works the same whether you're running that Arcade script in Windows or on an Android device or on an iPhone. Arcade can also be used to create custom popups and dynamic symbology on the fly. JavaScript is used in ArcGIS Pro to create label expressions, but also used for creating custom web mapping applications. There's also an ARCMaps software development kit, SDK for JavaScript, but we'll have to save that discussion for another course. And then there's Python, of course. Python can be used in label expressions and field calculations, but Python is also used to create scripts that are run as custom tools in ArcGIS Pro, or even published as geoprocessing services to run in ArcGIS Enterprise. Python scripts can also update maps based on data path changes, manage users and groups in AGOL or Portal and automate data maintenance processes. So Python scripts are used for bigger tasks. They can efficiently process large amounts of data, for example, making sure all of your feature classes are in the right coordinate system, publishing feature services from your updated feature classes on a regular basis, or checking 100,000 road segments to see if there are any overlapping address ranges. Python can also be used to automate processes. For example, suppose there's a government website that posts updated crime stats to their website weekly in tabular form. You could write a script that would download that table from the website, geocode the addresses in the table, and update the web service in one of your dashboards to point to that new crime data. And then you could schedule that script to run automatically early every morning before everyone gets into the office. Python can also be used to easily test alternate scenarios. For example, import this pipeline dataset, buffer all the pipelines by a thousand feet, clip the soils in the area, calculate the area of the acidic soils within a thousand feet of pipelines. What happens if I reduce the buffer distance to 500 feet, say, and pipeline can also be used to discover things. For example, suppose someone leaves your organization and you need to go change ownership of all of that person's web services. You could write a script to do that, and the script would simply prompt you for the existing owner's username and the name of the new owner at run time, and then it would go out and discover or find all the data sets owned by that old owner. That makes the script reusable. Now let's see where we write this Python code. ArcGIS Pro has several utilities for writing Python scripts. For testing simple one-liners and short scripts, ArcGIS Pro includes a Python command window. You find it in here under the Analysis ribbon, Python, Python Window. If the scripts involve a lot of geoprocessing, you can start by creating a model in Model Builder and then exporting that model to a Python script where you can further enhance the functionality by modifying the code. Here you can see a model that's already been created, and I can go here and export it directly to a Python file or send it to the Python window if I want. Python scripts can also be written from scratch and added as script tools to be run from Arc Toolbox. The scripts are written in an integrated development environment, an IDE. There are lots of IDEs that support Python, including IDLE, idle, which is installed with ArcGIS Pro, ArcGIS notebooks built on something called Jupyter Notebooks, Spyder, PyCharm, Visual Studio Code, and you can even use Notepad++. Where you write the script doesn't matter. What matters is that you import the GIS libraries, but each IDE does have its strengths. For example, ArcGIS Notebooks and Visual Studio Code are two IDEs commonly used by GIS professionals. Both have great syntax highlighting and code formatting, but ArcGIS Notebooks is much better for data visualization and exploration. Plus, it's easy to document your code and share the entire story of what your Notebook does. It's also really nice that with ArcGIS Notebooks, you create your code in little cells and the cells can be run in any order you like. Unlike Visual Studio Code and most other IDEs where you have to run the entire script from top to bottom to test anything in the script. ArcGIS Notebooks is installed with ArcGIS Pro, which also makes it really easy to use. Visual Studio Code is another IDE with a lot of strengths. It's got great code completion, nice debugging tools, and it's really easy to share the scripts. It doesn't come with ArcGIS, so it's a separate install, but it is free. Honestly, I go back and forth between ArcGIS Notebooks and Visual Studio Code, depending on the project. Visual Studio Code is preferred for larger scripting efforts that involve scripts calling other scripts. In this course, we're going to use ArcGIS Notebooks, mostly because it's available inside ArcGIS Pro, so there's nothing extra to install. When you finish this course and get comfortable with basic Python scripting, you should come back to this video and make a list of the IDEs that we mentioned so you can research each one and see what will work best for your purposes. Also, maybe ask around your organization and see if there's a preferred IDE that's used by other developers that might already be installed on your system. Here's where you find Notebooks in ArcGIS Pro. It's in analysis, Python, Python Notebook. It opens as another tab in your ArcGIS Pro interface. I'm going to get rid of the Python window here just to clean it up a little bit. You can find your existing notebooks over here in the catalog tree, so if you close one of these notebooks, you can always reopen it by finding it in the catalog tree and right-click and open, so notebooks are stored with the project. If you want to see where they actually live out on the disc, you can right-click on any of these notebooks in your catalog tree and choose show in file explorer, and it'll show exactly where that file lives. But notice again, it's in the project folder. If you write your Python code in Jupyter Notebooks or another IDE, you can just run the code right in the IDE to see the results. But sometimes you might want to attach the script to a tool. You'll learn how to do that later in the course. But Python scripts don't have to be attached to tools, they can exist as standalone scripts that are run directly from Windows just by double-clicking on them. They can also be scheduled to run automatically by the Windows scheduler. This is an excellent option for scripts that manage large amounts of data and may take a long time to run.
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.