|
POST
|
I want to calculate the time it takes to run series of geoprocessing tasks and use the result to populate a particular field in my database, any suggestions? Thanks
... View more
10-08-2013
05:00 AM
|
0
|
2
|
1744
|
|
POST
|
...if I may, I'd like to comment just a bit further on this - I thought I saw a better answer somewhere else a while back so out of curiosity I made a note to look later for it and lo and behold, here is something I think will even appeal to Richard (because it contains a single answer, at the time of this post anyway), please see the below. This is the work posted by Mike Toews and Tanner: Field Calculate Degree Minute Second in Different Format http://gis.stackexchange.com/questions/30754/field-calculate-degree-minute-second-in-different-format I didn't realize this, but there's unicode support in ArcMap for the characters degree, prime (minutes), and double-prime (seconds). These are designated by \u00B0, \u2032, and \u2033', respectively. The apostrophe or single-quote character substitution for minutes will do fine, but since we're talking about it and there's support for it, let's be more exact. Also, for what it's worth I agree with Matt about making the code more readable -- certainly it has tripped me in comic style like Jerry Lewis or Dick Van Dyke...but back to the point, why not write it in easy fashion without the necessity to escape quotes? So, try this technique to set the expression (exp): exp = u"str(%s) + '\u00B0 ' + str(%s) + '\u2032'" % ('!NUM1!','!NUM2!') ...or this, if you like the 'format' approach better: exp = u"str({0}) + '\u00B0 ' + str({1}) + '\u2032'".format('!NUM1!','!NUM2!') Then, of course, you can 'plug n play' this exp in the field calculator: arcpy.CalculateField_management("GISMainFabric_Line_Clip_0", "Bear", exp, "PYTHON_9.3") Enjoy, Wayne Cool it worked perfectly!!!
... View more
10-03-2013
09:24 AM
|
0
|
0
|
824
|
|
POST
|
Think I figured it out. Wildcard needs a wildcard: mxd = arcpy.mapping.MapDocument("Current")
tableText = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "TableText")[0]
for elm in arcpy.mapping.ListLayoutElements(mxd, wildcard="*_clone"):
print elm.name #just to double check you're actually getting results in the list
elm.delete() Thanks it worked perfectly!!! Although i added an extra * for elm in arcpy.mapping.ListLayoutElements(mxd, wildcard="*_clone*"):
... View more
10-02-2013
10:11 AM
|
0
|
0
|
1036
|
|
POST
|
If I had done this in Model Builder and exported it to Python like I normally do this thread would not be up to 16 posts. That is how I do it normally. Here is from the Model Builder export of a calculation that worked. # Process: Calculate Field
arcpy.CalculateField_management("GISMainFabric_Line_Clip_0", "Bear", "str( !NUM1! ) + \"\\xb0 \" + str( !NUM2! ) + \"'\"", "PYTHON_9.3", "") Thanks rfairhur24 It Worked perfectly!!!
... View more
10-02-2013
09:57 AM
|
0
|
0
|
1418
|
|
POST
|
What version of ArcGIS are you on (10.0 and under don't have the delete() method)? Version 10.1
... View more
10-02-2013
09:43 AM
|
0
|
0
|
1036
|
|
POST
|
Well this one you should be figuring out, since it tells you in the error what the problem is this time. You missed the underscore in "PYTHON_9.3" (You wrote "PYTHON 9.3") exp = 'str(!NUM1!) + "\xb0" + str(!NUM2!)'
arcpy.CalculateField_management("GISMainFabric_Line_Clip_0","Bear", exp,"PYTHON_9.3") If you want a space between the numbers and the minutes symbol after the second number, the expression should be: exp = 'str(!NUM1!) + "\xb0 " + str(!NUM2!) + "'"' This error below was what I got when I tried your suggestion, >>> exp = 'str(!NUM1!) + "\xb0 " + str(!NUM2!) + "'"'
Parsing error SyntaxError: EOL while scanning string literal (line 1)
... View more
10-02-2013
09:29 AM
|
0
|
0
|
1418
|
|
POST
|
I created some text element by cloning the original text element, I intend to delete all the cloned text elements after using them but after running my script it does not work at all, any suggestions. The cloned text elements are named Table Text_clone1, Table text_clone2 etc, see my code below >>> mxd = arcpy.mapping.MapDocument("Current") >>> tableText = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "TableText")[0] >>> for elm in arcpy.mapping.ListLayoutElements(mxd, wildcard="_clone"): ... elm.delete() ...
... View more
10-02-2013
09:20 AM
|
0
|
4
|
2824
|
|
POST
|
Thanks, but this is what I got: exp = 'str(!NUM1!) + "\xb0" + str(!NUM2!)'
>>> arcpy.CalculateField_management("GISMainFabric_Line_Clip_0","Bear", exp,"PYTHON 9.3")
...
Runtime error Traceback (most recent call last): File "<string>", line 1, in <module> File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\management.py", line 3128, in CalculateField raise e ExecuteError: Failed to execute. Parameters are not valid. ERROR 000800: The value is not a member of VB | PYTHON | PYTHON_9.3. Failed to execute (CalculateField).
... View more
10-02-2013
09:15 AM
|
0
|
0
|
1418
|
|
POST
|
Im afraid this is what I got exp = 'str(!NUM1!) + \'\xb0\'' + str(!NUM2!)'
Parsing error SyntaxError: invalid syntax (line 1)
... View more
10-02-2013
08:31 AM
|
0
|
0
|
3145
|
|
POST
|
Yeah! I got it see my code below import arcpy import pythonaddins import os import datetime import time arcpy.env.overwriteOutput = True class GraphicElementClass(object): """Implementation for GraphicElement_addin.button (Button)""" def __init__(self): self.enabled = True self.checked = False def onClick(self): mxd = arcpy.mapping.MapDocument("Current") df = arcpy.mapping.ListDataFrames(mxd)[0] lyr = arcpy.mapping.ListLayers(mxd, "LineTableLayoutz")[0] tableText = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "TableText")[0] numRows = int(arcpy.GetCount_management(lyr).getOutput(0)) rowHeight = 0.2 fieldNames = ["Sequence", "ParcelPlot_No", "FromBeaconNo", "ToBeaconNo", "Bearing", "Length"] numColumns = len(fieldNames) colWidth = 1.5 if df.scale <= 250: upperX = 2.5 upperY = 7.0 elif df.scale <= 500: upperX = 2.5 upperY = 7.0 elif df.scale <= 750: upperX = 2.5 upperY = 8.0 elif df.scale <= 1000: upperX = 2.5 upperY = 8.0 elif df.scale <= 1500: upperX = 2.5 upperY = 8.0 elif df.scale <= 2000: upperX = 2.5 upperY = 8.0 elif df.scale <= 2500: upperX = 2.5 upperY = 8.0 elif df.scale <= 5000: upperX = 2.5 upperY = 8.0 else: if df.scale <= 10000: upperX = 2.5 upperY = 8.0 tableText.elementPositionX = upperX + 0.05 tableText.elementPositionY = upperY tableText.text = fieldNames[0] accumWidth = colWidth for field in range(1, numColumns): newFieldTxt = tableText.clone("_clone") newFieldTxt.text = fieldNames[field] newFieldTxt.elementPositionX = newFieldTxt.elementPositionX + accumWidth accumWidth = accumWidth + colWidth table = arcpy.SearchCursor(lyr.dataSource) y = upperY - rowHeight for row in table: x = upperX + 0.05 try: for field in fieldNames: newCellTxt = tableText.clone("_clone") newCellTxt.text = row.getValue(field) newCellTxt.elementPositionX = x newCellTxt.elementPositionY = y accumWidth = accumWidth + colWidth x = x + colWidth y = y - rowHeight except: print"Invalid value assignment"
... View more
10-02-2013
07:33 AM
|
0
|
0
|
854
|
|
POST
|
Still the same error message ("GISMainFabric_Line_Clip_0","Bear","'" + str([NUM1]) + '\xb0' + str([NUM2]) + "'" ,"PYTHON 9.3")
Runtime error
Traceback (most recent call last):
File "<string>", line 1, in <module>
NameError: name 'NUM1' is not defined
... View more
10-02-2013
07:29 AM
|
0
|
0
|
3145
|
|
POST
|
Another error message arcpy.CalculateField_management("GISMainFabric_Line_Clip_0","Bear",str([NUM1]) + '\xb0' + str([NUM2]) + "'","PYTHON 9.3")
Runtime error
Traceback (most recent call last):
File "<string>", line 1, in <module>
NameError: name 'NUM1' is not defined
... View more
10-02-2013
06:56 AM
|
0
|
0
|
3145
|
|
POST
|
I tried your suggestion and this was what I got below: Traceback (most recent call last):
File "C:\Users\Administrator\AppData\Local\ESRI\Desktop10.1\AssemblyCache\{7F12A0CE-D617-8330-5EBC-E045415D9345}\PlanTool_addin.py", line 105, in onSelChange arcpy.CalculateField_management("GISMainFabric_Line_Clip_0","Bear",str[NUM1] + '\xb0' + str[NUM2] + "'","PYTHON 9.3")
NameError: global name 'NUM1' is not defined
... View more
10-02-2013
04:20 AM
|
0
|
0
|
3145
|
|
POST
|
I tried to populate a field by using the line below in my script but I got the error message below. Please how can I represent the degree (°) & Minute (') symbols in my Python Script. Any suggestions? arcpy.CalculateField_management("GISMainFabric_Line_Clip_0","Bear",'[NUM1] & "°" & [NUM2]',"VB") File "C:\Users\Administrator\AppData\Local\ESRI\Desktop10.1\AssemblyCache\{7F12A0CE-D617-8330-5EBC-E045415D9345}\PlanTool_addin.py", line 105 SyntaxError: Non-ASCII character '\xb0'
... View more
10-01-2013
05:43 PM
|
0
|
22
|
7330
|
|
POST
|
I'm trying to get my footing with my python scripts, please how would my code for your suggestion look like? If I can get a starting point, it would help me a great deal. Thank you for your wonderful suggestion.
... View more
09-30-2013
09:41 AM
|
0
|
0
|
854
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 10-19-2015 08:49 AM | |
| 1 | 10-15-2013 04:42 AM | |
| 1 | 09-20-2016 03:45 AM | |
| 2 | 09-25-2016 03:50 PM | |
| 1 | 08-25-2012 09:15 PM |
| Online Status |
Offline
|
| Date Last Visited |
11-11-2020
02:23 AM
|