GetCount results

41 views
Skip to first unread message

GISChick

unread,
Nov 5, 2010, 2:13:20 PM11/5/10
to Python - ARCGIS geoprocessing
Hi I'm getting a strange return when I try and use GetCount to check
and see how many features have been selected from my select
statements.

Here's a sample of the code I'm using:

ClippingFC = r'Database Connections\Bamber.sde
\FOREST_13.TSO_13\FOREST_13.OPERATING_AREA'
clipArg = "'OPERATING_AREA like 'Moose Valley%''"
gp.MakeFeatureLayer_management(ClippingFC, ClippingLyr)
if clipArg:
gp.SelectLayerByAttribute_management(ClippingLyr,
"NEW_SELECTION",clipArg)
print 'number of records selected: ',
gp.GetCount_management(ClippingLyr)


Instead of returning the number of features selected I get the
following line returned:

<geoprocessing server result object object at 0x00A1A938>

I tried it on the FC and the FL prior to executing the Select
statement and it returns the same thing??
Any ideas?
My script continues and executes a copyfeatures of the selected
features but the resultant layer is empty.

Colin Dyck

unread,
Nov 5, 2010, 3:15:36 PM11/5/10
to geop...@googlegroups.com
try
 
gp.GetCount_management(ClippingLyr).getOutput(0)
 
getcount brings back an object, not int.  you need to access from the getOutput method.  It works for me as I ran into that same issue recently.
 
hope that helps,
 
Colin


 

--
You received this message because you are subscribed to the Google Groups "Python - ARCGIS geoprocessing" group.
To post to this group, send email to geop...@googlegroups.com.
To unsubscribe from this group, send email to geopython+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/geopython?hl=en.


Steinke, Candice FOR:EX

unread,
Nov 5, 2010, 4:16:38 PM11/5/10
to geop...@googlegroups.com

Thanks Colin,

That kind of works...it returns u’126’.  Not sure what the u means? 

 

I thought this was strange because I ran a different script this morning with a bunch of getcount statements in it and it worked perfectly......I just compared my two scripts and noticed that this one that isn’t working creates the geoprocessing object using the 9.3 option whereas the one that works just creates the object without specifiying the version.

So,

gp = arcgisscripting.create()   works

but

gp = arcgisscripting.create(9.3)   does not

 

Not sure why, but I guess I solved my own problem.

Thanks again.

 

 

Candice Steinke
GIS/Data Analyst
BC Timber Sales - Kamloops TSO
1265 Dalhousie Drive
Kamloops, BC V2C 5Z5
Phone: 250-371-4450
Fax: 250-371-6565

Fran Tarkington

unread,
Nov 5, 2010, 4:31:24 PM11/5/10
to geop...@googlegroups.com
The u in u'someString' means the the string is encoded in unicode.  Unicode gives computer languages support for more characters than plain old ascii does.  More info on unicode can be found at http://en.wikipedia.org/wiki/Unicode

For most geoprocessing scripts, you should be able to use unicode just like you would any other string.  If you run into issues / errors or troubles with unicode encoded string objects you can easily convert them to regular ascii strings using the str() function.

Example:
# declare a unicode string
var = r'SomeString'
# convert the unicode string to plain old ascii.
var = str(var)

Regarding your experience with getcount.  The problem you are encountering is unique to the 9.3 release.  Previous releases (<9.3) returned an integer, and from some quick testing with arcgis10 it looks like it also returns a integer.

Finally looking at the code below you are using to create a gp object. 

gp = arcgisscripting.create()

should create a geoprocessing object using a 9.2 or a 9.3 install.  If you use this syntax on 9.3 your geoprocessing object should behave more like a 9.2 geoprocessing object.  Whereas

gp = arcgisscripting.create(9.3)

Creates a 9.3 geoprocessing object.  The major difference between the two has to do with the various list___ functions (listfields, listworkspaces, etc...).  9.2 gp objects list functions will return enumeration objects, whereas 9.3 list__ functions will return python lists.

hope this makes sense

Cheers

Kevin
Reply all
Reply to author
Forward
0 new messages