model builder tutorial

23
Automating Tasks with ModelBuilder in ArcGIS Presented at the 2008 International Association of Crime Analyst’s Conference (IACA) in St. Petersburg, Florida on October 14 th , 2008. Todd Wiles Crime Analyst II Jacksonville (FL) Sheriff’s Office Jim Mallard Crime Analysis Supervisor Arlington (TX) Police Department

Upload: madalina-bouros

Post on 27-Nov-2014

232 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Model Builder Tutorial

Automating Tasks with ModelBuilder in ArcGIS

Presented at the 2008 International Association of Crime Analyst’s Conference (IACA) in St. Petersburg, Florida on October 14th, 2008.

Todd Wiles

Crime Analyst II Jacksonville (FL) Sheriff’s Office

Jim Mallard

Crime Analysis Supervisor Arlington (TX) Police Department

Page 2: Model Builder Tutorial

2

Model #1: Create an Address Locator and Geocode Incidents

Scenario: Create a feature class from tabular crime data. This model will create the

necessary locator and output a layer of geocoded crimes.

1) Open ArcMap 9.2 through the start menu or by clicking the icon on the desktop

2) Click the radio button to Open an existing map, then double click Browse for

maps…

3) Navigate to C:\Model_Builder and open Model_Builder_Map.mxd

4) Open the ArcToolbox pane by click the red toolbox

5) Right-click in the ArcToolbox pane and choose New Toolbox, name the Toolbox

IACA Conference 08

6) Right click on the newly-created Toolbox and choose New->Model

7) Adjust the size of the model window so it is roughly the size of the map window.

8) Expand the Geocoding Tools toolbox in the ArcToolbox pane

9) Drag the Create Address Locator tool into the model window

10) Double-click on the square Create Address Locator then click the file button

next to “Address Locator Style”

11) Scroll down and choose US Streets then click OK

12) Click the file button next to Reference Data.

13) Click the Add Connection icon and browse to C:\Model_Builder; select the

folder and click OK.

Page 3: Model Builder Tutorial

3

14) Browse to the GIS data folder and select the Streets layer. Click add.

15) Click the drop down next to Role and change Streets.shp to the “Primary table,”

the fields in the table will map automatically.

16) Click the file button next to “Output Address Locator” navigate to

C:\Model_Builder\GIS data and name the locator “Gotham_Address_Locator”

17) Click OK.

Page 4: Model Builder Tutorial

4

18) From the Geocoding Tools toolbox drag the Geocode Addresses tool into the

model and place it to the right of the Gotham_Address_Locator (green oval).

19) Double-click on the rectangle Geocode Addresses

20) Click the file next to Input Table and browse to C:\Model_Builder\Crime data

open the database Crimes.mdb and select the MO table

21) Click the drop-down next to Input Address Locator and select

Gotham_Address_Locator

22) Click the drop-down under “Alias Name” and change it from <None> to

Address_of_Crime

Page 5: Model Builder Tutorial

5

23) Click the file button next to “Output Feature Class”, navigate to

C:\Model_Builder\Student Data open the database Student_Data.mdb and name

the Feature Class Gotham_Incidents

24) Click Save.

25) Click OK to return to the model.

26) Click the Auto Layout button

27) Click the Full Extent button

Page 6: Model Builder Tutorial

6

28) From the model window, choose Model --> Run Entire Model

29) When the model completes, close the dialog box and click Model -->Model

Properties…

30) Click the General tab and name the model Geocode_Crime_Data. Put the name

in both the Name box and the Label box. Add the following text to the description

field:

This model geocodes Gotham crime data

31) Click OK

32) Click Model->Save, then close the model window

33) Add the newly geocoded feature class to the map by browsing to

C:/Model_Builder/Student Data/Student_Data.mdb then adding

Gotham_Incidents

34) Save your map.

Page 7: Model Builder Tutorial

7

Model #2: Select incidents by attribute and by location

Scenario: Select all residential burglaries within 100 feet of the apartment complexes in

the city

1) Right-click the IACA Conference 08 Toolbox and choose New->Model.

2) Expand the Data Management Tools toolbox and then expand the Layers and

Table Views toolset. Drag the Select Layer by Attribute tool into the model.

3) Double click on the Select Layer by Attribute tool in the model and click the drop

down next to “Layer Name or Table View”; select Gotham_Incidents.

4) Click on the SQL calculator next to the Expression box and build the expression:

[Crime] = 'BURGLARY RESIDENTIAL'

5) Click OK twice to return to the model.

6) Drag the Select Layer by Location tool into the model window and position it to the

right of the green oval.

7) Select the connector tool and drag a connection from Gotham_Incidents to the

Select Layer by Location tool.

8) Switch back to the selection tool

Page 8: Model Builder Tutorial

8

9) Double-click on the Select Layer by Location tool; the Gotham_Incidents layer

should be visible as the “Input Layer”.

10) Click the drop-down next to Overlap Type and change the selection to

“WITHIN_A_DISTANCE”

11) Click the drop down-down next to Select Layer and choose apartments

12) Enter 100 into the “Search Distance” box

13) Change the “Selection Type” to “SUBSET_SELECTION”

14) Click OK.

15) Click the Auto Layout button

16) Click the Full Extent button

17) Expand the Data Management Tools toolbox then expand the Features toolset.

Page 9: Model Builder Tutorial

9

18) Drag the Copy Features tool into the model window and position it to the right of the

other elements in the model.

19) Select the Connector tool and connect Gotham_Incidents (3) (green oval output)

to the Copy Features tool:

20) Switch back to the selection tool

21) Click the Auto Layout button

22) Click the Full Extent button

23) Double click the Copy Features tool in the model.

24) For the Output Feature Class, browse to C:\Model_Builder\Student

Data\Student_Data.mdb and save the Feature Class as Res_Burg_Selection

25) Click Save.

Page 10: Model Builder Tutorial

10

26) Click OK. The completed model is shown below:

27) Right click on Res_Burg_Selection and uncheck the “intermediate” option***.

Page 11: Model Builder Tutorial

11

28) Go to Model --> Model Properties. Name the model Res_Burg_At_Apartments and

enter the same for the label.

29) Enter the following for the description:

This model selects residential burglaries within 100 feet of apartment complexes

within the City of Gotham.

30) Click OK and save the model (Model--> Save).

31) Close the model.

32) To run the model, double click the model from the IACA Conference 08 toolbox, and

then click OK to run.

33) Close the geoprocessing window.

34) Browse to C:\Model_Builder\Student Data\ Student_Data.mdb and add the output just

created (Res_Burg_Selection) to the map. This layer is a selection of all residential

burglaries within 100 feet of the apartment complexes in the City of Gotham.

35) Go to Selection --> Clear Selected Features, and then save the map.

Page 12: Model Builder Tutorial

12

Note about this model: This model creates a selection and also outputs the selection as a layer. If you only want to make a selection (and do not want a new layer created), you can omit steps 23-27 from the model.

*** Intermediate data is data created to connect tools and processes within models. You do not always want to keep every output, often only the last one. By default, when you run a model from the model window (as we have in this class), intermediate data is not deleted. However, when you run a model from its dialog box (e.g. double clicking on it from the toolbox), intermediate data is deleted. This leads to confusion as the data appear to be created every other time you run the model; to avoid this, just uncheck the “intermediate” option on any output data that you want to save.

Page 13: Model Builder Tutorial

13

Model #3: Create a buffer layer of a street segment and create a

separate layer of all crimes within this buffer.

Scenario: You want to monitor crime activity within 500 feet of Northwest Highway. You

also need a buffer layer of the road for your map. This model creates the buffer and it

also creates a layer of all crimes occurring within 500 feet of the road.

1) Create a new model (right click on toolbox and select new model)

2) Drag in the Select by Attributes tool (from Data Management Tools -->Layers and

Table Views) and double click it:

a. Select Streets as the Layer Name or Table View

b. Make a NEW_SELECTION

c. Set the Expression to "STREET_NAM" ='Northwest'

Page 14: Model Builder Tutorial

14

3) Click Ok twice to return to the model.

4) Expand the Analysis Tools toolbox then expand the Proximity toolset. Drag the

Buffer tool into the model.

5) Connect the streets output (green oval) to the buffer tool (using the connector tool)

6) Double click the buffer tool:

a. Save the output feature class as NWHwy_Buffer in Student_Data.mdb

b. Specify the distance as 500 feet

c. Choose ALL for the dissolve type.

7) Click OK to return to the model.

8) Right click on NWHwy_Buffer in the model and uncheck “intermediate”.

Page 15: Model Builder Tutorial

15

9) Drag the Select by Location tool into your model (from Data Management Tools --

>Layers and Table Views) and double click it:

a. Select Gotham_Incidents as the input layer

b. Choose INTERSECT

c. Select Layer = NWHwy_buffer

d. Make a NEW SELECTION

10) Click OK.

11) Click the Auto Layout button

12) Click the Full Extent button

13) Drag the Copy Features tool (from Data Management Tools -->Layers and Table

Views) into your model.

14) Connect it to the Gotham_Incidents output (green oval).

15) Double click the Copy Features tool and save the output as Incidents_500_NWHwy

into the Student_Data.mdb database.

16) Click OK

17) Right click on incidents_500_NWHwy and uncheck “intermediate”.

18) Click the Auto Layout button

Page 16: Model Builder Tutorial

16

19) Click the Full Extent button

20) The finished model should look like the one below:

21) Click Model->Model Properties…

22) Click the General tab and name the model “NWHwy_Buffer”. Put the name in both

the Name box and the Label box. Add the following text to the description field:

This model creates a buffer of Northwest Hwy and also creates a layer of all crimes

within 500 feet of Northwest Hwy.

23) Click OK.

24) Save the model (Model --> Save) and close it.

25) Double click on the model from the toolbox and click OK to run it.

26) Close the geoprocessing window once the model has completed.

27) Add the Incidents_500_NWHwy and NWHwy_Buffer layers from the

Student_Data.mdb database to your map (hint: use the Ctrl key to make multiple

selections).

28) Go to Selection --> Clear Selected Features.

29) Examine the created layers.

30) Save your map.

Page 17: Model Builder Tutorial

17

Model #4: Create a density layer of residential burglaries within 100

feet of apartment complexes.

Scenario: Create a model which builds a density layer of the selected residential

burglaries within100 feet of apartment complexes. You want to look for hotspots of

burglary activity near apartment complexes.

1) Create a new model in the Conference Toolbox.

2) Expand the Spatial Analyst Tools toolbox then expand the Density toolset. Drag the

Kernel Density tool into the model.

3) Adjust the settings as follows:

a. Browse to the Student_Data.mdb file and choose Res_Burg_Selection as the

input feature.

b. Leave population field to NONE

c. Save the output raster to C:\Model_Builder\Raster and call the raster

res_burgs. Click Save.

d. Specify 30 for cell size

e. Specify 2000 for search radius

f. Leave area units as SQUARE_MILES

g. Click OK to return to the model.

Page 18: Model Builder Tutorial

18

4) Go to Model Model properties.

5) Name the model res_burg_density and enter that for the label as well.

6) Enter the following for the description:

This model builds a density from the residential burglaries within 100 feet of apartments.

7) Go to the Environments tab.

8) Expand the General Settings box and check the Extent box.

9) Click the Values button.

Page 19: Model Builder Tutorial

19

10) Click General Settings and select Same as Layer Gotham as the basis for the

extent. This setting means the model will use the city boundary as the basis of the

raster; otherwise it uses the extent of the source layer.

Page 20: Model Builder Tutorial

20

11) Click OK twice to return to the model.

12) Right click on res_burgs in the model and uncheck “intermediate”.

13) Click the Auto Layout button

14) Click the Full Extent button

15) Save the model (Model --> Save).

16) Go to Model Run Entire Model.

17) Close the geoprocessing window once the model has completed.

18) Close the model, saving the changes if needed.

19) Click the Add Data button and add the res_burgs raster from the Raster folder

(C:\Model_Builder\Raster).

20) Move the layer just below the streets.

21) Double click the res_burgs density layer and go to the symbology tab. Choose

Classified from the left and symbolize as follows:

Page 21: Model Builder Tutorial

21

Hint: Set to 7 classes; make the 1st class white, the 4th class mars red and the last class

solar yellow. Select those three, right click and select “Ramp Colors”. Then change the

first one from white to ‘no color’.

22) Click OK and save your map. Turn off the point layers and your map should look

similar to the one below:

Page 22: Model Builder Tutorial

22

23) Close ArcMap – End of Tutorial!

Page 23: Model Builder Tutorial

23

Saving the toolbox you created in this class

The toolbox you created is stored in:

C:\Documents and Settings\%username%\Application Data\ESRI\ArcToolbox\My

Toolboxes

Where %username% is the username that you are logged in as on the training computer.

It is likely the only user listed in the Documents and Settings folder.

Copy the .tbx file to a thumb drive:

To load it on your computer, right click in ArcToolbox and choose “Add Toolbox”, then

browse to wherever you saved the toolbox. Note that ArcToolbox links to toolboxes (it

does not copy them to the location above), so you’ll want to copy it from your thumb

drive to a permanent location before loading it into ArcToolbox.

Also note that a completed version of the toolbox is in the Solution data folder, so you

can refer to that one as well.

Other notes about toolboxes:

• ArcMap and ArcCatalog use the same toolboxes. If you have both applications open and make changes to a toolbox in one program, the change will not be reflected in the other application until you close and re-open it.

• It is a good practice to store shared toolboxes on a network drive so that other users can access them. Any changes to the toolbox will be available to all users who have that toolbox loaded.