How to avoid Null Geometry in Point FC

742
2
Jump to solution
07-25-2019 08:29 AM
JoeBorgione
MVP Emeritus

As a follow up to an early post where the Create Locator tool in ArcGIS 2.4 is failing for me due to Null Geometry in two point features, I'm trying to find those records and not select them.  The initial data source is an Enter Geodatabase (aka SDE) point feature class, however I make a selection on those records based on a specific requirement and copy just those features to a scratch file geodatabase.  I'd like to avoid the null geometry points as part of that selection process as well.  That's where I'm getting stuck.

I ran the check geometry tool on my file geodatabase feature class and it returns 2 records; that tool creates a table of problems, and I can identify the two records easily with a relate:

In this post, Joshua Bixby suggests a snippet of code to delete those records.  Rather than delete, I just tried to see I a search cursor can find them, but I get no returns:

import arcpy

arcpy.env.workspace = r'J:\LocatorTesting\Scratch.gdb'
fc = 'AddPntsProtected'

fields = ['SHAPE@']
with arcpy.da.SearchCursor(fc,fields)as cursor:
    for row in cursor:
        if row is None:
            print('Found it')‍‍‍‍‍‍‍‍‍‍

I altered line 6 to 'SHAPE@XY' without success; tried 'SHAPE@X'; tried 'SHAPE@Y'; all without success.  How can I isolate the two problem records from the original selection I make to the EGDB?

Eric Anderson

Edited to add:

This shows some promise as the 'SHAPE@XY' returns a tuple, so if I tease either X or Y out for None, I should be good to go:  

arcpy.env.workspace = r'J:\LocatorTesting\Scratch.gdb'
fc = 'AddPntsProtected'

fields = ['OBJECTID','SHAPE@XY']
with arcpy.da.SearchCursor(fc,fields)as cursor:
    for row in cursor:
        if row[1][1] == None:
            print(row[0])
454702
454703
That should just about do it....
Tags (1)
0 Kudos
1 Solution

Accepted Solutions
JoshuaBixby
MVP Esteemed Contributor

You missed a small, yet very important, comma when copying my code snippet from https://community.esri.com/thread/181543-nullempty-geometry-in-python?commentID=812139#comment  :

Line 08 should either be:

for row, in cursor:

or Line 09 should be:

if row[0] is None:

The reason your existing code snippet isn't finding the records is because [None] is None is False.

View solution in original post

2 Replies
JoshuaBixby
MVP Esteemed Contributor

You missed a small, yet very important, comma when copying my code snippet from https://community.esri.com/thread/181543-nullempty-geometry-in-python?commentID=812139#comment  :

Line 08 should either be:

for row, in cursor:

or Line 09 should be:

if row[0] is None:

The reason your existing code snippet isn't finding the records is because [None] is None is False.

JoeBorgione
MVP Emeritus

ha...  this one:  

shp,
That should just about do it....
0 Kudos