|
POST
|
I almost exclusivly write and run my Python code from the PythonWin IDE. There are many Python code editors out there, but PythonWin is simple and does everything I need, so that's why I use it. PythonWin comes with the ArcGIS install CD (you have to manually install it!), but you can also download it free from here: http://sourceforge.net/projects/pywin32/files/pywin32/Build216/ Important: Download "pywin32-216.win32-py2.6.exe" as that is Python version (v2.6) that ArcGIS v10.0 uses. DO NOT try and get fancy and upgrade to a different version - it will not work.
... View more
11-03-2011
01:59 PM
|
0
|
0
|
1119
|
|
POST
|
Two things I have been doing since v9.1 to make Python-based parallel overlay processes run (not sure if I "need" to do them in v9.3.1 and/or v10.0 still, but it doesn't seem to hurt). 1) Write each result to seperate FGDBs (in your case, named results_1, results_2, etc). Another option that might work is to write the output to the in_memory workspace, and have a try/except statement that attempts to copy the FC to a single FGDB, if it fails, wait 5 sec and try again - maybe try up to 10 times or so... Something like:
tryCount = 0
successFlag = False
while tryCount <= 10:
try:
gp.CopyFeatures_managment(blah, blah)
successFlag = True
break
except:
time.sleep(5)
tryCount = tryCount + 1
if successFlag == False:
print "Failed!";sys.exit()
2) In the child processes, reset the TEMP and TMP system variables to unique directories. For example: import time, os, shutil
newTempDir = r"C:\temp\gptmpenvr_" + time.strftime('%Y%m%d%H%M%S')
os.mkdir(newTempDir)
os.environ["TEMP"] = newTempDir
os.environ["TMP"] = newTempDir This rediverts the overlaytiles.txt file to seperate folders so each process isn't trying to write to the same file.
... View more
10-28-2011
09:55 AM
|
0
|
0
|
1572
|
|
POST
|
While there is probably some performance increase having the address list stored in_memory, the real perfomance gain would be any enhancements that could be made to your geocoding service... Have you set it up correctly and in the most efficient way possible? Have you ever seen this? http://code.google.com/p/geopy It's pretty dang cool...
... View more
10-27-2011
12:50 PM
|
0
|
0
|
2378
|
|
POST
|
Sounds like a socialist conspiracy to undermine American capitalism... :cool:
... View more
10-25-2011
03:40 PM
|
0
|
0
|
2250
|
|
POST
|
Densify is now also available "out of the box" at v10 (ArcEditor and above license levels). Use the FeatureToVerticiesPoint tool to sort out what vertices belong to the original layer and which ones were created through the densifying process. A text field consisting of concatenated X and Y coordinates makes a convenient "key field" for doing the comparison.
... View more
10-25-2011
01:37 PM
|
0
|
0
|
2250
|
|
POST
|
Woops - Thanks Logan... Yes, I meant shapeFieldName, not oidFieldName (although oidFieldName is quite usefull sometimes as well). I didn't have my coffe yet...
... View more
10-25-2011
09:41 AM
|
0
|
0
|
1643
|
|
POST
|
The 'shape' field isn't always called shape... dsc = gp.describe(infc) #or your featurelayer rows = gp.SearchCursor(infc) #or your featurelayer row = rows.Next() feat=row.getvalue(dsc.oidFieldName)
... View more
10-25-2011
08:15 AM
|
0
|
0
|
1643
|
|
POST
|
Funny that: >>> import datetime
>>> datetime.datetime.now()
datetime.datetime(2011, 10, 12, 21, 8, 37, 327000) Easy breeze... Thank you for the reminder about datetime Kim!
... View more
10-12-2011
08:12 PM
|
0
|
0
|
2061
|
|
POST
|
Don't know much about "formal" methods of converting date/time formats in Python, but I think there are some built in converters: http://docs.python.org/library/time.html. I for one absolutely HATE all the different date/time formats that all the different databases use (Oracle vs. FGDB vs. DBF vs SQL vs...)! So one thing I always use (because it's simple) is to convert my disparate date/time fields to a simple long integer (or text) format of YYYYMMDDHHMMSS. So 20111012141239 would be 2:12:39PM on Oct 12, 2011. When reading from left to right, it is then very easy to then parse date/times.... Once everything is in a consistent format, then life is easy.
... View more
10-12-2011
01:42 PM
|
0
|
0
|
2061
|
|
POST
|
but does it work for overlapping polygons? There's only one way to find out... Using the Spatial Join tool, you will need to specify a Join operation of "ONE_TO_MANY" to deal with the overlapping polys. In addition to the afore mentioned Identity tool, the Intersect tool will also work. Both the Identity and Intersect correctly handle the one-to-many point/poly relationship by default. Don't reinvent the wheel... There are (at least three) out of the box tools that are designed to do exactly what you want!
... View more
10-11-2011
08:57 AM
|
0
|
0
|
1345
|
|
POST
|
Sounds like: http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//009z00000053000000.htm There are a few steps 😉 involved before you can run the Flow Length tool, and if you are new to the ESRI hydrology toolset, take a look here 1st: http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/An_overview_of_the_Hydrology_tools/009z0000004w000000/
... View more
10-07-2011
10:43 AM
|
0
|
4
|
5077
|
|
POST
|
Yes, that would indeed be a slow boat to China... A faster method: Use the SpatialJoin or Identity tool to assign the polygons OBJECTID onto the points. Then use the Frequency tool to count the occurances (points per polygon OBJECTID). Then use a simple tabular join and field calc to put the count (aka "FREQUENCY") values into a new field in the polygon FC.
... View more
10-06-2011
03:20 PM
|
0
|
0
|
1345
|
|
POST
|
Oh, one other thing I found was that in v9.3, using the gp.snapraster environment slowed down many of the Spatial Analyst functions (some by more than just a few seconds). So in my case 2 sec x 50,000 = 28 hours. My solution was to write my own "snapraster" function that would alter the gp.extent setting. Using my function (as opposed to gp.snapraster) I experienced no gp.snapraster-related slowdown... def snapExtentToRaster(inputExtent, snapRaster):
"Returns a xMin, yMin, xMax, yMax extent snapped to the cell allignment of a raster"
xMinInput = float(inputExtent.split(" ")[0])
yMinInput = float(inputExtent.split(" ")[1])
xMaxInput = float(inputExtent.split(" ")[2])
yMaxInput = float(inputExtent.split(" ")[3])
dscSnapRaster = gp.describe(snapRaster)
cellSize = float(dscSnapRaster.meancellheight)
xMinSnap = float(dscSnapRaster.extent.xmin)
yMinSnap = float(dscSnapRaster.extent.ymin)
xMaxSnap = float(dscSnapRaster.extent.xmax)
yMaxSnap = float(dscSnapRaster.extent.ymax)
#Calculates a modified xMinInput
if xMinSnap < xMinInput:
if divmod(abs(xMinInput - xMinSnap), cellSize)[1] / cellSize < .5:
xMinOutput = xMinSnap + divmod(abs(xMinInput - xMinSnap), cellSize)[0] * cellSize
else:
xMinOutput = xMinSnap + cellSize + divmod(abs(xMinInput - xMinSnap), cellSize)[0] * cellSize
else:
if divmod(abs(xMinInput - xMinSnap), cellSize)[1] / cellSize < .5:
xMinOutput = xMinSnap - divmod(abs(xMinInput - xMinSnap), cellSize)[0] * cellSize
else:
xMinOutput = xMinSnap - cellSize - divmod(abs(xMinInput - xMinSnap), cellSize)[0] * cellSize
#Calculates a modified yMinInput
if yMinSnap < yMinInput:
if divmod(abs(yMinInput - yMinSnap), cellSize)[1] / cellSize < .5:
yMinOutput = yMinSnap + divmod(abs(yMinInput - yMinSnap), cellSize)[0] * cellSize
else:
yMinOutput = yMinSnap + cellSize + divmod(abs(yMinInput - yMinSnap), cellSize)[0] * cellSize
else:
if divmod(abs(yMinInput - yMinSnap), cellSize)[1] / cellSize < .5:
yMinOutput = yMinSnap - divmod(abs(yMinInput - yMinSnap), cellSize)[0] * cellSize
else:
yMinOutput = yMinSnap - cellSize - divmod(abs(yMinInput - yMinSnap), cellSize)[0] * cellSize
#Calculates a modified xMaxInput
if xMaxSnap < xMaxInput:
if divmod(abs(xMaxInput - xMaxSnap), cellSize)[1] / cellSize < .5:
xMaxOutput = xMaxSnap + divmod(abs(xMaxInput - xMaxSnap), cellSize)[0] * cellSize
else:
xMaxOutput = xMaxSnap + cellSize + divmod(abs(xMaxInput - xMaxSnap), cellSize)[0] * cellSize
else:
if divmod(abs(xMaxInput - xMaxSnap), cellSize)[1] / cellSize < .5:
xMaxOutput = xMaxSnap - divmod(abs(xMaxInput - xMaxSnap), cellSize)[0] * cellSize
else:
xMaxOutput = xMaxSnap - cellSize - divmod(abs(xMaxInput - xMaxSnap), cellSize)[0] * cellSize
#Calculates a modified yMaxInput
if yMaxSnap < yMaxInput:
if divmod(abs(yMaxInput - yMaxSnap), cellSize)[1] / cellSize < .5:
yMaxOutput = yMaxSnap + divmod(abs(yMaxInput - yMaxSnap), cellSize)[0] * cellSize
else:
yMaxOutput = yMaxSnap + cellSize + divmod(abs(yMaxInput - yMaxSnap), cellSize)[0] * cellSize
else:
if divmod(abs(yMaxInput - yMaxSnap), cellSize)[1] / cellSize < .5:
yMaxOutput = yMaxSnap - divmod(abs(yMaxInput - yMaxSnap), cellSize)[0] * cellSize
else:
yMaxOutput = yMaxSnap - cellSize - divmod(abs(yMaxInput - yMaxSnap), cellSize)[0] * cellSize
#Returns the entire modified extent
return str(xMinOutput) + " " + str(yMinOutput) + " " + str(xMaxOutput) + " " + str(yMaxOutput)
#Set the gp.extent to that of the nestIdsBufferFC = nestId and use snapExtentToRaster() function to set the snapraster instead of gp.snapraster (which slows things down)
gp.extent = ""
tempExtentML = "in_memory\\temp_extent"
gp.Select_analysis(nestIdsBufferFC, tempExtentML, "NEST_ID = " + str(nestId))
gp.extent = tempExtentML
gp.extent = snapExtentToRaster(gp.extent, habGrd)
... View more
10-06-2011
10:14 AM
|
0
|
0
|
1758
|
|
POST
|
I am in your same boat. I wrote a large Python-based process that runs a fancy monte carlo / bootstrap habitat simulation. It builds about 50,000 individual cost distance grids (actually cost path grids, but same difference), and takes a really long time to run. Some things I found, used, plan to use, and want to use in a future v10 rewrite: The "max distance" parameter in the CostDistance tool doesn't work. I added an extra step to buffer the point, and then set the gp.extent to the buffer extent, so as to limit the size of the cost distance surface. That way I wasn't building the cost distance grid values for areas I didn't need it. GRID format (instead of FGDB) might be faster (even in v10). I wrote my script for v9.3, and at that time GRID format was faster. That probably might have changed in v10.0, but I haven't tested it. In v10.0 it appears you can now run concurrent spatial analyst processes (for example, run 4 CostDistance tools in seperate python.exe instances at the same time) using os.spawnv, subprocess, multiprocessing, etc modules. In v9.3 you could only run one spatial analsyt process at once. This would be an immense performace boost, but I haven't rewritten my script in arcpy yet to take advantage of this improvment (I plan to though in a few months). I didn't to it for CostPath function, but using a Python in-memory structure like a dictionary or numpy array you can write your own custom CostPath (or whatever) function. I have done a bit of backwards engineering of ESRI functions, but at a great investment in time (this is why my agency pays ESRI $300k+ a year, right???). I sure do wish ESRI would provide an "out of the box" in-memory grid structure (make raster data compatible with their in_memory workspace), so that we wouldn't have to write our own functions... Or at least maybe they can publish some of their spatial analyst source code (yeah right!). That said, there are probably some ways to speed up the script. One thing that would be easy - just use a larger cell size. The cursor probably isn't the realy culprit... I assume you are using it to extract out the individual point features, correct? Per non-ESRI cost distance functions, I am sure there are many. For example: http://grass.fbk.eu/gdp/html_grass64/r.cost.html. Just waiting for someone to write it in pure Python.... If you do, POST IT!!!
... View more
10-06-2011
09:04 AM
|
0
|
0
|
1758
|
|
POST
|
Try renaming your layer to some simple name that doesn't have a & or \ symbol in it (like "mylayer"), and then try running the code like updateLayer = arcpy.mapping.ListLayers(mxd, "mylayer", df)[0] Does that work? If so, my guess is that arcpy doesn't like the \ or & symbol in your layer name...
... View more
10-05-2011
03:34 PM
|
0
|
0
|
2385
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 03-25-2014 12:57 PM | |
| 1 | 08-29-2024 08:23 AM | |
| 1 | 08-29-2024 08:21 AM | |
| 1 | 02-13-2012 09:06 AM | |
| 2 | 10-05-2010 07:50 PM |
| Online Status |
Offline
|
| Date Last Visited |
08-30-2024
12:25 AM
|