|
BLOG
|
Python is one of the most popular languages used to script ArcGIS tasks, maybe because it has a relatively low learning curve and it can do a lot. Python is integrated into ArcGIS Desktop. You can create Python add-ins and toolboxes and in ArcMap you can directly enter Python label and MapTip expressions instead of having to load a script file. It's nice to have these options. Amidst all the Python love floating around, some have said ModelBuilder is the forgotten hero of the ArcGIS automation world. They contend that ModelBuilder deserves a bigger share of the spotlight that's shining on Python. I've always found GIS professionals to be visual thinkers who embrace scripting, so it makes sense they would use both Python and ModelBuilder to do their ArcGIS work (and many of you likely do). But if there is a Python vs. ModelBuilder debate, I'll stay neutral by saying that both are valuable and have their place. When an older child angrily accuses them of favoritism towards the unwanted intruder, wise parents know to respond, "We love your little brother just as much as we love you." And so it is with ModelBuilder and Python. Both are tools to automate GIS analysis, data management, and mapping workflows. Unlike Alex and little Sam, they can even play nicely together (you can add a Python script tool to a model, and you can export a model to a Python script). I've heard ModelBuilder called a "visual programming language." This is an interesting way to think about it as it's true there are many things you can do in ModelBuilder that mirror programming techniques—such as creating variables, iterating (looping) through a set of data, setting preconditions, and nesting submodels inside a larger model (similar to calling another script from inside a script). Let's shine a little light on ModelBuilder just in case it is feeling left out. Why might you want to create a model? Visualizing Workflows A model is extremely useful when designing and sharing a workflow, especially when it's complicated. You can always draw on a whiteboard, but dragging and dropping tools into a model scores efficiency points—you can dynamically build and adjust the workflow as you're thinking it through. You can easily rearrange model tools and elements and add text labels to document the flow and datasets being created. When collaborating with others, communicating about a workflow using a model is more effective than reading and scrolling down through a script. A model is like a map—it's a graphical medium that engages people and enhances understanding. You can even export a model to a graphic or PDF file and bring it along to a meeting as a handout. Exploring Results and Testing Scenarios Because you run a model from inside ArcGIS Desktop (ArcGIS Pro or ArcMap), you can examine the results immediately. In this way, a model is part of the daily fabric of your GIS work. If the model output creates a new question to investigate, all you have to do is change a model parameter (e.g., switch out a tool's input dataset or value) and rerun a process or rerun the entire model, then explore what that yields. With a script, it's certainly doable but not as easy to work iteratively like this. You have to open the script file, find the lines of code that need to be edited, make the edits, save the script, run the script, then possibly open ArcMap and add the output and maybe some other layers for context. To make things easier, you can start by loading the script into the Python window in ArcGIS and go from there. Identifying Problems One of the cool things about a model is that you can eyeball its progress as it runs. As each process executes, the tool flashes red and a drop-shadow displays under its elements when the process completes. You can immediately tell where an error occurred in the model because it stops processing there. Just find the first process that doesn't have a drop-shadow. After correcting the error, you can continue running the model from that point—you don't have to go back to the beginning. Just right-click the tool element in the process that failed and choose Run. Identifying the location of a problem in a script is not always as fast. Applying Skills You Already Have The most obvious reason to create a model over a script is that you lack scripting skills, whether Python or any other language, and you don't want or can't afford to invest the time to learn scripting. Though these days it's fairly easy to acquire basic Python skills. From Esri alone there are free tutorials, presentations, training seminars, and free and low-cost web courses. ArcGIS geoprocessing tools output Python code snippets you can examine to learn from and then modify to suit your needs. Basic Python skills don't cut it, however, if you need to automate an advanced workflow. Models chain together and run geoprocessing tools, so if you are a GIS professional who uses ArcGIS, more than likely you already have the skills required to create a model. Setting up a model correctly requires time and planning, like any other task. You have to understand your data, environment settings, tool parameters, and desired outputs. There are nuances and more advanced capabilities of models that you may need to educate yourself about, but again there are lots of resources to do so (see the list at the bottom of this post). In the end, the choice of whether to automate an ArcGIS workflow using a script or a model comes down to what you feel most comfortable doing. Python is a logic-driven text-based tool and ModelBuilder is a logic-driven visual tool. When feeding your culture appetite, sometimes you want to read a great novel and sometimes you want to look at a beautiful painting. Similarly, there may be times you want to write a script and other times you want to create a model. The beauty of ArcGIS is that you can easily do both, right inside ArcGIS Desktop. Related posts: ModelBuilder 101 for ArcGIS Pro ModelBuilder 101 (ArcMap) Resources to learn more about ModelBuilder: Esri training options ArcGIS Help (ArcGIS Pro, ArcMap) Resources to learn more about Python scripting: Python website Esri training options for Python
... View more
08-16-2012
10:32 AM
|
0
|
0
|
2366
|
|
BLOG
|
Updated February 13, 2018 A previous post covered converting standard annotation to feature-linked annotation—to recap, it cannot be done directly. A recommended workflow when you have standard annotation that you wish were feature-linked is to create an empty feature-linked annotation class, then append the standard annotation features to it (using the Append Annotation Feature Classes tool). Several readers have wondered, once you have feature-linked annotation in place, what happens when you need to replace the data linked to the annotation? No one wants to repeat the work of setting up annotation if they can avoid it. Can you change which feature class your feature-linked annotation is linked to? The answer is no. Feature-linked annotation can be associated with only one feature class (the one specified when the feature-linked annotation was created). The feature-linked annotation and the feature class participate in a relationship class that you cannot alter. Despite this, when you receive new data, there is a way to preserve the annotation. Consider this scenario: Every month, you receive updates to a geodatabase feature class in shapefile format. Each month, features have been deleted, there are new features to be added, and remaining features have changes. Replacing the data would be faster than editing the existing feature class. However, the feature class has linked annotation. A reader shared a solution for this situation: delete the existing features from the feature class (thus creating an empty feature class), then append the new features to repopulate the feature class. This solution works and it's a good one when you have data that changes a lot and doesn't participate in table joins or relationships (besides feature-linked annotation). This method is not advisable in all situations. Before deleting features, check your workflows to make sure there are no unintended impacts. Depending on how extensive the data changes are, you can replace all features or just a selected set. Below are the steps to do this using ArcMap. Of course, before deleting any data, it's always wise to make a backup copy first. For example, you could create a file geodatabase in an archive workspace and copy the feature class and feature-linked annotation class to it before performing the steps below. To create or edit a feature class that has feature-linked annotation, you need an Standard or Advanced license of ArcGIS Desktop. Delete Existing Features In ArcMap, open a blank map document and add the feature class that needs to be updated and its feature-linked annotation to the Table of Contents. Start an edit session. Select the features you want to delete. You can build a query expression to select a subset or, to delete all features, right-click the feature class layer and click Selection > Select All. Click the Delete button, then save your edits. Stop the edit session. Open the attribute table for the feature-linked annotation and note that its features have been deleted as well. Append Replacement Features Add the dataset that contains the new data to the map document. The Append tool accepts map layers, shapefiles, and geodatabase feature classes (and other data types) as input. You can use its optional Schema Type and Field Map parameters to control how attributes are treated. In the Catalog window, expand Toolboxes > System Toolboxes > Data Management Tools > General (or just use the Search window to search for "append"). Double-click the Append tool to open its dialog box. For Input Dataset, click the drop-down arrow and choose the layer that stores the new data. For Target Dataset, choose the existing feature class, then click OK to run the tool. After the Append tool finishes running, open the attribute tables for the updated feature class and the annotation. Note that the features were added and new annotation features were created for them. Review the features and annotation on the map and reposition individual annotations as needed, based on the new feature locations and shapes. So there you have it: an easy way to mass-update data and associated feature-linked annotation. Thanks to reader Pedonkus for sharing this solution. If you regularly receive new data to replace current data that has feature-linked annotation, you can automate this process using a Python script. The ArcPy site package includes the UpdateCursor function (can use to delete existing features). The Append tool help topic includes example Python code. Related Post: ArcGIS Annotation: Woes and Woohoos
... View more
04-04-2012
05:46 AM
|
0
|
2
|
1361
|