POST
|
I don't know of a single tool to accomplish your task, but I do it in two steps: After creating a feature class with road arc endpoints using FeatureVerticesToPoints_management, I remove the duplicate (overlapping) points with DeleteIdentical_management, specifying the "Shape" field to end up with one point at each endpoint. Alternatively, if I want a feature class without dangles or pseudonodes, there is an intermediate step. I do a one-to-many spatial join after using FeatureVerticesToPoints. The output has a "Join_Count" field which tells me how many points are at each location, so I can query out the points with Join_Count >= 3 (assuming arcs are split at intersections) to get the true nodes (intersections) only, and then I delete the identical points.
... View more
07-23-2014
01:57 PM
|
3
|
1
|
352
|
POST
|
Did you specifically create a toolbar for your add-in, as well as a tool (or button)? If not, open the customize window, and select the "commands" tab, and type the name of your tool in the "Show commands containing" box. If your tool installed properly, regardless of whether it is part of a toolbar, then it should be there. You can then drag the tool and place it in any open toolbar. Kerry
... View more
06-26-2014
08:41 AM
|
0
|
0
|
8
|
POST
|
Aaaargh! You're right! The field.defaultValue *is* a valid property...it just isn't documented in 10.1 or 10.2!!! I was relying on the documentation for the arcpy field class. I also tried searching the 10.2 help for "defaultValue," and finally gave up and parsed the default values out of the metadata xml files (ugh!). I submitted feedback through the Help pages, so hopefully that will be updated. Kerry
... View more
06-26-2014
07:52 AM
|
1
|
0
|
29
|
POST
|
Here's the code for the Python add-in I was referring to. Keep in mind that it is meant to work with our own data, so it would require significant changes to perform similarly with someone else's data. #ShieldToolAddin.py #By Kerry Alley 2013-03-12 #Vermont Agency of Transportation # #Python Add-In for ArcMap 10.1, 10.2 # #SELECT_ROAD (button) #When activated, will select features within 20 map-meters of the mouse click on the map. #The features are selected only from the top-most layer with the GDB_HMS.HMSADMIN.rdsmall_arc # data source, regardless of layer name. # #CREATE_SHIELD (button) #Requires that a single rdsmall_arc feature already be selected #User makes a single click on the map to indicate the location of the highway shield, and # makes a double-click where the leader line extending from the highway shield will end. #Both a point feature and a line feature are created, with relevant attributes transferred # from the selected rdsmall_arc feature. #There is an un-commentable option in this script that sets the length of the leader line to # a fixed length, for uniformity. # #NOTE: This addin works "normally" if there is not an active editing session in ArcMap, but if # there is an active editing session, the addin "crashes" at the call to stopEditing(). The # features will still be created, but the screen will not refresh if there is a pre-existing # editing session active. import arcpy, time, os, math import pythonaddins class SelectRoadClass(object): """Implementation for ShieldToolAddinA_addin.tool (Tool)""" def __init__(self): self.enabled = True self.shape = "NONE" def onMouseDownMap(self, x, y, button, shift): #start_time = time.time() #only used to compare run-times of different versions of the script arcpy.env.overwriteOutput = True rdsmall_dataSource = r"GDB_HMS.HMSADMIN.rdsmall_arc" mxd = arcpy.mapping.MapDocument('current') flag_rdsmall = 0 #flag_rdsmall is used to flag the first occurence of a layer having the desired dataSource in TOC for lyr in arcpy.mapping.ListLayers(mxd): if lyr.supports("dataSource"): if str(lyr.dataSource).endswith(rdsmall_dataSource) and not flag_rdsmall: rdsmall_lyr = lyr flag_rdsmall = 1 point = arcpy.Point() point.X = x point.Y = y pointGeometry = arcpy.PointGeometry(point) arcpy.SelectLayerByLocation_management(rdsmall_lyr, "WITHIN_A_DISTANCE", pointGeometry, "20 Meters", "NEW_SELECTION") #print time.time() - start_time, "seconds" class CreateShieldClass(object): """Implementation for ShieldToolAddinB_addin.tool (Tool)""" def __init__(self): self.enabled = True self.cursor = 3 self.shape = "LINE" def onLine(self, line_geometry): #start_time = time.time() #only used to compare rough run-times of different versions of the script arcpy.env.overwriteOutput = True #Hard-wiring the exact feature classes that will be edited with shield tool. shield_points_dataSource = r"GDB_HMS.HMSADMIN.hms_shields_points" shield_arcs_dataSource = r"GDB_HMS.HMSADMIN.hms_shields_arcs" rdsmall_dataSource = r"GDB_HMS.HMSADMIN.rdsmall_arc" mxd = arcpy.mapping.MapDocument('current') #for new shields to appear in current mxd, this script must refer to layers in the current mxd lyrs = arcpy.mapping.ListLayers(mxd) flag_points = 0 flag_arcs = 0 flag_rdsmall = 0 for lyr in arcpy.mapping.ListLayers(mxd): if lyr.supports("dataSource"): if str(lyr.dataSource).endswith(shield_points_dataSource) and flag_points == 0: shield_points_lyr = lyr flag_points = 1 if str(lyr.dataSource).endswith(shield_arcs_dataSource) and flag_arcs == 0: shield_arcs_lyr = lyr flag_arcs = 1 if str(lyr.dataSource).endswith(rdsmall_dataSource) and flag_rdsmall == 0: rdsmall_lyr = lyr flag_rdsmall = 1 if not (shield_points_lyr and shield_arcs_lyr and rdsmall_lyr): print "Must have 3 layers in this mxd: shield points, shield arcs, and rdsmall" #only allow shield creation if a single road arc is selected num_road_arcs = int(arcpy.GetCount_management(rdsmall_lyr).getOutput(0)) print "%s rdsmall arc(s) selected" %num_road_arcs if num_road_arcs == 1: workspace = rdsmall_lyr.workspacePath #(refers to .sde file in DatabaseConnections) arcpy.env.workspace = workspace edit = arcpy.da.Editor(workspace) edit.startEditing(True, True) #with undo, multiuser mode #identify maximum SHI_GRP_ID value currently used in shields feature class max_id = sorted(arcpy.da.SearchCursor(shield_points_lyr.dataSource, "SHI_GRP_ID"), reverse = 1)[0][0] #print max_id + 1 #collect selected road arc attributes rdsmall_values = sorted(arcpy.da.SearchCursor(rdsmall_lyr, ["UA", "FAID_S", "CTCODE", "RTNUMBER", "AOTCLASS"])) #uncomment the last line of this block of code to turn off the truncation of the leader line #determine line coordinates, slope, and truncated line geometry based on first and last point. a_pt = line_geometry.firstPoint b_pt = line_geometry.lastPoint slope = (b_pt.Y - a_pt.Y)/(b_pt.X - a_pt.X) theta = math.atan(slope) #fixed_length = 150. fixed_length = 185. if b_pt.X - a_pt.X < 0: x = fixed_length * math.cos(theta) * -1 y = fixed_length * math.sin(theta) * -1 else: x = fixed_length * math.cos(theta) y = fixed_length * math.sin(theta) point = arcpy.Point() point.X = a_pt.X + x point.Y = a_pt.Y + y array = arcpy.Array() array.add(line_geometry.firstPoint) array.add(point) fixed_line = arcpy.Polyline(array) #To remove the constraint of fixed shield arc lengths, uncomment the following line: fixed_line = line_geometry #this line reverts the fixed_line to the original input geometry #create shield point feature and populate attributes new_points_Cur = arcpy.da.InsertCursor(shield_points_lyr, ["SHAPE@XY", "UA", "FAID_S", "CTCODE", "RTNUMBER", "AOTCLASS", "SHI_GRP_ID", "INSET", "ISVISIBLE", "SUBINSET"]) test = (fixed_line.firstPoint,) + tuple(rdsmall_values) + (max_id + 1,) test_tuple = ((test[0].X, test[0].Y), test[1][0], test[1][1], str(test[1][2]), str(test[1][3]), test[1][4], test[2], "N", 1, "N") #test_tuple = ((test[0].X, test[0].Y), rdsmall_values[0], str(rdsmall_values[2]), str(rdsmall_values[3]), rdsmall_values[4], max_id + 1, "N", 1, "N") edit.startOperation() new_points_Cur.insertRow(test_tuple) edit.stopOperation() del new_points_Cur #create shield arc feature and populate SHI_GRP_ID, CTCODE, UA, INSET, ISVISIBLE, and SUBINSET fields new_arc_Cur = arcpy.da.InsertCursor(shield_arcs_lyr.dataSource, ["SHAPE@", "SHI_GRP_ID", "CTCODE", "UA", "INSET", "ISVISIBLE", "SUBINSET"]) edit.startOperation() new_arc_Cur.insertRow([fixed_line, max_id + 1, str(rdsmall_values[0][2]), rdsmall_values[0][0], "N", 1, "N"]) edit.stopOperation() del new_arc_Cur edit.stopEditing(True) #save changes (doesn't work if an editing session is open in ArcMap, but ) arcpy.SelectLayerByAttribute_management(rdsmall_lyr, "CLEAR_SELECTION") arcpy.RefreshActiveView() else: print "Shield Not Created" print "Must select a single arc from rdsmall" #print time.time() - start_time, "seconds"
... View more
06-26-2014
07:12 AM
|
0
|
0
|
32
|
POST
|
Hi Jim, The paths do help. It isn't clear to me, however, exactly what information is in your lookup table or how you want to use it. For example, does the lookup table identify which fips codes belong to which state? If so, how? Is every fips code listed in one field, with another field providing the name of the state the code belongs to? Will each shape file correspond to a single or multiple fips codes? I would need to understand these kinds of relationships between relevant fields, and to know the names of the fields, in order to incorporate the lookup table into the script. Kerry
... View more
06-24-2014
08:45 AM
|
0
|
0
|
16
|
POST
|
Hi Jim, Here's a little script that might help. You would need to edit 4 lines (indicated with comments) to refer to your SDE data, though. The script could be run from either the ArcMap Python window, or a Python IDE window. If you want to re-run the script, you'd have to delete the shapefiles manually because they can't be overwritten. If the fips code does not specify the state, you'd need to specify the state using an additional field... which would require about 4 more lines of code. import arcpy #Next 4 lines must be edited to correspond to your data and directories. fc = r"Database Connections\GDB_HMS.sde\GDB_HMS.HMSADMIN.rdsmall_arc" #original dataset path shortName = "rdsmall_arc" #a simplified dataset name (without "." characters found in our SDE dataset names) fipsField = "FIPS" #name of the field that is used to subdivide dataset outputFolder = r"V:\Projects\Shared\kalley\Documentation\rdsmall" #folder path where shape files should go fipsList = sorted(set([code[0] for code in arcpy.da.SearchCursor(fc, fipsField)])) #creates a sorted list of unique fips codes in dataset for fipsCode in fipsList: outputName = "{0}_{1}".format(shortName, str(fipsCode)) #new filename will look like shortName_fipsCode.shp query = "{0} = {1}".format(fipsField, str(fipsCode)) #assumes fipsCode is an integer arcpy.FeatureClassToFeatureClass_conversion(fc, outputFolder, outputName, query) arcpy.AddMessage("Created {0}\n".format(outputName))
... View more
06-23-2014
01:56 PM
|
0
|
0
|
16
|
POST
|
I don't know of a way to make a layer un-selectable through Python scripts, which I'm guessing is intentional because layers are always selectable from a script's perspective. (For example, arcpy.SelectLayerByLocation_management works on a layer even if it is not selectable in ArcMap, and the layer remains un-selectable even after running arcpy.SelectLayerByLocation_management via script or toolbox.) If you are updating a layer from a layer file, just make sure the layer file (layer.lyr) you are referencing was created from a layer that was not selectable, then it should preserve that property when brought into your map document. Kerry
... View more
06-23-2014
12:43 PM
|
0
|
0
|
32
|
POST
|
The Python/arcpy field class does not have a defaultValue property! Is that an oversight, or a deliberate feature of arcpy's field class? I know the IField interface (ArcObjects) will provide the defaultValue, but using comtypes is a hassle. Any other way of getting the default field value using Python? Thanks, Kerry
... View more
06-23-2014
11:56 AM
|
1
|
2
|
1108
|
POST
|
Hi there, this results in only displaying field 2... Any other suggestions? thank you very much for your help! JB What are the empty field values in your table? Are they <Null>? Spaces? Empty? If you're not absolutely sure, you can use a definition query builder to view the Unique Values. The Show Values button on the Label Expression window has a view that I find less informative. I'm guessing you don't have empty fields ("") because that is the condition for displaying field 1 in Matt's code. You might find (for example) that you have Null values, single spaces (" "), double spaces (" "), or possibly a mixture of empty-looking values. (Note that there should be two spaces between the last pair of quotes... the text formatting stripped my second space!)
... View more
03-19-2014
06:21 AM
|
0
|
0
|
287
|
POST
|
"A label expression is limited to a single line of code unless you check the Advanced box on the Label Expression dialog box." (From the Building Label Expressions help page) good luck!
... View more
03-18-2014
07:14 PM
|
0
|
0
|
287
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|