I have a number of point feature classes that are the result of geocoding various types of permits. I have 5 different permit feature classes, and since many of them were issued to same address, they are 'stacked' when viewed on a map. I wrote a simple script that adds and subtracts 5 map units from the SHAPE@X value or the SHAPE@Y value. That works great when all the records in a feature class have values, but since this feature class is the result of geocoding, those records that did not match have <null> values for their coordinates.
As a result, as I UpdateCursor through the feature class records, and try to perform an additive or subtractive operation the script errors out with something to the effect of 'Sorry Joe, I can't add or subtract from None'
Below is an example of the where clause in a SearchCursor:
fields = ['SHAPE@X','SHAPE@Y']
select = 'SHAPE@X is not None'
for fc in arcpy.ListFeatureClasses():
with arcpy.da.SearchCursor(fc,fields,select)as cursor:
for row in cursor:
if fc == 'APLIC':
print(row[0])
Traceback (most recent call last):
File "<ipython-input-16-18ea27620933>", line 3, in <module>
for row in cursor:
RuntimeError: An invalid SQL statement was used. [SELECT OBJECTID,Shape FROM APLIC WHERE SHAPE@X is not None]
I guess I could wrap my cursor in a try/except block block but I'd rather just process those records that have valid values in SHAPE@X and SHAPE@Y . Is there a way to select for just those records that meet my criteria?
Solved! Go to Solution.
None is not a valid keyword in SQL; try null instead. Also, I'm not sure if you can use the geometry property "token" fields in the where clause. You might have to use shape instead.
select = 'SHAPE is not null'
@BlakeTerhune looks like you retracted your post as I was replying to it.
select = 'SHAPE@X is not null'
for fc in arcpy.ListFeatureClasses():
with arcpy.da.SearchCursor(fc,fields,select)as cursor:
for row in cursor:
if fc == 'APLIC':
print(row[0])
finish = time.strftime('%H:%M:%S')
Traceback (most recent call last):
File "<ipython-input-20-4b6a74596c64>", line 3, in <module>
for row in cursor:
RuntimeError: An expected Field was not found or could not be retrieved properly. [APLIC]
is not Null is what I initially tried, but it errors as well.
Looks like that error is referring to a field you have listed as APLIC that maybe doesn't exist in one of the feature classes.
None is not a valid keyword in SQL; try null instead. Also, I'm not sure if you can use the geometry property "token" fields in the where clause. You might have to use shape instead.
select = 'SHAPE is not null'
Yep, that did it!