New answers tagged

4

You can iterate twice, first SearchCursor then UpdateCursor. Store values in a Collections.defaultdict(list) then use set to remove duplicates and join to create a string of the list. import arcpy from collections import defaultdict fc = r'C:\data.gdb\featureclass' fields = ['number','category','combined'] d = defaultdict(list) with arcpy.da.SearchCursor(...


0

Another way using collections.defaultdict(list), should work with any number of dates (not just 3 of the same): import arcpy from collections import defaultdict from random import shuffle fc = r'roadpoints' datefield = 'date' randfield = 'random' #Create a Dictionary with date as key and all oids of that date as a list of values d = defaultdict(list) with ...


0

You can do this in a single update cursor. You'll want to use dictionaries to keep track of each date's random pick and where in the count of each date you are. #update table tab = r"path\to\table" #date field dtFld = "Date" #random field ranFld = "Random" import arcpy import random #dictionary to store count of date countDi = {} #dictionary to store ...


0

I had forgotten to add the Header #!/usr/bin/python # -*- coding: utf-8 -*- before I added the script to the toolbox, I added the header after and it didn't affect the encoding until I deleted and then added the script to the toolbox again,


1

Thanks for the nudge, when creating the MWE I found I was reusing a field name by mistake. This was overwriting the results to appear like it did not do anything. The code now does what I tell it. Not sure yet if thats what I want. This code now works: # -*- coding: utf-8 -*- '''---------------------------------------------------------------------...


4

This is a limitation of Shapefiles which cannot store both date and time in the same field. The ESRI documentation at https://pro.arcgis.com/en/pro-app/help/data/tables/date-fields.htm says: When calculating date fields, the field calculator uses Python datetime functions. Some of the functions support datetime yyyy-mm-dd hh:mm:ss AM or PM. However, for ...


0

Use this on a sorted copy of your polygons: import arcpy ## works on sorted table !!! g=arcpy.Geometry() geomList=arcpy.CopyFeatures_management("POLYGONS",g) N=0 with arcpy.da.UpdateCursor("POLYGONS","Shape@") as cursor: for row in cursor: N+=1 if N==len(geomList):break origPgon=row[0] newPgon=origPgon.difference(geomList[...


4

It looks like you’re setting the ‘cumulative’ field to the area of that record only, not the running total. Try replacing: row[1] = AreaValue with: row[1] = running


1

Your code is slow because you have nested cursors so for each row in the updatecursor you are creating a searchcursor and reading rows. You are also using the old searchcursor (not da.) which is slow. Instead first count all occurences once using collections.Counter. The result is is a dictionary with FieldA value as key and count as value, for example: {1:...


0

It looks like you are mixing languages in your script snippet. The first part is written in Python, but then starting at From nd=... you seem to be switching to SQL. If you are dealing with a File Geodatabse (.gdb), you will not be able to use straight SQL to manipulate the data - this can only be done on some circumstances in SDE database, which are ...


Top 50 recent answers are included