Select to view content in your preferred language

ArcGIS Pro Python

337
1
07-13-2022 12:23 PM
Williams_Gregory
New Contributor II

I'm looking to create a tool or script using python that will list the selected records from a polygon feature layer after clicking a location.  I will then use information from a specific field (file location) to import into the current map a TIF image or CAD DWG file.  I'm new to python programing and I'm just looking for some suggestions on where to the start.  Every time I think I have found a existing geoprocessing tool within ArcGIS Pro that I can copy python code into model builder or the python window it's just a dead-end.  Any suggestions would be helpful...Thanks!

 

 

0 Kudos
1 Reply
KalinaStoycheva
New Contributor II

When you say select by location you mean select by the attribute of another polygon layer right? if so, the tool for selection is relatively simple to build. Here are the steps:

1. From Analysis choose Model builder to open your new model.

2. From Analysis again choose tools and search for the Select Layer by Location tool. Once you see it click and drag it to the Model builder panel. 

3. Again from the geoprocessing window search for  Select tool and drag it as well. This is what you should see:

KalinaStoycheva_1-1657788467263.png

4. Click on the right corner of the output feature class box of the Select tool and drag it to Select layer by Location box to connect them. From the connect options choose Selecting Features.

KalinaStoycheva_2-1657788771199.png

5. Right click on Select Layer By location and choose Create Variable -> From Parameter -> Input Features (this will be the layer with the selected features). One it's created right click on it and make it a Parameter. Parameters are the variables that can be seen once you run the model.

6. Right click the Select Layer By Location and choose Create Variable -> From Parameter -> Selection type. One it's created double click on it and from selection type choose Select Subset from current selection. Now the tool can select only from the already selected features. If you wish you can make this one a parameter as well so the tool can be used for different selections.

7. Right click the Select Layer By Location and choose Create Variable -> From Parameter -> Relationship. Once it's created double click on it and select some variation of Within depending on what you aim to select. Make it a parameter as well for more options in the future.

8. Right click on the Select box and choose Create Variable -> From Parameter -> Input Features (this will be the location layer in which you select). One it's created right click on it and make it a Parameter. Right click on it again and rename it to Location feature. It is important to note that the best feature to use here would be polygon type.

9. Right click on the Select box and choose Create Variable -> From Parameter -> Expression. Make the expression a Parameter as well, so that once the polygon layer with the location is chosen you can select the location by name or other attribute.

The result should look like this:

KalinaStoycheva_0-1657796549836.png

10. At the top from the ribbon next to the Save choose Properties

KalinaStoycheva_2-1657796710836.png

Choose parameters. Here you can see all the parameters that would be shown once the model is run as well as their order. Change the order to your liking, I personally did it like this:

KalinaStoycheva_3-1657796887694.png

 

11. Now that the model is ready save it from the top with the appropriate name

KalinaStoycheva_1-1657796644941.png

12. The model is ready to run. From geoprocessing search for it by name choose it and run it. If you wish to see all selected features, simply open Attribute from the selection ribbon. If you wish to list them outside of the program in a table just export them, or try to experiment with the model by dragging and adding the table to table or table to excel instrument  with the output of the model as an input for them. For more info on how to build models check this Use ModelBuilder—ArcGIS Pro | Documentation or watch this clip Make a Geoprocessing Model in ArcGIS Pro - Bing video.

0 Kudos