|
POST
|
Additionally, field names cannot begin with a number.
... View more
07-03-2017
09:40 AM
|
2
|
0
|
2214
|
|
POST
|
So you've got what sounds like a Near Table (no matter how it was created) and want to just grab the nearest n destinations for each OID? See if something like this works. Feels a little clunky with the conditionals but it was the easiest solution that came to mind. num_results = 3 ## set to how many SID matches you want for each OID
# Create output table with no rows
arcpy.TableToTable_conversion(inTable, outLocation, outTable, "1=0")
fields = ["OID","SID","Distance"]
with arcpy.da.SearchCursor(inTable, fields, sql_clause=(None, 'ORDER BY OID, DISTANCE')) as s_cursor:
with arcpy.da.InsertCursor(outTable, fields) as i_cursor:
oid_track = None
oid_count = 1
for oid, sid, dist in s_cursor:
if oid == oid_track:
if oid_count <= num_results:
oid_count += 1
# write to outTable
i_cursor.insertRow((oid, sid, dist))
else:
oid_count = 1
oid_track = oid
# write to outTable
i_cursor.insertRow((oid, sid, dist)) If that's still too slow, we can look at trying to improve performance with dictionaries.
... View more
07-03-2017
09:18 AM
|
1
|
5
|
1548
|
|
POST
|
Could you step back and clarify what the source tables look like? Ignore any intermediate table work your script is doing.
... View more
06-30-2017
04:39 PM
|
0
|
7
|
4085
|
|
POST
|
It means that the main goal of the PEP 468 "Preserving the order of **kwargs in a function" is now implemented in Python 3.6 Interesting...
... View more
06-30-2017
04:36 PM
|
0
|
0
|
4085
|
|
POST
|
Also, the sorted() method will sort dictionaries by their key value (unless otherwise specified with the key parameter). EDIT: I see you're using a dictionary but not actually assigning anything to the value. In other words, you just need a list. Or in this case, a tuple would work because it's immutable and preserves the order items were inserted. Try something like BIDList = tuple(BID for BID, SID, Dist in in cursor)
... View more
06-30-2017
03:52 PM
|
0
|
3
|
4085
|
|
POST
|
As you found, dictionaries (and lists) do not preserve the order of items added. However, there is an OrderedDict in the collections module that will maintain the order of items. However, instead of trying to do the distance checking manually, Near or Generate Near Table might suit your needs better.
... View more
06-30-2017
03:25 PM
|
2
|
6
|
4085
|
|
POST
|
You posted in the GeoNet Help community but it should probably be in Managing Data or https://community.esri.com/community/gis/analysis/spatial-analyst?sr=search&searchId=c6738220-e61e-4e3f-9c7e-502f2a96a3b1&searchIndex=3
... View more
06-29-2017
09:47 AM
|
0
|
0
|
2651
|
|
POST
|
Since this discussion was created in 2011, ListDomains—Help | ArcGIS Desktop is probably the best way to get this information in 2017 using Python.
... View more
06-29-2017
08:22 AM
|
1
|
0
|
3013
|
|
POST
|
When using an if statement, you probably have to use the field calculator code block option. You also mixed up the field name syntax between VB and Python. code block: def compareCalc(col1, col3):
if col1 == col3:
return 'yes'
else:
return 'no' expression: compareCalc(!column1!, !column3!)
... View more
06-29-2017
08:17 AM
|
1
|
0
|
2035
|
|
POST
|
In the future, try Posting code with Syntax Highlighting on GeoNet. Makes code easier to read and copy.
... View more
06-27-2017
03:50 PM
|
0
|
1
|
1824
|
|
POST
|
In addition to the ArcREST scripts, I also found the ArcGIS Server Administration Toolkit - 10.1+ helpful; although the code on GitHub is probably more up to date.
... View more
06-22-2017
08:18 AM
|
1
|
0
|
5083
|
|
BLOG
|
We added some fancy formatting to the email sent out by all of our Python scripts running as scheduled tasks. # Opening lines of email message body
msg = "{scriptName} ran on {hostComputer}".format(
scriptName = os.path.basename(__file__),
hostComputer = socket.gethostname()
)
istring = " Started {} ".format(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
msg += "\n\n{:~^64}\n\n".format(istring) This creates the msg string which becomes the email body. The first two lines of the email always looks like this... SomeScriptFileName.py ran on ServerName123
~~~~~~~~~~~~~~~~~ Started 2017-06-19 04:30:03 ~~~~~~~~~~~~~~~~~~ There's a similar line at the end of the email too.
... View more
06-21-2017
09:47 AM
|
2
|
0
|
495
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 07-10-2026 07:32 AM | |
| 1 | 10-23-2025 03:53 PM | |
| 1 | 04-28-2026 07:25 AM | |
| 1 | 03-19-2026 08:59 AM | |
| 1 | 02-12-2026 01:37 PM |