Select to view content in your preferred language

Problem using .sde featureclass in the GetCount tool

669
2
03-20-2013 12:26 PM
AultonSmith1
New Contributor
My app needs to test the user-selected feature class for a selected set before it continues. The only method I have found in the forum to accomplish this is to use the GetCount function on the map layer and on the source feature class and compare them. So far, so good, this works fine on shapefiles. But I need for it to work on .sde feature classes, too. The documentation and posts in the forum suggest using the arcpy.mapping.layer.DataSource function to get the connection to the .sde feature class. This is not working for me. Any help?

This is the path which is returned by the DataSource function:
>>> lyr = arcpy.mapping.Layer(r"New Group Layer\Property Line")
>>> str = lyr.dataSource
>>> print str
C:\Documents and Settings\acsmith\Application Data\ESRI\ArcCatalog\gisviewer@sde.pepopcogis2.sde\SDE.SDE.cadastre_real_estate\SDE.SDE.parcel_area
(gisviewer is the connection name, pepopcogis2 is the server, SDE.SDE.cadastre_real_estate is the dataset, and SDE.SDE.parcel_area is the feature class)

This is the error which is returned by the failed GetCount function:
>>> count1 = arcpy.GetCount_management(arcpy.mapping.Layer(r"New Group Layer\Property Line").dataSource)
Runtime error Traceback (most recent call last): File "<string>", line 1, in <module> File "c:\program files\arcgis\desktop10.1\arcpy\arcpy\management.py", line 13637, in GetCount raise e ExecuteError: ERROR 000732: Input Rows: Dataset C:\Documents and Settings\acsmith\Application Data\ESRI\ArcCatalog\gisviewer@sde.pepopcogis2.sde\SDE.SDE.cadastre_real_estate\SDE.SDE.parcel_area does not exist or is not supported
Tags (2)
0 Kudos
2 Replies
MathewCoyle
Honored Contributor
Can you access it directly without using a layer? Try these two.

fc = r'C:\Documents and Settings\acsmith\Application Data\ESRI\ArcCatalog\gisviewer@sde.pepopcogis2.sde\SDE.SDE.cadastre_real_estate\SDE.SDE.parcel_area'

print(arcpy.Exists(fc))

print(int(arcpy.GetCount_management(fc).getOutput(0)))


Also you may want to investigate FIDSet.
http://resources.arcgis.com/en/help/main/10.1/index.html#/Layer_properties/018v00000063000000/
0 Kudos
AultonSmith1
New Contributor
Thanks for the suggestion, MZ. Unfortunately, that didn't work either. On the bright side, with some help from my database administrator, I found out the path which does work. It turns out to be: 'Database Connections\Connection to gisviewer.sde\SDE.SDE.cadastre_real_estate\SDE.SDE.parcels_area'. All I have to do now is to extract the 'gisviewer' string (or whichever connection was used) from the string DataSource provides.
0 Kudos