POST
|
Chris, Thanks for the tips. Re: suggestion 1, I don't think I can use SelectLayerByAttribute because I have a standalone table. Re: suggestion 2, I thought this might be the winner, since I do have a series of searches to run over the same table. However, the overhead in creating the 2.3mil key:value pairs was REALLY expensive. I let my script run for about 6-7 minutes, and the dictionary hadn't yet been created...let alone complete any searches. I thought I might be able to leverage some functionality from numpy, since all my values are numeric. Turns out there is a pretty cool way to load an array (my_array = numpy.fromiter) but that, too, was quite expensive. For comparison sake, I used a smaller table with ~160K records. For each of the trials, I started a fresh ArcMap session. I'm not sure if the individual methods are coded the best, but here's the times and code to run 10 searches over the same table: by cursor:14.17s by making table and counting: 28.4s by dictionary: 98.5s from arcpy import *
from stopwatch import clockit
from numpy import *
@clockit
def do_search_by_count(table):
count = 0
for i in range(100,1000,100):
searchstring = "NEAR_DIST < " + str(i)
count += make_table_and_count(table, searchstring)
print "done by count: " + str(count)
return count
@clockit
def do_search_by_cursor(table):
count = 0
for i in range(100,1000,100):
searchstring = "NEAR_DIST < " + str(i)
count += cursor_search_count(table,searchstring)
print "done by cursor: " + str(count)
return count
@clockit
def do_search_by_dict(table):
lookupDict = create_dict(table)
count = 0
for i in range(100,1000,100):
count += count_dict(lookupDict,i)
print "done with dict: " + str(count)
return count
@clockit
def make_table_and_count(table,searchstring):
arcpy.MakeTableView_management(table,"mytv5k",searchstring)
x = int(str(arcpy.GetCount_management("mytv5k")))
return x
@clockit
def cursor_search_count(table,searchstring):
rows = arcpy.SearchCursor(table,searchstring)
count = 0
for row in rows:
count += 1
return count
@clockit
def create_dict(table):
lookupDict = {}
searchRows = arcpy.SearchCursor(table)
for myrow in searchRows:
lookupDict[myrow.OBJECTID] = [myrow.NEAR_DIST]
del myrow
del searchRows
print "created dict"
return lookupDict
@clockit
def count_dict(lookupDict,dist):
count =0
for k,v in lookupDict.iteritems():
if v[0] < dist:
count += 1
return count
Thanks again for the tips. Mike
... View more
09-10-2010
06:39 AM
|
0
|
0
|
671
|
POST
|
hi, I've made an ArcGIS service from a WMS service by loading it as an .mxd, and publishing that .mxd. If I run an identify task following the method in the samples on the ArcGIS service all I get back is a very long url string, rather than the normal identify results Has anyone tried using an identify task this way? I'm thinking about parsing the url for info, but I thought I'd see if anyone has run up against this before.
... View more
09-09-2010
07:30 AM
|
0
|
6
|
3026
|
POST
|
Sorry for the late response - my email filter sent the reply notices to my spam folder. Go figure. There are a substantial amount of records for some tables....3-4 million in a few cases. A test with a 2,130,000 records took 19.07 seconds using the following code: from arcpy import *
from stopwatch import clockit
@clockit
def maketv_count(table):
arcpy.MakeTableView_management(table,"mytv5k","NEAR_DIST < 1000")
arcpy.GetCount_management("mytv5k") using a search cursor and iterating through took 19.43 seconds using this code: def maketv_cursor(table):
rows = arcpy.SearchCursor(table,"NEAR_DIST < 1000")
count = 0
for row in rows:
count += 1 Granted, 2 million records is a LOT...but I didn't expect the methods to be nearly identical in their speed. Thanks mike
... View more
09-08-2010
09:56 AM
|
0
|
0
|
1988
|
POST
|
That method does work, but it isn't any faster (at least with my tables) than using a search cursor and iterating through it.
... View more
09-03-2010
10:48 AM
|
0
|
0
|
1988
|
POST
|
Thanks! I tried making a table view and then running GetCount on that, and it didn't seem any faster than what I was doing before. And unfortunately, I can't run GetCount on the SearchCursor object. thanks, mike
... View more
09-03-2010
07:59 AM
|
0
|
0
|
1988
|
POST
|
Hi, I'm using the arcpy.SearchCursor code to query a standalone table. All I really need is the count of the results - not any of the actual data. The searchcursor itself finishes rather quickly, but iterating through the search cursor takes a surprisingly long time. Here's the method I'm using. Is there a faster way to get what I need? rows = arcpy.SearchCursor(table,searchstring)
#count the number of rows in output
count = 0
for row in rows:
count += 1
... View more
09-03-2010
05:24 AM
|
0
|
19
|
17248
|
POST
|
During the scipy install the setup procedure automatically found the python install in the C:\python26\ArcGIS10.0 folder, and chose it as the default install directory. Wish I knew enough about how python is integrated with ArcGIS to figure this out... thanks, mike
... View more
08-18-2010
04:21 AM
|
0
|
0
|
411
|
POST
|
To test that, I'd probably need to reinstall python, huh... Has anyone been able to successfully install it and run a function, or is it just me? Doesn't look like ArcGIS gives you the option of specifying a different folder for python to install.
... View more
08-17-2010
10:21 AM
|
0
|
0
|
411
|
POST
|
yep - I used this one http://sourceforge.net/projects/scipy/files/scipy/0.8.0/scipy-0.8.0-win32-superpack-python2.6.exe/download Are there other dependencies that I don't know about? thanks! mike
... View more
08-17-2010
09:37 AM
|
0
|
0
|
411
|
POST
|
hi, Has anyone tried installing the SciPy python module in ArcGIS 10 and had success? I downloaded the appropriate package from sourceforge (http://sourceforge.net/projects/scipy/files/), and ran the installer. I get no error in the python command line when I 'import scipy', but my python shell will crash if I try an operation (scipy.misc.factorial(4) for example).
... View more
08-17-2010
06:11 AM
|
0
|
7
|
3663
|
POST
|
Charles' solution works for me - at least for this particular problem. I'm moving from VBA/.NET ArcObjects into python, so it'll take me a while to be "pythonic". Thanks guys, mike
... View more
08-12-2010
04:38 AM
|
0
|
0
|
573
|
POST
|
and what is the syntax for calling a .py script ? I can't just type the name of the python file into the command line.
... View more
08-11-2010
12:17 PM
|
0
|
0
|
1330
|
POST
|
Thanks Chris, Those workarounds do just fine - but it seems silly to have to do those. Isn't passing arguments a very, very basic functionality?
... View more
08-11-2010
09:10 AM
|
0
|
0
|
1330
|
POST
|
Hi, This seems absurdly simple to ask, but I cannot seem to find the answer, and I've scoured the help files. I have a script (let's say it's called myscript.py) and requires 2 arguments. How the heck do I execute that script from within the python window in ArcGIS 10? execfile() seems close, but I can't figure out how to pass the arguments. Thanks, mike
... View more
08-11-2010
07:55 AM
|
0
|
16
|
19239
|
POST
|
Ah - I see. Thanks for filling me in. I found a workaround (if anyone is interested). First I changed my XML. Where there were 4 properties(Xmin, Ymin,Xmax,Ymax) for each entry before, there is a single comma-delimited string now. I can bind that to the button.tag in the data template and parse that string in code behind on the button's click event handler. Then I create a new envelope, and pass the parsed string parts to the bounding box coordinates of the new envelope. Finally, I call Map.ZoomTo(mynewenv) and it works. Thanks, mike
... View more
07-30-2010
05:31 AM
|
0
|
0
|
156
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|