|
POST
|
Also - watch your paths. Single back slashes may be interpreted incorrectly on windows. They need to be double or the string must be prefixed by "r". arcpy.CreateFolder_management("C:\\ETE_STATE",outName,outName2,outName3,outName4) Arc 10 help: Paths explained
... View more
08-27-2012
10:22 AM
|
0
|
0
|
1742
|
|
POST
|
If I could convert the <Null>s to zeros then I believe this the 'return max() function' might work. The try/except handles the issue where all are null - you'll just get null back. Calculate Field tool: Expression: maxfld(!Area1!, !Area2!, !Area3!) def maxfld(fld1,fld2,fld3):
try:
lst = list()
for k in (fld1,fld2,fld3):
if k: lst.append(k)
return max(lst)
except:
pass
... View more
08-27-2012
10:01 AM
|
0
|
0
|
4557
|
|
POST
|
Looking good. Can't overstate the usefulness of that Python tutorial! Your function looks fine - but you need to run it:
>>> file_check(path)
One little thing, there is another os function that will avoid a bug in your program if there are extra dots in your file name. instead of using split(), os.path.splitext():
for file in os.listdir(path):
basename = os.path.splitext(os.path.basename(file))[0]
if basename not in mlist:
mlist.append(basename)
Also - your last if statement is inside the loop, I think you want it to dedent so it will run after the for loop is done.
... View more
08-27-2012
08:58 AM
|
0
|
0
|
4376
|
|
POST
|
I went into Control Panel (Windows Server 2008) but did not see python listed in the Add/Remove programs area. It looks like the 10.0 uninstaller removed Python 2.6 - but maybe not all of it. And it looks like your windows file associations maybe are still pointing .py files to Python26.exe - it should be opening all .py files with Python27.exe. this is why a repair install of Python 2.6 (from the 10.0 DVD) followed by an uninstall of 2.6 followed by a repair install of Python 2.7 (from the 10.1 DVD) may be the best fix. Or you can try to go in brute-force and (as -pr) open windows explorer and in Tools / Folder Options make sure .py files are associated with the correct python.exe. But I've found that often just the repair-install approach seems to get everything done better in the long run, so I would try that first. However, A manual thing you could and should do is remove any references to Python 2.6 from your system PATH variable. Installers usually aren't very good at editing the PATH. The command line I gave would work from any folder, as it specifying the full path to the Python 2.7 executable. I formatted up my code block to make that more clear.
... View more
08-24-2012
03:10 PM
|
0
|
0
|
1685
|
|
POST
|
This doesn't work? E:\workspace> C:\Python27\ArcGIS10.1\python.exe scriptname.py You want only one version of Python installed unless you absolutely require multiple versions, as it can be done but is a real pain. ArcGIS 10.1 Server requires Python 2.7 (64 bit, yay!)
... View more
08-24-2012
02:31 PM
|
0
|
0
|
1685
|
|
POST
|
I tried to select only those features that aren't equal to zero, but the tool 'Select Layer By Attribute' could not be integrated in the model chain. If you pass your dataset or table to Make Feature Layer or Make Table View with a where expression you should be able to connect its output to Calculate Field with just the rows you want available to calculate. Alternatively, you could use a code block with Calculate Field. This would just give you nothing in the field if the divide failed for any reason: expr: f(!POP_2010!,!RES_PIX!) Type: PYTHON code:
def f(pop,res):
try:
return pop / float(res)
except:
pass
... View more
08-24-2012
01:46 PM
|
2
|
0
|
1689
|
|
POST
|
1. Please can you shed more light on how to extract the value from your table using a cursor (row.getValue) and the conversion, im still a juvenile with arcpy/python. There are helpful examples in the help for SearchCursor. 2. For a reason i don't know the script arcpy.MakeFeatureLayer_management("Parcels", "tLyr", '"TDP_Status" = \'GENERATED\'')
count = int(arcpy.GetCount_management("tLyr").getOutput(0))
if count == 0:
arcpy.AddMessage("TDP already generated")
else:
arcpy.Buffer_analysis("Parcels", "ClipFeature", "12.5 meters", "FULL", "ROUND", "LIST") Continues with the buffer process even if the count is o or 1. Do you know why? This shouldn't happen if your indents are correct as above. I would test your script by printing a test message (arcpy.AddMessage("Count is: " + str(count)).
... View more
08-24-2012
01:29 PM
|
0
|
0
|
1723
|
|
POST
|
i want to generate a pdf output by using the arcpy.exporttopdf function, i want the final output to use this nomenclature for naming the pdf output (plot_no.pdf); the plot_no would be derived from an attribute value under the field named plot_no in the attribute table. Please do you have any suggestions. OK, last post on this thread. 🙂 Extract the value from your table using a cursor (row.getValue), convert it to a string if necessary and construct a pathname to pass to the arcpy.ExportToPDF tool -- like this: outName = "plot_" + str(val) + ".pdf"
... View more
08-24-2012
01:06 PM
|
0
|
0
|
1723
|
|
POST
|
Sorry to bother you again i got this error Sorry; I fixed the code above. There's an example for getOutput (I spelled it wrong) in the help for the GetCount tool.
... View more
08-24-2012
12:21 PM
|
0
|
0
|
1723
|
|
POST
|
Thanks curtvprice for the nugget of information, please can you help me with this Please can you kindly help with this script also; i am trying to do a search through my attribute table, for a field called TDP_Status and if the attribute is GENERATED, I want the arcpy script to print TDP ALREADY GENERATED and stop the process else it should continue with the buffer analysis. Please [post=224499]use [noparse] blocks[/noparse][/post] in your posts - it really helps.
No need for a cursor - the GetCount tool is very helpful here.
arcpy.MakeFeatureLayer_management("Parcels", "tLyr", '"TDP_Status" = \'GENERATED\'')
count = int(arcpy.GetCount_management("tLyr").getOutput(0))
if count == 0:
arcpy.AddMessage("TDP already generated")
else:
arcpy.Buffer_analysis("Parcels", "ClipFeature", "12.5 meters", "FULL", "ROUND", "LIST")
... View more
08-24-2012
11:06 AM
|
0
|
0
|
1723
|
|
POST
|
Where do i add the field?
arcpy.AddField("table","TIME_GEN","TEXT","","",20)
import datetime
now = datetime.datetime.now()
strNow = now.strftime("%d %b %Y %H:%M:%S")
arcpy.CalculateField_management("table","FIXDATE",'"' + strNow + '"')
... View more
08-24-2012
10:28 AM
|
0
|
0
|
1723
|
|
POST
|
Just to debate Curtis' statement about cursors vs. CalculateField... Thanks Chris - I hope you meant "discuss" -- the "right" way to do something can include many factors, including whether you need to support multiple versions of ArcGIS, what is easiest for you to code/maintain, what you "like", etc.... This is helpful information. I hadn't done any testing and probably didn't notice because like you, I tend to use Calculate Field for simple expressions using VBScript (the default), which as you have said - is faster than python cursors. Great to hear that arcpy.da cursors are near the speed of ArcObjects cursors.
... View more
08-24-2012
09:24 AM
|
0
|
0
|
1623
|
|
POST
|
What I am doing wrong? Close is a function. To make it work you need parentheses (you're missing them at the end) >>> f1.close # just prints the string rep of the object <built-in method close of file object at 0x01E55E90> >>> f1.close() # with the parens the function will actually do the close I'm a huge fan of Python's interactive window. FORTRAN sure didn't have that. 🙂
... View more
08-24-2012
08:38 AM
|
0
|
0
|
3147
|
|
POST
|
doesn't the Calc Field tool simply implement a cursor behind the scenes? Why is that inherently faster? Is it because the cursor doesn't have to work through the interpreter? I don't know whether Calculate Field uses cursors, but I do know that there are at least three kinds of cursors in the ArcGIS universe: 1. arcpy cursors, 2. ArcObjects cursors (accessed through .NET) and 3. (new at 10.1) arcpy.da cursors. Calculate Field can do complex decision making with a code block, but can only write to one field. All I know is that CF is much faster and more convenient to code, so for me it's preferable if you only need to write to one field.
... View more
08-24-2012
08:28 AM
|
0
|
0
|
1623
|
|
POST
|
how can i include the current time also. The details are in the Python documentation. http://docs.python.org/library/time.html
import datetime
now = datetime.datetime.now()
strNow = now.strftime("%d %b %Y %H:%M:%S")
... View more
08-24-2012
08:22 AM
|
0
|
0
|
1623
|
| 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
|