Friday, June 16, 2017

Geoprocessing with ArcGIS

This week in python I began learning how to use python to create tools and run models in and out of ArcGIS. I started with Model Builder in Arc. Model Builder is a simple way to run multiple tools in Arc and it allows you to run tools on the output of previous tools. For an example, in this lab the first tool I ran created a clip out of the soil layer that fit to the basin layer.

Inputs: Soil.shp - Basin.shp
    Tool: Clip > Output: Basin_Soil.shp

I can run the Clip tool myself, but with model builder I can run further tools on the output all at the same time. The next thing I wanted to do is remove the parts of the Basin_Soil.shp that weren't farmable land. To do this I needed to run the selection tool to select any shapes that contained the "Not Prime Farmland" attribute. Finally I needed to remove that selection, so I used the Erase tool to remove the selection of "Not Prime Farmland" from the previously created Basin_Soil.shp.

Inputs: Soil.shp - Basin.shp
    Tool: Clip > Output: Basin_Soil.shp
        Inputs: Basin_Soil.Shp
            Tool: Select>Query "FARMLNDCL" = 'Not Prime Farmland' > Output: Basin_Soil_Sel.shp
            Inputs: Basin_Soil.shp - Basin_Soil_Sel.shp
            Tool: Erase>Output: Basin_Soil_Farmland.shp

The final output is the soil layer clipped to the basin with all shapes not containing prime farmland removed. Here's what the output looks like.

The next step of the lab was to convert this model into a Python script, which is an export option in the model builder. Then I opened the created script in PythonWin and modified it so that the user could input their own shapefiles. The modification allows them to direct the script to run the same tools but on any two shapefiles they want, if there is no input it will default to the soil and basin shapefiles.

No comments:

Post a Comment