|
POST
|
Well, sort of: 1) You can copy and paste the code all at once into the Python window in ArcMap 2) For Python.exe and PythonWin you either need to: A. Copy, paste, and execute each line of code (one at a time) B. Save the code as a .py file and then run the .py file via python.exe or PythonWin. BTW: Does anyone know of a Python IDE (or a method in PythonWin) that lets you execute blocks of code all at once (copy and paste a bunch of code into an "Interactive Window" and then execute it)???? I found you can do this in the Python Window in ArcMap, but as of yet I can't find a way to do it in PythonWin.
... View more
11-01-2010
12:33 PM
|
0
|
0
|
3961
|
|
POST
|
Here's how I would do it: import arcgisscripting
gp = arcgisscripting.create(9.3)
gp.overwriteoutput = True
catchmentsFC = gp.GetParameterAsText(0) #in a toolbox GUI, this should be Type = FeatureLayer
landCoverFC = gp.GetParameterAsText(1) #in a toolbox GUI, this should be Type = FeatureLayer
outputFC = gp.GetParameterAsText(2) #in a toolbox GUI, this should Type = FeatureClass
gp.Intersect_Analysis (catchmentsFC + ";" landCoverFC, outputFC, "ALL", "", "INPUT")
... View more
11-01-2010
11:07 AM
|
0
|
0
|
5388
|
|
POST
|
your code of: gp.Intersect ("Catchments; LandCover", Output, "ALL", "", "INPUT") should be: gp.Intersect (Catchments + ";" LandCover, Output, "ALL", "", "INPUT") When you used "Catchments; LandCover" in your code, you are using the string equivalent instead of the variables (formatted as a string in order to be used in the tool).
... View more
11-01-2010
10:52 AM
|
0
|
0
|
5388
|
|
POST
|
Is Output = gp.GetParameterAsText(2) a featureclass output? If so: gp.Intersect ("LandCover; Catchments", Output, "ALL", "", "INPUT") #don't put quotes around the variable because if you do, it just becomes a string... If Output is the directory where "output.shp" will be stored, then: gp.Intersect ("LandCover; Catchments", Output + "\\output.shp", "ALL", "", "INPUT") You might want to consider making a toolbox GUI, then there is easy control over the "types" of parameters (e.g. Folder vs. a FeatureClass vs. a Raster).
... View more
11-01-2010
10:38 AM
|
0
|
0
|
5388
|
|
POST
|
FYI: gp.GetParameterAsText() is used only when getting arguments from an ArcToolbox tool interface sys.argv[] is used when getting arguments from another "non-toolbox" source. For example: #master script (calls 100 instances of "subprocess.py"
subProcessScript = r"C:\temp\subprocess.py"
pythonExePath = r"C:\Python25\python.exe"
rootDir = r"D:\temp"
for tileNumber in range (1,101):
parameterList = [pythonExePath, subProcessScript, rootDir, str(tileNumber)]
os.spawnv(os.P_WAIT, pythonExePath, parameterList)
#subprocess program (subprocess.py)
rootDir = sys.argv[1]
tileNumber = sys.argv[2]
os.mkdir(rootDir + "\\tile_" + str(tileNumber)
... View more
11-01-2010
10:09 AM
|
0
|
0
|
5388
|
|
POST
|
Or using a dictionary-based approach: import os, arcpy
rootDir = r"D:\csny490\temp"
meregString = ""
shpDict = {}
for dirPath, dirNames, fileNames in os.walk(rootDir, topdown = False):
for fileName in fileNames:
if fileName.endswith(".shp"):
if fileName not in shpDict:
shpDict[fileName] = [dirPath]
else:
shpDict[fileName].append(dirPath)
for shp in shpDict:
for path in shpDict[shp]:
mergeString = mergeString + path + "\\" + shp + ";"
arcpy.Merge_management(mergeString[:-1], r"D:\csny490\trythis.gdb\merge_output")
... View more
11-01-2010
09:44 AM
|
0
|
0
|
3961
|
|
POST
|
Moving existing posts, which I really don't feel strongly one way or the other, is a pretty small detail overall, and is really a side issue. If it will help grease the wheels towards the end goal, I say no - don't move existing posts. I'll admit: If I posted a question about scripting the Clip tool using Python and put it in the new ***Python Forum***, and then ESRI created a new Clip tool forum (because some wingnut begged and pleaded with ESRI to create a Clip tool forum for say maybe the last 4 months or so), and then ESRI moved all the Clip tool posts to the new Clip tool forum - yes I'd probably be mad about that. Leave it up to the users where their posts go. If they want it in a new forum, they can cross post it there. New Python forum topic. Don't move posts. Sink or swim. Easy. 😄
... View more
10-29-2010
08:08 AM
|
0
|
0
|
1479
|
|
POST
|
If Jim were to create a new forum for Python, what is the argument to not consolidate existing Python-related posts from other forums there (other than it being a pain in the :o)? I suppose it may be a bit conflicting to move a post entitled "How to execute SDE commands via Python" that was currently in the SDE forum. But, as my basic argument basically states, I think a question like that would stand a better chance of being answered if it was in a Python forum in the 1st place. I agree there is some grey area, but not a huge amount...
... View more
10-28-2010
01:23 PM
|
0
|
0
|
1479
|
|
POST
|
Another question in regards to your response to #3: Do you think Esri should move any and all existing python related discussions (like those currently in Map Automation, etc) to the future Python subforum? It's not critical... But if Jim has a magic wand to do that sort of thing, by all means.
... View more
10-28-2010
12:16 PM
|
0
|
0
|
1668
|
|
POST
|
So my questions: - Will a separate Python forum remedy this situation? Will it prevent python discussions from cropping up in other forums? - Do you guys recommend posting the same question multiple times on multiple forums? - And should any and all Python related discussions go in a future Python forum? As Dan mentioned above, there has to be another way�?� #1a: Won't remedy it, but I do think it will minimize it. #1b: No, but again, probably minimize it. #2: No, but honestly I don't really see the problem in cross posting the same thread to different forums. #3. Ideally yes. #Another way? I haven't heard many: Auto-tagging crawler code? Expert users applying tags manually? Seems too pie-in-the-sky to me. Jim already said he wouldn't (or at least be reluctant) to institute an forum crawler auto-tagger. Who's going to sit around an manually tag stuff? Not me! Per #3, Frank P. said: For example i have seen topics like the following throughout the geoprocessing forum: - Model Builder - Writing custom Geoprocessor Tools with their own Python Scripts - Writing Python Scripts from Scratch to be used via command line - ArcObjects and Python - This third party library python has issues with ArcGIS - My python install is borked. - How can i implement X for python? (or any other question just about python) This is very true of course. My argument is that these questions all have the word "Python" in them (except the MB one!), and therefore belong in the "Python" forum. Assuming, people that are knowledgeable of Python stuff, and and like to lurk in the Python forum (because they learn a lot doing so), would have good/better answers to these questions as they have the focused experience in "many things Python". Basically, a focused concentration of knowledge on a specific topic will yield better results. The positive outcome is debatable, but this logic worked well at Los Alamos in the 1940's. The focus here I think should be building a "community" of knowledgeable and motivated contributors and making it easy for them to contribute answers. A single "General" forum is not community building, nor does it make it easy for contributors to respond to threads related to their specific areas of expertise. Merriam-webster definition for "Community": People with common interests (like GIS-Python scripting) living in a particular area (like an ESRI "Python" forum). Vote Python!
... View more
10-28-2010
09:46 AM
|
0
|
0
|
1668
|
|
POST
|
George, Sorry to lead you astray: Seems the "\"\ thing for .shp and .dbf formats is no longer neccessary in v9.3.1. Try this: gp.SelectLayerByAttribute("temp_lyr", "NEW_SELECTION", "BID = '1'") or if the BID field is numeric, then just this: gp.SelectLayerByAttribute("temp_lyr", "NEW_SELECTION","BID = 1")
... View more
10-28-2010
08:25 AM
|
0
|
0
|
1395
|
|
POST
|
This is a stupid syntax thing with .shp and .dbf files, but try this: gp.SelectLayerByAttribute("temp_lyr", "NEW_SELECTION","\"BID"\" = '1'") if it was in FGDB it would just be: gp.SelectLayerByAttribute("temp_lyr", "NEW_SELECTION","BID = '1'")
... View more
10-27-2010
03:46 PM
|
0
|
0
|
1395
|
|
POST
|
WAIT A MINUTE - aren't you the same Bart_D_Hound that said this: Put my vote in as well for splitting up these here forums for gp, into scripting (python) and at least Model Builder, along with General GP. here: http://forums.arcgis.com/threads/10092-Should-this-forum-be-SPLIT?p=48122&viewfull=1#post48122 What gives? This vote certainly isn't going the way I thought it would...
... View more
10-27-2010
02:48 PM
|
0
|
0
|
2309
|
|
POST
|
Poll posted to http://forums.arcgis.com/threads/15984-Should-there-be-a-new-quot-Python-Scripting-quot-forum I should have made one of these a while back...
... View more
10-27-2010
10:02 AM
|
0
|
0
|
574
|
| 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
|