POST
|
Clearly you do have 32-bit paths in your sys.path that do not belong there when you are running the 64-bit python. The question is where they are coming from. This sure looks like something you'd want to open a support incident to get to the bottom of the issue.
... View more
05-10-2013
08:49 PM
|
0
|
0
|
756
|
POST
|
I would expect your expression to look more like: "rastercalc" + "rastercalc2" + "rastercalc3" with the three names showing up in the Raster Calculator tool dialog box. I'm assuming the three names are raster datasets or raster layers that are elements in the model. I'll also mention that the above expression would probably be handled easier (and more efficiently, and with handy additional option on how NoData cells are handled) using the Cell Statistics tool instead of Raster Calculator.
... View more
05-10-2013
07:21 PM
|
0
|
0
|
458
|
POST
|
Here's my updated ListUnique script - works with 9x/10x. Thanks guys, this is a big improvement to what I had before. A cute tweak I learned that sorted(set()) returns a list.
def ListUnique(inTable,Field):
"""Create a list of unique values from a table/tableview.
arguments
inTable Table or table view
Field Field name
"""
Row, Rows = None, None
try:
try:
# this will only work for 10.1
import arcpy.da
lstValues = \
sorted({r[0] for r in
arcpy.da.SearchCursor(inTable, [Field])})
except:
import arcgisscripting
gp = arcgisscripting.create(9.3)
Rows = gp.SearchCursor(inTable,"","",Field,Field)
Row = Rows.next()
lstValues = []
while Row:
lstValues.append(Row.getValue(Field))
Row = Rows.next()
# unique-ize and sort the list
lstValues = sorted(set(lstValues))
return lstValues
except:
raise
finally:
if Row: del Row
if Rows: del Rows
... View more
05-01-2013
12:25 PM
|
0
|
0
|
868
|
POST
|
Hey Curt, I thought about doing a MakeFeatureLayer and then running a series of SelectLayerbyAttributes but from my experience, that significantly increases processing time. Not a big deal with small to moderate sized datasets, but with 3.2 million records, I didn't want to play with those implications. I agree - I fixed the code above so you're just selecting off the layer directly with the Select_analysis tool. If you added a field index you'd get the time back in spades when you ran the Select tool -- even faster! Someone commented on the post about leveraging the TableToNumPyArray function to get better performance Talk about gilding the lily. arcpy.da.SearchCursor is pretty darn fast. It's so fast, I wonder if Esri's team they used a numpy array to do it!
... View more
05-01-2013
12:11 PM
|
0
|
0
|
868
|
POST
|
I was able to pull up a list of the unique store IDs by using:
def Unique_Values(table, field):
with arcpy.da.SearchCursor(table, [field]) as cursor:
return sorted({row[0] for row in cursor})
fc = "C:\Users\username\Documents\ArcGIS\Default.gdb\MyCustomers"
field = "DID"
UniqueValues (fc, field)
which resulted in a list of all of my unique store IDs, 957 in all. Neat. I may steal that. What I'm not sure of however, is how to go about iterating through that list and using each value in the list in a where_clause in a "FeatureClassToFeatureClass_conversion" to export each unique dataset. Note, you could avoid scripting altogether and do this in ModelBuilder using Iterate Feature Selection. But, if you want to do this in Python, it's a matter of making a layer and selecting on it:
lyr = arcpy.CreateFeatureLayer(management(fc, "lyr")
stores = UniqueValues(lyr, field)
for store in stores:
where = "{0} = {1}".format(field, store)
outFC = "store{0}".format(store)
arcpy.Select_analysis(lyr, outFC, where)
UPDATE: Chris beat me to the post. Nice one-liner, Chris! Just a note about my more verbose approach: If a GP tool gets a layer input, it can assume that the input exists and its field list is already in memory ready to roll. This can make a difference if you need to do 957 select/copy operations.
... View more
05-01-2013
10:44 AM
|
0
|
0
|
868
|
POST
|
And it looks like I can use the 'Single Output Map Algebra' tool to place this in ModelBuilder. Yes, indeed. Map Algebra is quite useful! For the thread I should add that when you move up to 10.x SOMA and Raster Calculator (from the menu) are no longer available. Your 9.x model that uses SOMA will still run, you just will have to do it differently in new models. What's new in ArcGIS Spatial Analyst 10
... View more
04-29-2013
08:40 AM
|
0
|
0
|
1199
|
POST
|
Scott: Warning: your code has mixed indents, some tabs, some spaces. It's best to use one or the other, I like spaces. This can lead to unexpected results as your indents may not work exactly as intended. Most Python IDEs have a setting to convert automatically to spaces for you.
... View more
04-26-2013
09:08 AM
|
0
|
0
|
506
|
POST
|
If you used the Define Projection tool, or modified the coordinate system properties in a dialog box, that does not change the coordinates, it just changes the metadata that tells ArcGIS what projection the coordinates reference. So for those shapefiles that you altered, the coordinates are still in the original projection, but ArcGIS thinks they are in the new UTM zone so draws them in the wrong place. You need to project the datasets from 18N to 17N using the Project tool. Hope this helps. Update: Hi Mark - you responded a few seconds before I did!
... View more
04-26-2013
08:57 AM
|
0
|
0
|
2533
|
POST
|
Here's a better description of using pth files from the gis.stackexchange.com site, posted by my colleague Rich Signell. If you don't want to tweak your environment for your python session, this is an easier approach than a .bat file. Note path files are read in alpha order, so if you name your custom pth file starting with "zz" it will be loaded last -- which may avoid conflicts. [/hr] The Enthought Python Distributions, including Canopy, are stand-alone and don't need anything in the registry or in the environment variables. So they can play nice with other Python distributions like the one that comes with ArcGIS 10.1. To access ArcGIS 10.1 python modules from Enthought Canopy: Create a "path" file in the Canopy user directory that points to the ArcGIS 10.1 python modules. On my system, I created a text file called arcpy.pth with these 4 lines:
# .pth file for arcpy
C:\ArcGIS\Desktop10.1\bin
C:\ArcGIS\Desktop10.1\arcpy
C:\ArcGIS\Desktop10.1\ArcToolbox\Scripts
and put arcpy.pth in the Canopy User site-packages directory: C:\Users\rsignell\AppData\Local\Enthought\Canopy32\User\lib\site-packages To access Enthought Canopy modules from ArcGIS 10.1: Create a "path" file in the Arc site-packages folder that points to the Canopy python modules. On my system, I created a text file called epd.pth with these 3 lines:
# .pth file for EPD Canopy
C:\Users\rsignell\AppData\Local\Enthought\Canopy32\User\Lib\site-packages
C:\Users\rsignell\AppData\Local\Enthought\Canopy32\System\Lib\site-packages
and then put epd.pth in the Arc site-package folder: C:\Python27\ArcGIS10.1\Lib\site-packages This works because Enthought Canopy and ArcGIS10.1 are at the same version of Python (2.7) and Numpy (1.6). I hope we can continue to have this compatibility!
... View more
04-25-2013
11:01 AM
|
0
|
0
|
1015
|
POST
|
I'm reclassifying the original raster file three times to produce three different new raster files. Original raster attribute table: Rowid; Value; Count 0; 1; 609624542 1; 2; 854540105 2; 3; 167276779 I used the Value field to reclass it once to 1, 0, 0, and NoData to 0. Did a second reclass to 0, 1, 0, and NoData to 0 and then a third reclass to 0, 0, 1, and NoData to 0. Mel, I think the Raster Calculator tool would be a more straight-forward approach as you can use the IsNull and Con tools together like this: Con(IsNull("inraster"), 0, Con("inraster" == 1, 1, 0)) Con(IsNull("inraster"), 0, Con("inraster" == 2, 1, 0)) Con(IsNull("inraster"), 0, Con("inraster" == 3, 1, 0))
... View more
04-25-2013
09:57 AM
|
0
|
0
|
1199
|
POST
|
When running the model using the custom toolbar, the layer is removed from the TOC, and also should be added to display-because it's checked on. But, when i right click the model, go to edit, and then run within the mxd the layer is not removed, and the most current buffer is added to display. Jake - you need to set it up as an output parameter. From the help: Note: Add To Display has no effect outside ModelBuilder. When running a model tool from its dialog box or the Python window, the Add To Display setting will not be honored. To add model data variables to the display when running the model from its dialog box or the Python window, make the data variable a model parameter, then enable the Add results of geoprocessing operations to the display option from the Standard toolbar: Geoprocessing > Geoprocessing Options > Add results of geoprocessing operations to the display Desktop 10.1 Help: Displaying model data
... View more
04-25-2013
09:30 AM
|
0
|
0
|
223
|
POST
|
newList is a list of field names, there should be 72 items in it Apparently not, if you're getting that error. I suggest using a try-except block to find which line is causing the problem (see my code for an example).
... View more
04-25-2013
09:16 AM
|
0
|
0
|
395
|
POST
|
What is your ArcGIS version and SP? (See Help > About ArcMap) If not on the most recent, do update!
... View more
04-24-2013
10:27 AM
|
0
|
0
|
1232
|
POST
|
I keep getting a �??list index out of range�?� error message when doing this. How many fields are there in the line? If you only have 10, lineList[36] will raise an out of range error. Here's another shot at this:
# skip 5 rows
skipRows = 5
for n in range(skipRows + 1):
line = inFile.readline()
row = skipRows + 1
# read and clean up data
while line:
print 'Row', row, 'line info=', line[:72]
# clean line and split into list
lineList = [f.strip().replace("/","_") for f in line.split(',')]
print 'line info =', lineList
latidx,lonidx = 36, 37 # lat and long are in field 36 and 37
if len(lineList) > lonidx:
raise Exception, "line {0} too short".format(row)
for k in latidx, lonidx:
if lineList == "":
lineList = 0
outFile.write(','.join(newList) + "\n")
line = inFile.readline()
row += 1
... View more
04-24-2013
08:03 AM
|
0
|
0
|
395
|
POST
|
If you construct a an intermediate filename using a built-in variables, the system won't modify them when the model is validated. (Note, %scratchfolder% is 10.1 only, %scratchworkspace% would be used in earlier versions). For example: %scratchfolder%\clip_%n%.tif will be interpreted at runtime as D:\work\scratch\clip_0.tif D:\work\scratch\clip_1.tif ... Depending on the iteration, the built-in iteration variable used could be either %n% or %i%. Hope this helps!
... View more
04-24-2013
07:31 AM
|
0
|
0
|
1232
|
Title | Kudos | Posted |
---|---|---|
1 | 04-24-2020 02:51 PM | |
1 | 09-03-2021 02:26 PM | |
1 | 10-23-2023 09:44 AM | |
1 | 10-23-2023 09:54 AM | |
1 | 10-18-2012 10:16 AM |
Online Status |
Offline
|
Date Last Visited |
a week ago
|