I'm not sure how you were able to get those as the actual field names. I would double check that they aren't field name aliases first. There are definite restrictions on field names. Details can be found at https://desktop.arcgis.com/en/arcmap/latest/manage-data/tables/fundamentals-of-adding-and-deleting-fields.htm#GUID-8E190093-8F8F-4132-AF4F-...
"Old-style" search cursors are an artifact of the past. All supported versions of ArcGIS Desktop and Server offer Data Access cursors, which are faster and more Pythonic (list-oriented).
This is one way to rewrite your code, though there are options for faster runtime execution if you know that the number of IDs to be added is a relatively small ...
The field names contain spaces, which are non standard characters. Those special characters often cause problems, so you should either completely remove the space between X/Y and Coordinates, or replace it with "_" e.g. XCoordinates or X
I'm providing a more recent solution for finding duplicates and adding the count to a new field. It's straight from ESRI's help document: How to identify duplicate or unique values in ArcGIS Pro.
This script will count the number of occurences of a value in a field ("field_in") and write them to a
new field ("field_out")...
I ended up making a polyline out of the points, splitting the polyline at each point, and getting the midpoint of each split polyline. Then I did the Thiessen polygons on the midpoints.
From your code sample, your logic is a bit messed up. I assume that's because you're trying to update your code from ListFeatureClasses to making use of da.Walk.
Your code, right now, is passing the list fc from ListFeatureClasses into the cursor and not using walk.
If all you want to do is iterate over all the feature classes in your defined workspace, you ...
Not 100% sure the Try is helping here. But I would say it doesn't look like you're dealing with the condition where "SRC_NAME" is NOT in lstFields.
I wonder does the below work? Using the else statement to catch these occurrences?
Also combines the calculate and delete together as I assume you only want the delete to occur if the calculation has ...
Hard to understand what you want, this is how I see it (similar to @Michael Stimson.
Create polygon outlines, and generate near table. Add 2 more columns (highlighted in a picture below):
Calculate coordinates of point 'opposite' to nearest with big enough distance. This is how I computed OPP_X:
!FROM_X!-500*math.cos(math.radians( !NEAR_ANGLE! ) )
If possible, the use of a DEM can solve this problem:
If the location of the glacier front is known, so is the altitude. It then can be assumed that all subglacial overdeepenings below that altitude have been exposed.
While this does not use proximity analyses, it should solve the problem in nearly all cases.
See comments in your question, but an alternative approach when you understand that geoprocessing tools return Result objects is this:
resObj = arcpy.CreateFileGDB_management(output_folder, "DEM.gdb")
The correct way to perform shortest path is to use Travelling Salesman algorithm, ( as per FelixIP comment) - which has been implemented in ArcGIS in the Network Analyst extension.
You would need to create some network data first though, this could ...
In answer to comment above, arcpy.RemoveJoin_management raises an exception if there are no joins on the table. Also, ArcPy does not support update cursors on joined tables, even if the field being updated is in the base table. However, you can put arcpy.RemoveJoin_management inside a try block with no action on the exception if there are no joins.
There is a missing part in example 3. self is unknown. As @KHibma stated, it might be a part of a bigger project, probably a Python tool.
I am not able to test right now, but removing selfs and specifying aprx would solve the problem if you don't make a python tool.
Try in this way:
aprx = arcpy.mp.ArcGISProject(r"C:\path\to\file.aprx")...
I used this:
count1 = 0
spatial_Reference = arcpy.Describe(output_splitLine_fibre_duct3).shapeFieldName
with arcpy.da.UpdateCursor(output_splitLine_fibre_duct3, ["Fibre_D", "SHAPE@", "OBJECTID"]) as cursor:
for row in cursor:
count1 = count1+1
feature = row
p1 = feature.positionAlongLine(0.51, True)...
The problem is possibly down to this line
arcpy.env.workspace = "C:\Program Files (x86)\ArcGIS\Desktop10.8\ROBERT FILES\EXTRACTION WORKING FOLDER\ROBERT_WORKING_EXTRACTION.gdb\TransportationGroundCrv_AddFieldTest"
You are using window file path syntax so you need to say its raw text, all you need to do is put an r in front of the string so ...
regex could be used to identify the suffix without having to know what exists ahead of time, so you could do something like this:
# retrieve all field names
field_names = [field.name for field in arcpy.ListFields(fc)]
drop_fields = 
for name in field_names:
# check to see if the field name contains a literal underscore followed by
Edited casting m.listLayers to variable l, just directly used m.listlayers (line 1). Also needed to utilize the sym.updateRenderer function to change the layer symbology. Code below.
for lyr in m.listLayers():
sym = lyr.symbology
if hasattr(sym, 'renderer'):
if sym.renderer.type ...
Loop through a list of field names perhaps:
fields = ['field1', 'field2', 'etc...', 'field12']
fields = [f.name for f in arcpy.ListFields(out_dataset)]
fms = arcpy.FieldMappings()
for field in fields:
#Define field mapping objects
fm = arcpy.FieldMap()
# ***NOTE: 'field1, field2, etc, are actual fields that have different names***
I believe you only need to edit a few lines of code.
The lines I have edited/added are marked with ### at the end of the line. The key method is boundary(), it returns the polygon as a polyline and feeds that into the rest of the existing logic. The update cursor also now updates the geometry as a polygon.
So this code now expects the input to be a polygon ...
This code worked for me
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")
for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
mxd.dataDrivenPages.currentPageID = pageNum
pageName = mxd.dataDrivenPages.pageRow.CoupeID3
Subsequent to this question you have asked what is effectively the same question multiple times as:
https://gis.stackexchange.com/q/378925/115 (since deleted by you)
Converting ArcMap to ArcGlobe code using ArcPy
Get coordinates from a mouse click in ArcGlobe
Link a map to an add-in in ArcGlobe
That question seems to distill to how to obtain 3D coordinates ...
I finally figured it out, and sharing the code in case anyone runs into a similar situation and needs some sample code to get them started
River_Section = "C:\....<path to data>"
Adjacent_MileMarkers = "C:\....<path to data>"
scursor = [row for row in arcpy.da.SearchCursor(Adjacent_MileMarkers, ("...
You're not going to find any inFCs as you're not setting arcpy.env.workspace to a gdb before calling arcpy.ListFeatureClasses() which looks in the current workspace.
outGDB = r"E:\Jamie_Temp\Main_GDB.gdb"
arcpy.env.workspace = ws = r"E:\Jamie_Temp\...
I don't believe that there is any such functionality built into ArcGIS. You could create a tool to do something similar. However, it would not be as neat and simple to use as the QGIS widget.
The tool needs to have 3 parameters (although you could create it with 1 parameter, and have the layer/feature-class and field name hard-coded if you wanted it to be ...
The following worked a treat, thanks to Michael Stimson:
with arcpy.da.UpdateCursor(dataset, ["String", "Year_short","Date_date"]) as updateRows:
for row in updateRows:
string_split = row.split("_")
row = datetime.datetime.strptime(string_split, '%Y%m%d%H%M').year
row = datetime....
At least there is a official convoluted guide now how to do such simple thing in about million steps:
How To: Change query layer SQL expression using Python
In brief you need to get all the info about current query layer (existing query, geodatabase connection information, spatial reference, geometry column name, geometry type, identifier - typically ...
The GP tool framework with ToolValidator.updateMessages function let you provide feedback to the user in a way that standard and familiar (some text accompanied by either warning or error icon). The most relevant help topics i'd recommend is this
ArcGIS Pro/Customizing script tool behavior
Another reason to avoid the use of message box from ToolValidator (...
Inside your try block, change it to the following:
arcpy.env.workspace = "C:/buildings_cabinets"
What did I change?
I used a format string to help dynamically populate your first ...
I've noticed that in the screenshot of your code, you have the following in line 5:
if r"company shared data\" in layer.datasource.lower():
The backslash right before your closing quotation will escape that quotation mark and make it part of the string, so it continues searching for the next non-escaped quotation mark to close the string. This ...
if max in (Con and Ed)
if (max == Con) and (max == Ed)
(The brackets aren't really necessary here, but they do make it more readable, in my opinion.)
(Con and Ed) evaluates to True or False ie, a boolean (or integer - hence the error regarding int being not iterable). Therefore if max in (Con and Ed) is like saying if max in True - it ...
This error is actually documented on the Error: 000824 page.
The solution is to
Add the following code snippet to check-out the extension containing
the tool before calling the tool for use:
The extension names are documented in the arcpy.CheckOutExtension help. For Network ...
Add Field has a list too. I don't think there is a page mapping parameter types. As you are developing an arcpy toolbox, stick to the naming conventions used in the geoprocessing tools as they only accept those. You just have to assume that your users are savvy enough to realise "Text" is "string" and vice versa.
If you want to help your ...
Most Python IDEs can do this. I personally use PyScripter. This link should help you.
I think your indexing is incorrect, you are leaving one field out of the calculation:
field_names = [u'T34TET20160527', u'T34TET20160606', u'T34TET20160616', 'Mean_16']
['T34TET20160527', 'T34TET20160606', 'T34TET20160616']
row[:-2] should be row[:-1]