Hot answers tagged

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


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:{} ...


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


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

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


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


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


Only top voted, non community-wiki answers of a minimum length are eligible