|
POST
|
The Same as Layer choice does not work dynamically, just like Same as Display -- ie the extent from the source is applied right then and then the source is "forgotten." The extent environment is either four coordinates or a rule (Union, Intersection of inputs) and does not reference a dataset or layer after it is set. In contrast, the Snap Raster setting is applied to the extent when a tool runs -- it does point to a dataset and work dynamically. The only way you can make it work "at runtime" dynamically is to set it up that way inside ModelBuilder by linking a dataset to a tool, specifying Environment>Extent when you do so.
... View more
10-04-2012
02:10 PM
|
0
|
0
|
1552
|
|
POST
|
Your AttributeError is from the case sensitive name being wrong. So, start by spelling setValue correctly. >> type(row.setValue) <type 'instancemethod'> >>> type(row.SetValue) Traceback (most recent call last): File "E:\Program Files (x86)\Wing IDE 3.2\src\debug\tserver\_sandbox.py", line 1, in <module> # Used internally for debug sandbox under external interpreter File "D:\ArcGIS\Desktop10.1\arcpy\arcpy\arcobjects\_base.py", line 28, in __getattr__ raise AttributeError("%s" % attr) AttributeError: SetValue >>> (It wasn't in arcgisscripting, but it is in arcpy, which is fully Pythonized.) If you're operating on a raster attribute table, it's best to MakeTableView and than open the table view instead of trying to open the raster as a table. Dictionaries are totally the way to go with simple lookups like this: Lookups =[1,2,3,4] ClassList=["Tree_Canopy", "Impervious", "Vegetation", "Soil", "Water"] lookup = dict(zip(Lookups,ClassList)) ... for row in rows: v = lookup[row.getValue("Value")] row.setValue("Class", v) row.setValue("Ref", v) rows.updateRow(row) Also, note the syntax of getValue and setValue - the first argument is a field name string ("Value"), not a field value (row.Value). Hope this helps.
... View more
10-04-2012
01:29 PM
|
0
|
0
|
1741
|
|
POST
|
(1) In your "Test.csv", you have 3 columns: rec, X, Y. In my sc12points.csv, I have 5 Columns: ID, Lot_ID, X_coord, Y_coord, Z_coord). How can I read these 5 columns in the "try:" section of the Python Script of my sc12points.txt (this will be changed to .py)? My real problem is: how can I write the ArcPy-Python code statements to read the ID and Lot_ID in the "try:" section? As long as they are the file, they will come in as columns in the table. You don't need to specify them in the Python code, just in the input file. (2) How can I specify the World 84 coordinates system in the spRef? Specify the appropriate path for spRef. I think what you want is: spRef = r"Coordinate Systems\Geographic Coordinate Systems\World\WGS 1984" (3) I used my Excel 2007 to create my 12points.csv file. I just typed in the names of 5 columns in the first row and then typed in (i) 1, 2, 3, ...., 12 in ID, (ii) Lot_ID, copied the values of X_coord and Y_coord from my old text file to my new csv file, and (iii) leave all the indendations to the right. Do I have to change (i) the types of ID and Lot_ID to integer, (ii) the types of X_coord, Y_coord and Z_coord to float, and (iii) indentation of all the input data to the left? I don't think it matters that much, whitespace around column delimeters is usualy ignored, and the field types are defined from the data as it is read.
... View more
10-04-2012
12:22 PM
|
0
|
0
|
1502
|
|
POST
|
If the extent of a polygon approaches the raster resolution on your precipitation raster, you are going only pick up a few (or no) cells for each tax parcel polygon. Have you tried setting the environment Raster > Cell Size to be a smaller value than the resolution of your precip raster?
... View more
10-03-2012
09:24 PM
|
0
|
0
|
1910
|
|
POST
|
How do I create a new shapefile from a selected polygon? I'm trying to separate one county out of a state. Do I use clip tool? Using Version 10.1 Most geoprocessing tools that accept layer input will honor the current selected set, ie only take the selected features as input. All you need to do is either use the Copy Features tool. (Interactively, right click the layer, data, export will work too -- if you make sure the radio button is selected to only export selected features.)
... View more
10-03-2012
12:27 PM
|
0
|
0
|
735
|
|
POST
|
I would add a little tweak to capture the error messages if any. Also, the way to enter a blank line - no quotes is: "echo.":
@echo off
echo Start time: %time% > Road_Index_Update.log
echo ------------ Update time: %time%
echo ------------ Create Road Index -------------
echo ------------ Create Road Index ------------- >> Road_Index_Update.log
Feature_Class_for_Road_Index.py >> Road_Index_Update.log 2>&1
echo End time: %time%
echo. >> Road_Index_Update.log
echo End time: %time% >> Road_Index_Update.log
The issue of things not working when not logged in may be a Windows permissions setting. (That's why it was suggested you run at the highest permission account you have access to.)
... View more
10-03-2012
12:03 PM
|
0
|
0
|
4745
|
|
POST
|
Is this possible or do you have to delete one cursor before opening another? The arcpy.da.SearchCursor" rel="nofollow" target="_blank">http://resources.arcgis.com/en/help/main/10.1/index.html#/UpdateCursor/018w00000014000000/]arcpy.da.SearchCursor doc says right up front: Opening simultaneous insert and/or update operations on the same workspace using different cursors requires the start of an edit session.
... View more
10-03-2012
11:48 AM
|
0
|
0
|
3596
|
|
POST
|
{{ and }} give you single curlys. Neat, Jason! Interactive Python example: >>> 'I am going {{{nuts}}}'.format(nuts= 'crazy over this')
'I am going {crazy over this}'
>>>
... View more
10-03-2012
11:45 AM
|
0
|
0
|
10880
|
|
POST
|
I think it's safer to use positional parameters like they do in the help, instead of names. The arcpy.sa functions return a raster object. So, maybe something like this using PathDistance will work better?
from arcpy.sa import *
if Distance_method == "model-cost":
## calculates the least cost distance to the nearest lineage point
## the result is written directly to lineage_dist_gridname
distRaster = PathDistance(Raster("lin_lyr"),maxent_model)
distRaster.save(lineage_dist_gridname)
... View more
10-02-2012
02:45 PM
|
0
|
0
|
926
|
|
POST
|
We could dive in deeper on writing geometries, but if all you are working with is points, it's a LOT easier to create a csv file with field headings. Name it "myPoints.csv" and ArcGIS will see it as a table. You can feed that table directly to the MakeXYEventLayer tool. If you need a dataset, just follow that with Copy Features. Here's an example file "test.csv":
rec,x,y
1,-74.0,35.0
2,-74.1,35.1
See the tool help for Make XY Event Layer for an example. Hope this helps!
... View more
10-02-2012
02:26 PM
|
0
|
0
|
1502
|
|
POST
|
I swear by O'Reilly's Learning" rel="nofollow" target="_blank">http://shop.oreilly.com/product/9781565924642.do]Learning Python (Lutz). It's a really nice learning tool and refresher book.
... View more
10-02-2012
10:48 AM
|
0
|
0
|
2690
|
|
POST
|
It's always a bit of a confusing hassle to manage multiple installations of the same software on one machine, I'm constantly running into this myself on 64 bit systems where I have 64 and 32 bit installs of the same thing, or the fact that TortoiseHg uses its own local Python, etc. I did find a spot in the registry that provides those standard extra sys.path entries (I'm on XP64, so it's in the Wow6432Node folder): Name: HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Python\PythonCore\2.7\PythonPath Data: D:\Python27\ArcGIS10.1\Lib;D:\Python27\ArcGIS10.1\DLLs;D:\Python27\ArcGIS10.1\Lib\lib-tk
... View more
09-24-2012
12:58 PM
|
0
|
0
|
2240
|
|
POST
|
I have been toying around with ToolValidator b/c the script has to skip over creating a constant raster & performing times if there is no parameter (after the first 2 raster layers & weight values the parameters are optional). I'm not so clear how you are using the isinstance() function. The usual way to do this with arcpy is by examining the returned value of arcpy.GetParameterAsText(). If the argument was not provided (and was not populated using script tool defaults or in validation code) the GetParameterAsText() result will be an empty string (not None, since the function always returns a text string). if arcpy.GetParameterAsText(2) != "":
do stuff with arcpy.GetParameterAsText(2)
... View more
09-24-2012
12:29 PM
|
0
|
0
|
1458
|
|
POST
|
I'm more that a little curious about the motivations for needing to know this and dubious that it matters, but I'll indulge you. Thank you Jason, I really appreciate this - it really gives me a better handle on what's happening here. This is important to me because a colleague was having issues with the ArcMap prompt sys.path picking up a few 64 bit paths from his EPD 64 install - which could obviously break things (or not?). Knowing a bit more what is happening under the hood will definitely help us (and others trying to support multiple Pythons on the same computer) avoid problems. In general we seem to be having the best luck when we use startup scripts to keep total control of the system PATH when starting a specific Python that we want. I found some good documentation in the python manuals (27.14. site �?? Site-specific configuration hook), which taught me this cool trick to quickly check your setup: D:\Python27\ArcGIS10.1>python -m site
sys.path = [
'D:\\Python27\\ArcGIS10.1',
'D:\\ArcGIS\\Desktop10.1\\ArcToolbox\\Toolboxes\\USGS_EGISTools\\scripts',
'C:\\WINDOWS\\system32\\python27.zip',
'D:\\Python27\\ArcGIS10.1\\DLLs',
'D:\\Python27\\ArcGIS10.1\\lib',
'D:\\Python27\\ArcGIS10.1\\lib\\plat-win',
'D:\\Python27\\ArcGIS10.1\\lib\\lib-tk',
'D:\\Python27\\ArcGIS10.1\\lib\\site-packages',
'D:\\ArcGIS\\Desktop10.1\\bin',
'D:\\ArcGIS\\Desktop10.1\\arcpy',
'D:\\ArcGIS\\Desktop10.1\\ArcToolbox\\Scripts',
]
USER_BASE: 'C:\\Documents and Settings\\cprice\\Application Data\\Python' (doesn't exist)
USER_SITE: 'C:\\Documents and Settings\\cprice\\Application Data\\Python\\Python27\\site-packages' (doesn't exist)
ENABLE_USER_SITE: True
... View more
09-24-2012
11:52 AM
|
0
|
0
|
2240
|
|
POST
|
ArcGIS 10.1 Final Separate Python distribution (EPD) installed in its own folder (not in system PATH). Here's what I see from a command line:
Z:\>d:\python27\ArcGIS10.1\python
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print '\n'.join(sys.path)
("" - current folder)
D:\ArcGIS\Desktop10.1\ArcToolbox\Toolboxes\USGS_EGISTools\scripts # in my PYTHONPATH
C:\WINDOWS\system32\python27.zip
d:\python27\ArcGIS10.1\DLLs
d:\python27\ArcGIS10.1\lib
d:\python27\ArcGIS10.1\lib\plat-win
d:\python27\ArcGIS10.1\lib\lib-tk
d:\python27\ArcGIS10.1
d:\python27\ArcGIS10.1\lib\site-packages
D:\ArcGIS\Desktop10.1\bin # Desktop10.1.pth in site-packages
D:\ArcGIS\Desktop10.1\arcpy # Desktop10.1.pth in site-packages
D:\ArcGIS\Desktop10.1\ArcToolbox\Scripts # Desktop10.1.pth in site-packages
>>> But from within the ArcMap Python prompt I'm seeing paths that are not in my PYTHONPATH, somehow it's picking up libraries from my EPD.
>>> print '\n'.join(sys.path)
D:\ArcGIS\Desktop10.1\ArcToolbox\Toolboxes\USGS_EGISTools\scripts # in my PYTHONPATH
d:\arcgis\desktop10.1\arcpy
C:\WINDOWS\system32\python27.zip
E:\python27_epd32\Lib # where did these three come from??
E:\python27_epd32\DLLs
E:\python27_epd32\Lib\lib-tk
D:\Python27\ArcGIS10.1\Lib
D:\Python27\ArcGIS10.1\DLLs
D:\Python27\ArcGIS10.1\Lib\lib-tk
C:\Documents and Settings\cprice # where did this come from?
D:\ArcGIS\Desktop10.1\bin # Desktop10.1.pth in site-packages (why here?)
D:\Python27\ArcGIS10.1
D:\Python27\ArcGIS10.1\lib\site-packages
D:\ArcGIS\Desktop10.1\arcpy # Desktop10.1.pth in site-packages
D:\ArcGIS\Desktop10.1\ArcToolbox\Scripts # Desktop10.1.pth in site-packages
My EPD install gives me a shorter list, but it's still mysterious to me:
Z:\>e:\python27_epd32\python.exe
Enthought Python Distribution -- www.enthought.com
Version: 7.3-2 (32-bit)
Python 2.7.3 |EPD 7.3-2 (32-bit)| (default, Apr 12 2012, 14:30:37) [MSC v
Type "credits", "demo" or "enthought" for more information.
>>> import sys
>>> print "\n".join(sys.path)
("" - current folder)
D:\ArcGIS\Desktop10.1\ArcToolbox\Toolboxes\USGS_EGISTools\scripts
e:\python27_epd32\python27.zip
e:\python27_epd32\DLLs
e:\python27_epd32\lib
e:\python27_epd32\lib\plat-win
e:\python27_epd32\lib\lib-tk
e:\python27_epd32
e:\python27_epd32\lib\site-packages
e:\python27_epd32\lib\site-packages\PIL # PIL.pth in site-packages
e:\python27_epd32\lib\site-packages\win32 # pywin32.pth in site-packages
e:\python27_epd32\lib\site-packages\win32\lib # pywin32.pth in site-packages
e:\python27_epd32\lib\site-packages\Pythonwin # pywin32.pth in site-packages
This leaves me with some question about the ArcGIS Desktop Python prompt. 1. There are some entries in the sys.path in both setups that I honestly don't see where they came from. The first one in the lists above came from my PYTHONPATH, and the the last three are in the .pth file in site-packages. Where did all the others entries come from? 2. There are some imports (sys, arcpy) that the ArcMap python window has loaded already. Where did that happen? 3. The ArcMap python prompt is picking up some paths from somewhere mysterious (in italic above) 4. In all setups, what's up with the path: C:\WINDOWS\system32\python27.zip. That file does not exist in my install.
... View more
09-24-2012
11:30 AM
|
0
|
4
|
3736
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 08-11-2021 01:26 PM | |
| 5 | 12-10-2021 04:58 PM | |
| 1 | 02-27-2017 09:30 AM | |
| 2 | 12-04-2023 01:05 PM | |
| 1 | 04-12-2016 10:17 AM |
| Online Status |
Offline
|
| Date Last Visited |
06-19-2024
12:10 AM
|