New answers tagged

3

You have features in your feature class without geometry. "SHAPE@XY" returns (None, None) when a feature has no geometry. As @MarceloVilla suggested, you can print out the OBJECTID of the features without geometry if you're interested knowing these. with arcpy.da.UpdateCursor(FeatClass, ["SHAPE@XY", "OID@"]) as cursor: for (x, y), oid in curs: ...


0

This script worked for me: (inspired by previous answers and from examples here: https://pro.arcgis.com/en/pro-app/arcpy/get-started/writing-geometries.htm) Get the extent of the raster Save extent values as points (coordinates in [x,y]) Create new feature class to store new geometry Insert cursor as geometry to new feature class Script: # Create ...


1

Off course after I've asked the question I know the answer. After using Searchcursor I still have to iterate through it. Changed the last line in the else to this and it works: with arcpy.da.SearchCursor(inl, '*', where_clause=ftext) as feats: featureIterator = [] for f in feats: ...


1

You'll need to create a variable to track your condition. In the examples, I used "failure", which is initialized to False--indicating that no rows are missing a map unit. Later, during the cursor, if any row is missing a map unit, you update the failure variable to True. Then, after your cursor iteration, you can check whether failure is True. If you want ...


3

sys.exit (1) ends the script. Get rid of this line. with arcpy.da.SearchCursor(MapUnitPolys, ['SHAPE@', 'MapUnit', 'OBJECTID']) as cursor: for row in cursor: #arcpy.AddMessage(str(row[1])) # Does this Polygon have a map unit if row[1] == "" or row[1] is None or row[1] is 'NULL': arcpy.AddMessage('Polygon OBJECT ID:{} ...


0

I wanted to insert a new answer rather than editing my previous one as this comes with a new solution that should handle the problematic of updating the geometries of polygons with more than one inner ring as well. The OP in the comments pointed out that my other answer didn't work for the case "two donuts in one polygon". Trying myself I was susprised but ...


5

Use a dictionary: The main operations on a dictionary are storing a value with some key and extracting the value given the key. d = {1:"Lightning", 2:"Equipent use", ... } with arcpy.da.UpdateCursor(fc, ["CAUSE_TEXT", "CAUSE"]) as cursor: for row in cursor: if row[1] in d: #Check if value of row[1] exists in dictionary row[0] = ...


1

Your case is very interesting to me as it reveals that explode_to_points=True is indeed "deconstruct(ing) a feature into its individual points or vertices." (as stated in the arcpy.da.UpdateCursor help). HOWEVER as in a Polygon, the first and last vertex of a feature (and all its parts) are coincidents, it seems that updating the geometry of the first ...


1

I suggest you to give the explode_to_points if the UpdateCursror a try in this case. If you set it to True, each row of your cursor will be each vertex of your polygons. I did not tested it, but you can try something like the below: import arcpy fc = r"C:\Scratch\fcTest.shp" # Get Spatial Reference of dataset desc = arcpy.Describe(fc) sr = desc....


2

Your script is printing that both values are in the SDE because your query is always returning at least one feature (and consequently one row) and thus your flag is always True. Check the following function to check if exists in a table or not: def value_exists(fc, field, where_clause): with arcpy.da.SearchCursor(fc, field, where_clause) as cursor: ...


1

The Reading geometries documentation shows the proper processing procedure for sub-parts in polygons: for row in arcpy.da.SearchCursor(infc, ["OID@", "SHAPE@"]): # Print the current multipoint's ID # print("Feature {}:".format(row[0])) partnum = 0 # Step through each part of the feature # for part in row[1]: # Print the ...


0

Use pandas library which comes with ArcGIS >=10.4. Create a pandas dataframe using da.SearchCursor. Group by year and quarter (with year ending with february). I had to convert the dates from object (~strings) to datetime and drop na with my test data, these lines are commented below. import arcpy import pandas as pd fc = r"X:\data.gdb\somefc" date_field = ...


Top 50 recent answers are included