In my last blog post about overlay, I introduced the concept of cartographic spaghetti and how it can be used to split polygons by line features. In this post, I want to continue with the cartographic spaghetti theme by introducing a companion concept: meatballs, which are the centroids of the spaghetti polygons. I’ll show how spaghetti and meatballs can be used to calculate the number of overlapping polygons.
Downloads
If you’re looking for a tool you can use immediately to count overlapping polygons, you can download the Count Overlapping Polygons tool. You can also download the sample data and model used in this post here.
The scenario
The Deepwater Horizon oil spill in the Gulf of Mexico lasted from April 20 to July 15, 2010. During this time, NOAA mapped the extent of the plume daily and distributed it in various GIS formats. The map below uses this data to show the plume concentration over 67 days. The count value in the legend is the number of days the plume covered an area. Since there is one polygon per day, count is simply the number of overlapping plume polygons.
Counting overlaps
The easiest and fastest way I’ve found to count the number of overlapping polygons is the ‘spaghetti and meatballs’ method described below. To use this method, you need a single feature class containing all the overlapping polygons. For example, the oil spill data above started out as 67 feature classes, each containing one polygon, and I used the Merge tool to merge all 67 features into one feature class (the Append tool can also be used).
To illustrate the details of this technique, I’ll use the dataset shown in Figure 2, one I created by buffering a bunch of point features.
Create some spaghetti
The first step is to create some cartographic spaghetti from the overlapping polygons. As described in the previous post, the Feature To Polygon tool does this for you. Feature To Polygon takes one or more line or polygon feature classes and creates a polygon feature class as output. And, as mentioned in the post, you want to avoid having any attributes on the output of Feature To Polygon and there’s a trick you can use of supplying an empty point feature class to the Label Features parameter of Feature To Polygon. (Alternatively, you could use the Delete Field tool.) Figure 3 shows the model to create an empty point feature class in memory and connecting it to Feature To Polygon.
The output of Feature To Polygon is shown on the right side of Figure 4. The left side is the original overlapping polygons and I’ve highlighted two void areas that are made into polygons by Feature To Polygon. I call these ‘artifact’ polygons. I note these because such artifact polygons require a bit of special handling later.
Create some meatballs
The next step is to create a centroid point for each polygon in the output of Feature To Polygon. These centroids are the ‘meatballs’ of the spaghetti and meatballs technique. We’re going to use these points in an overlay of the original overlapping polygons to produce a count.
To create the meatballs, use the Feature To Point tool, illustrated in Figure 5. Be sure to check the Inside option—this guarantees that the point created will be inside the polygon.
Figure 6 shows the meatballs inside their spaghetti polygons along with the attribute table. On the attribute table, ORIG_FID is the OBJECTID(feature ID) of the spaghetti polygon from which the point was constructed.
Point-in-polygon overlay
Now comes the interesting part—we overlay these meatball centroids with the original overlapping polygons to get a count of how many polygons overlap each meatball point. There are several ways we can do this. For example, the Intersect tool could be used to create a new point feature class containing one point for each polygon that overlaps it. The next step would be to count up the number of occurrences of ORIG_FID using the Summary Statistics tool. But this is a lot of steps to go through just to get the count.
I’ve found the fastest way is to use the Spatial Join tool. Figure 7 shows the model and dialog.
Figure 8 shows the attribute table of the result of Spatial Join – a copy of the meatball point feature class with a Join_Countfield, which is the number of polygons that overlap the point.
A couple of things to note about the Spatial Join parameters:
-
- The Join Operation parameter is JOIN_ONE_TO_ONE, notJOIN_ONE_TO_MANY. Choosing JOIN_ONE_TO_MANY would result in many more points output—if a point was overlain by 3 polygons, 3 points would be output—and Join_Count would not be calculated.
- Keep All Target Features is checked. If it was unchecked, the artifact polygons would not be joined. We need them in the output because we want to find them (their Join_Count will be zero) and delete them.
- In the Field Map parameter, I remove all attributes except ORIG_ID, the only attribute I care about.
- Finally, the Match Option is WITHIN, which means only Join Features (the overlapping polygons) will be matched if a Target Feature(meatball) is within them. The INTERSECT Match Option would also work here.
Copy the Join_Count field
Now all we need to do is to copy the Join_Count field back to the spaghetti polygons. I use the Join Field tool for this, illustrated below.
Deleting artifacts
The final step is to delete the artifact polygons described above. All we need to do is select those polygons with a Join_Count equal to zero and delete them. Here’s the last piece of the model that does this:
In the Make Feature Layer tool, the Expression parameter value is “Join_Count” = 0. This creates a layer with the two artifact polygons selected. Delete Features is executed on this layer to delete these two polygons. (When the Delete Features tool is executed in the above model, it will always issue WARNING 000117: Warning empty output generated which you can ignore.)
Oil spill revisited
Let’s go back to the original 67 oil spill polygons for a moment. Running Feature To Polygon on these 67 overlapping polygons results in 18,733 unique polygons with a maximum Join_Count of 65. To count overlaps on these 18,733 polygons using the spaghetti and meatballs method takes about 65 seconds on my laptop. Using 64bit background processing, it takes 44 seconds.
Summary
Overlapping polygons in a single feature class is not uncommon. By creating spaghetti with the Features To Polygon tool, you can resolve the overlaps and begin further analysis. The technique of creating meatballs (centroids) of the spaghetti gives you a point feature class that can be used in overlays to discover other properties, such number of overlaps as was done with the oil spill data above. In a future post, I’ll show how you can use this technique to resolve one-to-many problems that occur frequently in ecology data, where geographic extent (the range) of an individual species is captured as a single polygon, and the task is to find overlapping ranges and the species within.
A final note: this spaghetti and meatballs technique is not a substitute for standard overlay tools such as Intersect, Identity, and Union. Spaghetti and meatballs is only for data that has the exact same attribute schema—that is, you have a single feature class with overlapping polygons. If you have two or more feature classes, such as one of soil data and another of slope data, you’ll want to use the standard overlay tools.
Read the next blog in this series: spaghetti, meatballs, and the one-to-many problem
Commenting is not enabled for this article.