Spatial Join
A spatial join is the process that can be used to count the number of items contained within a boundary. There are other spatial join processes that can also be performed, but this is the most common use of this command. For example, if the location of students at a college is available, then a spatial join can be used to determine how many students live in each census tract in a county.
In this example, the number of doctors within the state of Kentucky will be counted per county.
In this example, the number of doctors within the state of Kentucky will be counted per county.
- Loading arcpy, setting the environment, and the workspace are set in the first three lines of functional code.
- The next three lines of functional code defines three variables.
- The SpatialJoin command is located in the analysis toolbox.
- The first parameter is the boundary file, for this example it will be a Kentucky County shapefile.
- The second parameter is what shapefile will be counted, for this example it is KY_doctors.
- The final parameter is the name of the output file, which will contain a new field for the count.
- Each row of the Kentucky county file represented an individual polygon, which is generally a single county (there are a few exceptions in western Kentucky). Note, the output file is created as part of the process.
- Open in ArcMap and explore the results.