New answers tagged

1

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-...


1

You've a colon in your "Cell Phone Number:" and "Home Phone Number:" fields and that's throwing a invalid SQL statement.


1

"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 ...


1

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 _Coordinates


0

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. import arcpy ''' 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")...


2

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. import arcpy arcpy.PointsToLine_management(SHP_IN_PTS, templine1) arcpy.SplitLine_management(templine1, templine2) arcpy.AddGeometryAttributes_management(templine2, "...


0

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 ...


1

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 ...


2

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! ) ) ...


0

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.


2

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") arcpy.env.workspace= resObj.getOutput(0)


3

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. https://desktop.arcgis.com/en/arcmap/latest/extensions/network-analyst/algorithms-used-by-network-analyst.htm You would need to create some network data first though, this could ...


0

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. A ...


5

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: import arcpy aprx = arcpy.mp.ArcGISProject(r"C:\path\to\file.aprx")...


2

To get the angles in degrees use this one line code. arcpy.AddGeometryAttributes_management(output_split_merge_fibre_drop_sheath2, Geometry_Properties= "LINE_BEARING")


2

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[1] p1 = feature.positionAlongLine(0.51, True)...


2

There's an open try block with no closing block; removing that should fix the issue


0

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 ...


1

regex could be used to identify the suffix without having to know what exists ahead of time, so you could do something like this: import re # 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 # ...


1

Problem solved. 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(): if lyr.isFeatureLayer: sym = lyr.symbology if hasattr(sym, 'renderer'): if sym.renderer.type ...


5

Loop through a list of field names perhaps: fields = ['field1', 'field2', 'etc...', 'field12'] # Or 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*** ...


2

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 ...


1

This code worked for me mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0] for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1): mxd.dataDrivenPages.currentPageID = pageNum pageName = mxd.dataDrivenPages.pageRow.CoupeID3 arcpy.mapping.ExportToTIFF(mxd, r"C:\...


0

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 ...


1

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 import arcpy River_Section = "C:\....<path to data>" Adjacent_MileMarkers = "C:\....<path to data>" scursor = [row[0] for row in arcpy.da.SearchCursor(Adjacent_MileMarkers, ("...


2

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. Try (untested): #Import modules import arcpy import os #Target GDB outGDB = r"E:\Jamie_Temp\Main_GDB.gdb" #LIBRARIES #Set workspace arcpy.env.workspace = ws = r"E:\Jamie_Temp\...


2

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 ...


1

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[0].split("_") row[1] = datetime.datetime.strptime(string_split[1], '%Y%m%d%H%M').year row[2] = datetime....


1

It sounds like you are using the wrong version of Spyder. I created a tutorial on Installing spyder IDE for ArcPro at GeoNet that you can try to follow to accomplish this.


1

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 ...


0

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 (...


2

Inside your try block, change it to the following: gdb=arcpy.GetParameterAsText(0) arcpy.env.workspace = "C:/buildings_cabinets" arcpy.JSONToFeatures_conversion("C:/buildings_cab/{}.json".format(x), os.path.join("C:/buildings_cab/yu.gdb", x)) What did I change? I used a format string to help dynamically populate your first ...


2

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 ...


2

Change this: if max in (Con and Ed) to this: 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 ...


2

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: import arcpy … arcpy.CheckOutExtension("[Extension name]") The extension names are documented in the arcpy.CheckOutExtension help. For Network ...


3

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 ...


0

This script solved my task: import arcpy import os import xlwt arcpy.env.overwriteOutput = True Dataset_name = arcpy.GetParameterAsText(0) Report_folder = arcpy.GetParameterAsText(1) fields = arcpy.ListFields(Dataset_name) wb = xlwt.Workbook() ws = wb.add_sheet('Test') ws.write(0, 0, "Field") ws.write(0, 1, "Type") row = 1 for field ...


2

Most Python IDEs can do this. I personally use PyScripter. This link should help you. https://community.esri.com/t5/python-documents/run-pyscripter-with-arcgis-pro-s-python-3-x-and-the-arcgis-api/tac-p/920531


2

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'] print(field_names[:-2]) ['T34TET20160527', 'T34TET20160606'] print(field_names[:-1]) ['T34TET20160527', 'T34TET20160606', 'T34TET20160616'] So row[:-2] should be row[:-1] in row[-1]=sum(...


Top 50 recent answers are included