New answers tagged

0 votes

Name output feature classes with feature names with ArcPy

You are appending the currentDate after the .shp file extension. Change your loop to something similar to this: for fc in fcList currentDate = str(now.month) + str(now.day) + str(now.year) ...
0 votes

ArcPy command to get the number of features in map layer

The reason your code didn't work is that you provided the layer source (lyr.dataSource), not the layer (lyr). Functions which accept layers will honor a source, by converting it to a layer, with ...
  • 19.1k
1 vote

ArcPy command to get the number of features in map layer

arcpy.GetCount_management(lyr) It will honour definition queries and return a count of features in the layer. If there are any selected features, it will return a count of the selected features only. ...
  • 54.2k
1 vote

ArcPy SelectLayerByLocation cannot retrieve selected features

The program is mostly correct. It needs two updates to make it work: First, change with ap.da.SearchCursor(Lyr2, ['SHAPE@', 'Name']) as cur: to with ap.da.UpdateCursor(Lyr2, ['SHAPE@', 'Name']) as cur:...
  • 1,087
0 votes

Deleting geometries in feature layer based on unique field values

Vince makes several good points. First, stop using the legacy/original Cursor - ArcGIS Pro and start using the newer (not really new as they have been around since 10.1 but still newer than original) ...
  • 744
0 votes

ESRI GEodatabase - LRS Metadata. Where to find it using SQL?

The information that is required was moved to the GDB_ITEMS table, it can be fetched with a cursor: identifier = None with arcpy.da.SearchCursor(os.path.join(arcpy.env.workspace,"sde....
  • 734
0 votes

Trying to use Python to copy feature datasets with many feature classes from an enterprise database to a file GDB

Your arcpy.ListFeatureClasses() is not specifying which feature dataset to use. Your for fd loop never uses fd for anything. So it is copying across the feature classes that are not in ANY feature ...
1 vote
Accepted

Automate exporting species distribution maps with ArcPy by iterating through species fields in graduated symbology layer

This might work. Keep a copy of the original layer with the preferred symbology settings. Turn it off, and set a copy that is turned on for the layout. Then use the ApplySymbologyFromLayer tool to ...
  • 1,991
1 vote

RuntimeError: [blank] when trying to add a standalone table to a map with python

You can use Make Table View: Creates a table view from an input table or feature class The view will be added to the map
  • 55.4k
0 votes

Deleting geometries in feature layer based on unique field values

This is how I might tackle it as a first go using a dictionary to keep track of the parcels and building sizes. parcels = {} with arcpy.da.SearchCursor(buildings, ["PARCELID","...
  • 1,991
0 votes

Summarize Within 100014 error no luck with Esri help article

According to the documentation of the arcpy.analysis.SummarizeWithin() function: arcpy.analysis.SummarizeWithin( in_polygons, in_sum_features, out_feature_class, {keep_all_polygons}, ...
  • 7,063
0 votes

While trying to insert a layer to an existing .mxd, I get an AssertionError, and can't figure out why

You might check that new_layer or ref_layer are indeed raster layers. Or this might work. new_raster = arcpy.management.MakeRasterLayer(raster, "GWS_30D.tif").getOutput(0) new_layer = arcpy....
  • 1,991
0 votes
Accepted

Save CIMTableFrameField to JSON with Arcpy

I solved my issue by saving a layout file with all the table frames and fields I want to show, then into my python script: calculate statistics and create results layers import the layout file to my ...
0 votes
Accepted

Table to Excel For loop keeps producing lock file in directory using ArcPy

The update cursor will lock the dbf file as you are inside it. One option is to just keep track of what you want to save out as and then loop through it at the end. Something like this. out_files =...
  • 1,991
2 votes
Accepted

Calling table frame layout element from Python Toolbox using ArcPy

I believe you are going to have to use the CIM access to reach into the table frame structure. Look at the TableFrame examples in the ArcGIS Pro Python CIM Samples.
2 votes
Accepted

A Python Script that runs without issue in ArcGIS Pro fails in PyCharm

Your issue comes from the Delete line. In your script at lines 7-11 you have defined variables Del_Address, Del_Zoning, … while at the the delete function you are passing in strings 'Del_Address', '...
2 votes

A Python Script that runs without issue in ArcGIS Pro fails in PyCharm

Looks like you should use arcpy.env.overwriteOutput = True at the top of your script. In the Pro app it's pulling this setting from your preferences, outside of the app it's not.
2 votes
Accepted

"NameError: name 'SetNull' is not defined" error in ArcPy script?

As commented by Vince, you either need to include the arcpy.sa before your SetNull, or do a wildcard import. Explicit reference: import arcpy ... output_raster = arcpy.sa.SetNull(raster < 0.1, ...
  • 29.3k
1 vote

Change Symbology of layers from within ArcMap

My answer to similar question Changing color of symbol in UniqueValuesSymbology object using ArcPy? : Current answer for ArcMAP 10.8 (may be some previous versions too) is "yes, it's possible&...
0 votes

Changing color of symbol in UniqueValuesSymbology object using ArcPy?

Current answer for ArcMAP 10.8 (may be some previous versions too) is "yes, it's possible". You can use a Layer method .updateLayerFromJSON Core part of solution is to create JSON ...
4 votes
Accepted

Using Notepad++ to write Python scripts for ArcGIS Pro

From the documentation: C:\Program Files\ArcGIS\Pro\bin\Python\scripts\propy.bat my_script.py But you could also switch to a code editor/IDE that understands conda environments like VS Code or ...
  • 54.2k
1 vote
Accepted

Using ArcPy to overwrite one SDE feature class with another SDE feature class (from different SDE)

I ended up solving the problem. The feature class in question participated in a topology, which creates a lock on that feature class that is not removed by arcpy.DisconnectUser. Removing it from the ...
-1 votes

Using ArcPy with ArcGIS Pro .setExtent()

I'd recommend first confirming that your extent object is honoring the layer definition query. Curious if you were able to resolve this? I'm a having a similar issues after upgrading from 2.8 to 2.9. ...
0 votes

Loop through raster names in two folders, perform Con (Spatial Analyst tool) if the dates match

I have managed to gather the code with some additional help.Here is the code. import arcpy, os from arcpy.sa import * from arcpy import env # Set the current workspace location_a = "D:/datasets/...
0 votes

Loop through raster names in two folders, perform Con (Spatial Analyst tool) if the dates match

Looping through both folders is pretty inefficient. I would propose the following logic (which only uses a single loop): For each image in folder A, extract the date into a variable Construct the ...
  • 8,158
0 votes

Loop through raster names in two folders, perform Con (Spatial Analyst tool) if the dates match

After you spit your file names and extract the dates you have your list indices mixed up. snow_values = snow_name[2] for location_A should be snow_values = snow_name[0] and snow_values = snow_name[0] ...
  • 7,527

Top 50 recent answers are included