I think this blog post follows up nicely to Dan Patterson's recent blog post, ...That empty feeling... The conversation about null and empty geometries in ArcGIS isn't new, but it does take some getting your head around.
When it comes to creating new feature classes, I am sure most people are quite familiar with the following screen from the New Feature Class wizard:
When creating a new feature class using ArcGIS Desktop, either through the GUI or ArcPy, the default settings allow for NULL values in the SHAPE field (see yellow highlight above). Regardless of whether NULLs in the SHAPE field are a good or bad idea, they are supported and allowed by default, so it is good to understand what does/can happen when geometries aren't populated with the rest of a record in feature classes.
After troubleshooting several cases where NULL wasn't NULL, I decided to take a deeper look at what really happens when geometries aren't populated in feature classes. It turns out, the answer depends both on the tool and type of geodatabase being used to insert, store, and retrieve records. Presented here are the results for some of the more common tools and types of geodatabases.
Table 1 shows what actually gets populated in the SHAPE field when nothing, None, an empty geometry, and a non-empty geometry are inserted into a polygon feature class using three different methods.
|TABLE 1: SHAPE Field Values in Feature Class|
Table 2 shows what gets returned by search cursors once the records from Table 1 have been inserted into a feature class.
|Table 2: Retrieved Geometry/Object From SHAPE Field|
It is clear there are some differences, inconsistencies one might say, with how different tools insert nothing or empty geometries into a feature class that allows NULL values. Even with the same tool, there are situations where nothing or empty geometries are handled differently between different types of geodatabases. There are also differences with how different search cursors, and likely update cursors, retrieve empty geometries from feature classes.
I can't say what it all means, but there are a few items that stuck out for me.
- Non-empty geometries are handled consistently across tools and types of geodatabases.
- "Allow NULL Values" for the SHAPE field doesn't mean missing geometries will be NULL, it means missing geometries may be NULL, they could also be empty.
- The ArcPy Data Access search cursor returns None whether a SHAPE field is NULL or contains an empty geometry, so None doesn't necessarily mean NULL for geometries.