Emil Brundage
  • Member for 7 years, 5 months
  • Last seen this week
How to randomly subset X% of selected points?
Accepted answer
30 votes

Here's a python function that will select random features in a layer based on percent, ignoring current selection: def SelectRandomByPercent (layer, percent): #layer variable is the layer name in ...

View answer
Retrieving size of shapefile in ArcPy?
Accepted answer
14 votes

Iterate through all files in the shapefile directory with a valid shapefile extension and add their sizes together. The os module is helpful for this task. Here's a function that returns the size of ...

View answer
how to get max and min from a raster using arcpy?
13 votes

Create a raster object using the full path to your raster. Raster objects have the properties minimum and maximum. >>> rastFullPath = r"C:\Rasters\rasters.gdb\Slope" >>> rast = ...

View answer
How do I count occurrences of unique field values?
Accepted answer
10 votes

@nmpeterson's answer is a good one. If you don't want to create a table you can get this information as a SearchCursor. You can do it by making use of a dictionary to tally counts: import arcpy fc = ...

View answer
Using UpdateCursor for joined field in ArcPy?
9 votes

Instead of messing with joins, which is a bit confusing and on the slow side, use a python dictionary and an update cursor. Iterate the table you would join, and store the join field values in your ...

View answer
ArcGIS Python Script Tool Field Name Drop Down?
Accepted answer
9 votes

Change the "Obtained from" property for the input to the shapefile parameter.

View answer
Use ArcPy/Python to print out the number of selected features based on different selection criteria
8 votes

Get Count. Returns a Result object, whose first output is the count. Thus to get your count: count = arcpy.GetCount_management ('ParcelBoundaries_DevTest').getOutput (0) For whatever reason the ...

View answer
ArcPy saveACopy method saving copy of MXD to wrong path?
Accepted answer
8 votes

I would set the PATH2 variable this way: PATH2 = r"C:\Users\Daimon Nurse\Desktop\DFMPROJECT" And then try this insead of mxd.saveACopy(PATH2 + zone): newmxd = os.path.join (PATH2, zone + ".mxd") ...

View answer
Using if statement with ArcPy and GetCount?
7 votes

All geoprocessing tools produce a Results object. You want the first output of your GetCount results object. The output will be a string, so you also must convert the string to an integer. if int (...

View answer
Finding distance from center of polygon to its furthest edge/point?
7 votes

Your best bet is to convert feature vertices to points, and then iterate through each midpoint and perform a point distance on its correlating polygon vertices. This will be a slow process, but I'm ...

View answer
SQL MAX Subquery in arcpy.MakeFeatureLayer_management
7 votes

An sql where clause can't incorporate sql functionality such as MAX or MIN because your input can only be what proceeds WHERE in an sql. Note how in the Select By Attribute window the first part of ...

View answer
UpdateCursor Not Working
Accepted answer
7 votes

As Vince mentioned in the comments, 'The "with" syntax is a Data Access cursor construct'. You have a couple options: Using the old version of update cursor: cursor = arcpy.UpdateCursor(i) for row ...

View answer
calculate the population inside a buffer with census data
Accepted answer
7 votes

This can be accomplished with an Intersect, followed by a Field Calculate, and then finally a Summary Statistics. Make sure that your buffer feature class has a unique ID field. Before getting ...

View answer
Merge shapefiles in folders and subfolders with arcpy
Accepted answer
7 votes

So currently you're using the input of your shape file name but not indicating a directory. The full path is needed for the merge to work. Or you can set your environment's workspace each time you ...

View answer
CopyFeatures management creates long name
Accepted answer
6 votes

Turn off Qualified Field Names before joining. arcpy.env.qualifiedFieldNames = False Tools that honor the Qualified Field Names environment use this setting to distinguish between qualified or ...

View answer
Creating WHERE clause from list using ArcPy
Accepted answer
6 votes

You're using AND when you should be using OR. A value can't equal all the values in field_names. 5, as an example, can't equal 5 AND 7 AND 3 AND 23 AND... I like to make a string out of my list of ...

View answer
Improving poor performance of ArcPy update cursor with ArcSDE and Editor?
6 votes

The nested cursors are slowing you way down. Instead, use a searh cursor to create a dictionary with UIDs as your key and rows as your values. Then use an update cursor to update your second feature ...

View answer
Cutting a circular buffer via Arcpy
Accepted answer
6 votes

Here's a script I put together. The script uses your point and your line feature class, and outputs a new line feature class of line features as desired. The basic steps: Iterate through points ...

View answer
Output the Search Cursor as a string
Accepted answer
6 votes

The issue I see is that you are not assigning your count to a variable. Also, row[] isn't correct syntax. And you're missing a for row in cursor:. And you spell cursor wrong in a spot. And you have a ...

View answer
Getting values of last row in table with ArcPy/SearchCursor?
6 votes

If you're using 10.2, I would first recommend using the data analysis version of the search cursor. Then you can use python's list comprehension to get the last value. Try something like the code ...

View answer
Get list of editable fields while also adding 'SHAPE@' to the end
Accepted answer
5 votes

Here's an easy way: fields = arcpy.ListFields('//path/to/layer') flds = [f.name for f in fields if f.editable and f.type != "Geometry"] + ["SHAPE@"]

View answer
Insert Cursor Not Filling XY Field
Accepted answer
5 votes

The token "SHAPE@XY" populates the geometries of the feature. You won't see the results in your output table. If you have fields for X and Y use their names instead of "SHAPE@XY". with arcpy.da....

View answer
Changing name of attribute field in shapefile using ArcPy?
Accepted answer
5 votes

Creating the new field, calculating it, and deleting the old field is the way to go. arcpy.AddField_management (Habitat, "Fox_Mean", "DOUBLE") arcpy.CalculateField_management (Habitat, "Fox_Mean", "[...

View answer
Writing ArcPy Update Cursor "Where Clause" that Refers to its own Rows?
5 votes

Store the relationship between IDs and lat/lons in a python dictionary, generated with a search cursor. Then update your shapefile with an update cursor, reading lat and lons from your dictionary. No ...

View answer
Using Not Equal in ArcPy SetNull
Accepted answer
5 votes

!= is Python syntax for does not equal. <> is sql syntax for the same. Since the expression in question is an sql where clause, you must use the sql syntax, even though it’s within a python ...

View answer
StopIteration: iteration not started error in arcpy.da.UpdateCursor
Accepted answer
5 votes

It looks like you're deleting a row if conditions are met, and then trying to update the same row following, which no longer exists. You can't update a row after it's been deleted. Try: fieldList = [...

View answer
Snap Point to Specific Edge of Polygon
Accepted answer
5 votes

The would be a four step process, involving determining which polygons don't have overlapping sides. Given: Initiate a feature to line on your parcel feature class. Perform a spatial join on the ...

View answer
update cursor inputting the same values
Accepted answer
5 votes

With each row you iterate through integers of the length of tbl (1, 2, 3, 4....) and update each row for each value. The final value will always be the last value in tbl. You'll need to get rid of ...

View answer
Debugging RuntimeError: workspace already in transaction mode from arcpy.da.UpdateCursor and ArcSDE feature classes?
Accepted answer
5 votes

With help I have found my solution, though the reasoning behind it is a bit blurry currently. In my code, creating a version through one SDE connection file and then creating the feature layer to be ...

View answer
Is there a way to turn a data frame off in ArcMap 10.2?
Accepted answer
5 votes

On/off doesn't appear to be an option with a data frame. Moving the frame off the document would work with elementPositionX and elementPositionY. Shrinking the frame to zero is an option as well. ...

View answer
1
2 3 4 5
14