|
POST
|
True - My forays into v10 arcpy land have not been very encouraging. ArcGIS v9.3.1 remains my geoprocessing workhorse...
... View more
03-29-2011
09:46 AM
|
0
|
0
|
1386
|
|
POST
|
Is it faster if you comment out the gp.snapraster line? Also, I notice you are setting the extent of the new raster to be the same as the snapRaster... Why not set the gp.extent = to that of the inputShapefile and then set gp.snapraster = snapRaster? By setting the gp.extent = the extent of snapRaster, you don't need to then set gp.snapraster = snapRaster. Could it be that the extent of the snapRaster is much more expansive than the extent of the inputShapefile (and therefore has to take a lot of time to produce a bunch of extra NODATA cells on the periphery)?
... View more
03-29-2011
08:23 AM
|
0
|
0
|
1386
|
|
POST
|
Would this script help? http://arcscripts.esri.com/details.asp?dbid=16700
... View more
03-28-2011
09:16 AM
|
0
|
0
|
1838
|
|
POST
|
I'm guessing this is related to your issue, but a while back I reported a bug to ESRI: When you set a snaperaster in a Python script, the SA tools all perform significantly slower (compared to if you don't set it). The ESRI fellow noted the slowdown, but didn't seem to understand why this was a big deal, and wanted to close the "incident" right away ( incident #807205 BTW)... Maybe they get incentive pay for "number of closed incidents"? Hmm... Anyway, in ancient times (pre v9.2), before the gp.snapraster function worked (at all), I wrote a function that adjusted a given gp.extent to the cell alignment of a given raster (see code below). Basically this is what gp.snapraster is doing behind the scenes... Upon finding the aforementioned bug in v9.3, I resurrected my code, and happily use it to this day. Probably more verbose than necessary, but it works great... Might require some small re-writes for v10. 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)
#Example of use.... adjuest the extent of oesfBufferFC so it aligns with gnnReadGrd
oesfBufferFC = fgdbPath + "\\oesf_buffer"
gnnReadGrd = r"\\dnrutoly05\d$\csny490\gnn_20100303\mr200_sppsz_2006\gnn_20100303"
gp.extent = oesfBufferFC
gp.extent = snapExtentToRaster(gp.extent, gnnReadGrd)
... View more
03-28-2011
08:44 AM
|
0
|
0
|
1386
|
|
POST
|
In the olden days you used to be able to run the SA tools (like zonal stats) in a loop for weeks with no memory leaks. Whatever ESRI did to some of the SA tools in v9.3 and v10 seemed to: 1. Increase the speed of execution (sometimes by a whole lot). We all appreciate that... 2. Cause many of these algorithms to run out of memory. Yar... One example is the Fill tool. In years past, the thing might take a week to finish, but it finished. Now the stupid things just bombs with an 'out of memory' error. Hmm...
... View more
03-23-2011
01:39 PM
|
0
|
0
|
3355
|
|
POST
|
The os.walk command is the way to loop through subfolders (and files) from a top level directory. Example #1 is how to deal with folders, and example #2 is how to deal with the files within the folders. Example #1: This code will attempt to compress any FGDB (a .gdb folder) under the rootDir import os, fnmatch, arcgisscripting
gp = arcgisscripting.create(9.3)
rootDir = r"C:\temp"
gdbList = []
for dirPath, dirNames, fileNames in os.walk(rootDir, topdown=False):
if fnmatch.fnmatch(dirPath, "*.gdb") == True:
gdbList.append(dirPath)
gdbCount = len(gdbList)
if gdbCount == 0:
print "No matching FGDBs found!"
else:
print "Attempting to compress " + str(gdbCount) + " geodatabases..."
for gdb in gdbList:
try:
gp.CompressFileGeodatabaseData_management(gdb)
print "Compressed " + gdb + "..."
except:
print "ERROR: Failed to compress " + gdb + "!" Example #2: This code will attempt to compress any PGDB (an .mdb file) under the rootDir import os, fnmatch, arcgisscripting
gp = arcgisscripting.create(9.3)
rootDir = r"C:\temp"
gdbList = []
for dirPath, dirNames, fileNames in os.walk(rootDir, topdown=False):
for file in fileNames:
if fnmatch.fnmatch(file, "*.mdb") == True:
gdbList.append(dirPath + "\\" + file)
gdbCount = len(gdbList)
if gdbCount == 0:
print "No matching PGDBs found!"
else:
print "Attempting to compact " + str(gdbCount) + " geodatabases..."
for gdb in gdbList:
try:
gp.Compact_management(gdb)
print "Compacted " + gdb + "..."
except:
print "ERROR: Failed to compact " + gdb + "!"
... View more
03-11-2011
08:41 AM
|
0
|
0
|
6493
|
|
POST
|
Try the MakeQueryTable tool in ArcToolbox. The 'Expression' parameter is where you would put all the SQL. I haven't tested it using any SQL spatial stuff though - just tabular stuff I use to make pseudo spatial views. Be sure to return the Shape field in the query, else you only get a table view back (and not a feature layer).
... View more
03-09-2011
12:50 PM
|
0
|
0
|
529
|
|
POST
|
Hmm... Another option (assuming this works), would be to temporarily rename the shapefile (use the Rename tool), use the describe, and then rename it back. Yet another option: There is a .prj file that accompanies the .shp (assuming there is a defined projection). Instead of using the describe method directly, maybe just have Python look for/read the .prj file. The prj string can then be loaded into a SR object using the "loadFromString" method.
... View more
03-09-2011
10:07 AM
|
0
|
0
|
1472
|
|
POST
|
Did you try making a feature layer from the unfortunately-named shapefile and then try the describe on that? For example: fc = r"C:\temp\test.badname.shp"
gp.MakeFeatureLayer(fc,"fl")
dscObj = gp.describe("fl")
srObj = dscObj.spatialreference
print srObj.name
... View more
03-09-2011
08:50 AM
|
0
|
0
|
1472
|
|
POST
|
Generally speaking: 1) Only name GIS datasets using letters, numbers, or an "_". 2) Always start the name (database names, rasters, featureclasses, field names too!, etc.) with a letter (not a number or an underscore). 3) Avoid spaces and special characters (such as a ".", "&", "#", etc.). 4) If you can help it, keep names <= 10 characters. There are many exceptions of course, but... I have followed these four basic rules for 12 years, and have never gone wrong. Sorry, but I think you will have to rename your shapefile to get this to work (maybe reformat to a FGDB, and the "." may be supported in that format?).
... View more
03-09-2011
08:42 AM
|
0
|
0
|
1472
|
|
POST
|
Perhaps have a dummy script that launches the tkinter script? The dummy script (the one directly launched from the toolbox will finish, but the tkinter one will continue (but be independent from the toolbox and act as a stand alone script without ArcToolbox functionality - i.e. won't add output layers to the TableOfContents, etc.). Is it just annoying to have the toolbox dialog, or something else? Seems that it really is "appropriate" that the toolbox dialog is there because the script is still actually running until something is clicked in the tkinter GUI, right?
... View more
03-08-2011
07:45 PM
|
0
|
0
|
1009
|
|
POST
|
Make sure the zone raster and/or the value raster has a raster attribute table. If not, use the BuildRasterAttrbibuteTable (or is it called CreateRasterAttributeTable? I forget). Generally, if the raster has more than 500 (I think) values, the raster attribute table is not automatically created.
... View more
03-08-2011
07:37 PM
|
0
|
0
|
3355
|
|
POST
|
The ProjectRaster tool is available via ArcToolbox in v10 (same name as it has been since v9.0 I think). When I open the tool, there is (still) a parameter for "geographic Transformation". It will be "unselectable" until you have defined an output coordinate system - assuming a transformation is applicable.
... View more
03-02-2011
01:17 PM
|
0
|
0
|
3367
|
|
POST
|
parcel labels as multiparts I don't understand why they have to be multipart... Is it becasue the parcels themselves are (sometimes) multipart polygons)? Why not just first break the parcels into singleparts (MultipartToSinglePart tool) and then get rid of any resulting labelpoints that share the same PARCEL_ID?
... View more
02-24-2011
01:57 PM
|
0
|
0
|
2445
|
|
POST
|
You can make rapid coordinate system conversions by using an appropriate spatial reference parameter in a cursor. For example, this code spits out the vertice coordinates of a township layer in WGS84 coordinates (not their native StatePlane coordinates). import arcgisscripting
gp = arcgisscripting.create(9.3)
fc = r"\\snarf\am\div_lm\ds\gis\tools\sde_connections_read\ropa_gis_layer_user.sde\CADASTRE.TOWNSHIP_SV"
spatialRef = r"C:\Program Files\ArcGIS\Coordinate Systems\Geographic Coordinate Systems\World\WGS 1984.prj"
dsc = gp.describe(fc)
shapeFieldName = dsc.shapeFieldName
oidFieldName = dsc.oidfieldname
searchRows = gp.searchcursor(fc, "", spatialRef)
searchRow = searchRows.next()
while searchRow:
oidFieldValue = searchRow.getvalue(oidFieldName)
print oidFieldName + " = " + str(oidFieldValue)
shapeFieldObj = searchRow.getvalue(shapeFieldName)
partCount = shapeFieldObj.partcount
partIndex = 0
while partIndex < partCount:
print "Part " + str(partIndex)+ ":"
partObj = shapeFieldObj.GetPart(partIndex)
pointObj = partObj.next()
pointCounter = 0
while pointObj:
print pointObj.x, pointObj.y
pointObj = partObj.next()
pointCounter += 1
# If pointObj is null, either the part is finished or there is an interior ring
if not pointObj:
pointObj = partObj.next()
if pointObj:
print "Interior Ring:"
partIndex += 1
searchRow = searchRows.next()
... View more
02-24-2011
07:56 AM
|
0
|
0
|
3285
|
| 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
|