|
POST
|
I tested it with your sample data, but I don't know how well it will work with more a more complex dataset. Note that the output field that lists all of the ItemID values has to have a limit, which I arbitrarily set to 255. Of course, you'll also need to change the paths and names accordingly. def main():
import arcpy
import os
# Local variables
mygdb = r"N:\TechTemp\BlakeT\Work\TEMP.gdb"
mytable = os.path.join(mygdb, "SegmentSequence")
# Read input table into dictionary
itemsdict = {}
with arcpy.da.SearchCursor(mytable, ["ItemID", "Begin", "End"]) as s_cursor:
for item, begin, end in s_cursor:
itemsdict[item] = (begin, end)
# Identify segments
allsegments = [i[0] for i in itemsdict.values()] + [i[1] for i in itemsdict.values()]
segments = tuple(sorted(set(allsegments)))
del allsegments
# Create output table
arcpy.CreateTable_management(mygdb, "SegmentSequence_output")
mytable_out = os.path.join(mygdb, "SegmentSequence_output")
arcpy.AddField_management(mytable_out, "Begin", "SHORT")
arcpy.AddField_management(mytable_out, "End", "SHORT")
arcpy.AddField_management(mytable_out, "SegmentItems", "TEXT", field_length=255)
# Write segment items to output table
with arcpy.da.InsertCursor(mytable_out, ["Begin", "End", "SegmentItems"]) as i_cursor:
for enum, seg in enumerate(segments):
try:
begin = seg
end = segments[enum + 1]
except IndexError:
break
seg_items = [k for k, v in itemsdict.items() if v[0] <= begin and v[1] >= end]
row = (begin, end, str(seg_items).strip('[]'))
i_cursor.insertRow(row)
if __name__ == '__main__':
main()
... View more
05-07-2015
04:47 PM
|
2
|
5
|
1820
|
|
POST
|
So it's kind of like this? 1004__________
1003_____
1002______________________________
1001_________________________
1000_____
0 1 2 3 4 5 6 7 So the segment from 0 to 1 includes items 1000, 1001 1 to 2 includes items 1001, 1002 2 to 3 includes items 1001, 1002 3 to 4 includes items 1001, 1002, 1004 4 to 5 includes items 1001, 1002, 1003, 1004 5 to 6 includes items 1002 6 to 7 includes items 1002 But it looks like you dissolve the segments that have the same items. So 1-2 and 2-3 become 1-3? Same with 5-6 and 6-7 becoming 5-7?
... View more
05-07-2015
03:21 PM
|
0
|
1
|
1820
|
|
POST
|
In the output table, how did you get a Begin range value of 5 when there was no Begin value of 5 in the input table?
... View more
05-07-2015
02:56 PM
|
0
|
3
|
1820
|
|
POST
|
Are all of the the "Item ID" values unique in the source table?
... View more
05-07-2015
02:31 PM
|
0
|
1
|
1820
|
|
POST
|
There's no easy, built-in way to do this. Have you considered using Subtypes? You can have different default field values based on whatever is chosen for the subtype.
... View more
05-06-2015
09:53 AM
|
0
|
0
|
3599
|
|
POST
|
Check out the Intersect Help Topic, there are some helpful Python code examples at the bottom. The function can take all three of your output files as a list for input.
... View more
05-05-2015
10:48 AM
|
0
|
0
|
906
|
|
POST
|
Sorry, here's the help topic for ArcGIS Pro The in_memory workspace—ArcGIS Pro
... View more
05-05-2015
08:38 AM
|
1
|
0
|
1063
|
|
POST
|
I think symbolizing your polygons by population with a fill using a graduated color ramp is the easiest way to visually identify which feature is greater or less than the other. Could you describe the overall goal here? Maybe there is a different way to approach your problem.
... View more
05-04-2015
10:50 AM
|
1
|
0
|
1330
|
|
POST
|
I typically use the method Tim Witt described to just print whatever I want to the Python Interpreter window. If you're using Esri geoprocessing tools, you can also print the original Esri messages with GetMessages (arcpy).
... View more
05-04-2015
10:31 AM
|
0
|
0
|
681
|
|
POST
|
ArcGIS Help 10.1 - Using in-memory workspace Just make sure you also delete your in-memory workspace afterwards to keep things clean.
... View more
05-04-2015
10:24 AM
|
1
|
2
|
1063
|
|
POST
|
If you like, post the code you used and we can help you debug it. I just tested my logic and it worked in a file geodatabase. Here is updated code that is a little more flexible. def main():
import arcpy
import os
temp_gdb = r"N:\TechTemp\BlakeT\Work\TEMP.gdb"
fc = os.path.join(temp_gdb, "TEMP_Line")
sortFieldName = "Note1"
seqFieldName = "SeqID"
# Step 1
existingFields = [field.name for field in arcpy.ListFields(fc)]
if seqFieldName not in existingFields:
arcpy.AddField_management(fc, seqFieldName, "SHORT")
# Step 2
cursorFields = [sortFieldName, seqFieldName]
sql_postfix = 'ORDER BY {}'.format(sortFieldName)
with arcpy.da.UpdateCursor(fc, cursorFields, sql_clause=(None, sql_postfix)) as u_cursor:
# Step 3
for seqid, row in enumerate(u_cursor, start=1):
# Step 4
row[1] = seqid
u_cursor.updateRow(row)
if __name__ == '__main__':
main()
... View more
05-04-2015
09:44 AM
|
1
|
2
|
4422
|
|
POST
|
Looks like the solution posted there is very similar to mine. Thanks for the follow-up Dan.
... View more
05-01-2015
04:51 PM
|
0
|
0
|
1580
|
|
POST
|
Could you try something like this? If applicable, Add Field to store sequential id Since you're on 10.2, you can create an update cursor with a sql clause using ORDER BY (see second to last code sample). The link is for 10.3 but I've tested this in 10.2.2 on SDE and file geodatabase just fine. Set up the iteration on the cursor using enumeration Iterate through the cursor and update the sequential id field with the enumeration number I haven't tested this, but here's an example: def main():
import arcpy
import os
temp_gdb = r"C:\Temp\MyGDB.gdb"
fc = os.path.join(temp_gdb, "MyFC")
# Step 1
arcpy.AddField_management(fc, "SeqID", "SHORT")
# Step 2
fields = ["OID@", "MySortField", "SeqID"]
with arcpy.da.UpdateCursor(fc, fields, sql_clause=(None, 'ORDER BY MySortField')) as u_cursor:
# Step 3
for seqid, row in enumerate(u_cursor, start=1):
# Step 4
row[2] = seqid
u_cursor.updateRow(row)
if __name__ == '__main__':
main()
... View more
05-01-2015
04:31 PM
|
1
|
8
|
2842
|
|
POST
|
When using Esri tools, I've always understood that append was the quickest way to do a mass insert. You could also try Copy Rows to see if that's any different.
... View more
05-01-2015
03:41 PM
|
1
|
1
|
2379
|
|
POST
|
Our solution is to break the attribute table apart and put the secured fields in a separate table that is related to the master feature class. You can then set all the necessary permissions on the related table(s).
... View more
04-29-2015
01:17 PM
|
0
|
1
|
619
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 12-01-2025 06:19 AM | |
| 1 | 07-31-2025 11:59 AM | |
| 1 | 07-31-2025 09:12 AM | |
| 2 | 06-18-2025 03:00 PM | |
| 1 | 06-18-2025 02:50 PM |