Questions tagged [arcpy]

A site-package created by Esri to expose ArcGIS Desktop (ArcMap and ArcGIS Pro) geoprocessing, mapping, etc, to Python.

Filter by
Sorted by
Tagged with
70
votes
6answers
11k views

When to use ModelBuilder over Python scripting and vice versa?

I am new to Python scripting in ArcGIS but not new to ModelBuilder. I would like to know the benefits of Python vs ModelBuilder. When should we write Python script for GIS automation rather than ...
49
votes
5answers
9k views

Debugging ArcPy scripts?

I have written many Python scripts using ArcPy in ArcGIS 10, and so far my only means of debugging is restricted to printing messages to the geoprocessing results window using arcpy.AddMessage(). ...
38
votes
4answers
6k views

Performance of ArcGISScripting and large spatial data sets

I am currently writing a python script using the arcgisscripting module to process a reasonably large data set (~10,000 records in total) normalised over a small number of tables, 8 in total. The ...
37
votes
6answers
27k views

Learning ArcPy?

Where can I start to learn ArcPy?
35
votes
2answers
17k views

Fastest way to count the number of features in a feature class?

With the introduction of the Data Access module in arcpy (30x faster search cursors), I want to know if counting features matching sql criteria is faster than the traditional MakeTableView + GetCount ...
34
votes
2answers
2k views

Streamlining Python Code for Big Data

I have Python code which is designed to take point shapefiles through the following workflow: Merge points Integrate points, such that any points within 1 m of each other become one point Create ...
33
votes
3answers
23k views

What is the proper syntax and usage for ArcGIS “in_memory” workspace?

I am unclear how best to use the in_memory workspace in ArcGIS. The best resource I have found on the subject is from ESRI on Using in-memory workspace. Unfortunately, the help section is not very ...
33
votes
6answers
2k views

Sharing Open Source Python/ArcPy Code and Models for ArcGIS Desktop?

I will be writing scripts for ArcGIS Desktop in Python with ArcPy. Is there a community or open source project where code and models can be shared?
30
votes
6answers
18k views

Ways to Speed Up Python Scripts Running As ArcGIS Tools [closed]

This is a pretty general question. I just wondering what tips and tricks GIS programmers have used to speed up arcpy scripts that you import into the toolbox and run. I work most everyday writing ...
28
votes
6answers
3k views

How to buffer raster pixels by their values?

The pixels to the left represent tree locations and their associated crown radii (i.e. pixel values ranging from 2 - 5). I would like to buffer these raster pixels by their crown radius value. The ...
27
votes
6answers
25k views

Defining projections for multiple shapefiles in ArcMap?

I have over 100 shape files that don't have .prj file and thus when I bring them into ArcMap 10 they show the coordinate system as unknown. I know all of the shape files coordinate system is GCS WGS ...
27
votes
4answers
13k views

Making separate Python installation that can call ArcPy?

I see a lot of Q&As asking how you can create a separate Python installation (e.g. the Anaconda or Python XY distribution) that can use arcpy, while not 'breaking' the original ArcGIS python ...
26
votes
5answers
7k views

Using ArcGIS functionality in Python without running ArcMap (e.g. separate editor/environment)?

I'm trying to take the next step in programming ArcGIS with Python and see if its actually possible to run my script/code without having to load ArcMap and paste them into the Python window. I imagine ...
25
votes
3answers
7k views

Why learn/use Python Toolboxes over Python Script Tools? [closed]

I've written a few Python Toolboxes (which are new at ArcGIS 10.1), but am yet to decide whether/when I should write them rather than Python Script Tools in a standard toolbox. I thought the Online ...
23
votes
4answers
35k views

Listing all feature classes in File Geodatabase, including within feature datasets?

From python how can I build a list of all feature classes in a file geodatabase (*.gdb), including inside feature datasets? The standard example only lists feature classes at the top level of the ...
23
votes
3answers
5k views

Exporting table to XYZ ASCII file via ArcPy?

I'm looking for a way to export an ArcGIS table (created with the Sample tool) to a text file via ArcPy. I can do this in ArcGIS via the context menu by right-clicking the table, but have not found ...
23
votes
4answers
27k views

Running Python scripts (with parameters) within another Python script with ArcPy?

A common coding pattern used in AML was to run an AML (with parameters) inside another AML. An application that I'm currently developing would benefit from being able to run a Python script (with ...
22
votes
6answers
29k views

Getting ArcPy to work with Anaconda?

I am trying to follow the step-by-step directions in the answer to "how to separate Python installation with ArcGIS" but cannot find the path file, DTBGGP64.pth, in C:\Python27\ArcGIS10.2\Lib\site-...
22
votes
3answers
5k views

Do ArcGIS SpatialReference object factory codes correspond with EPSG numbers?

I've got a project where I'm reading in geometry objects from text files to put them in ArcSDE. These geometry objects have an associated EPSG code, and I'm looking for a way to ensure they're in the ...
22
votes
1answer
6k views

How to get size of file geodatabase feature class on disk?

Is there a simple way to determine the amount of hard drive space a feature class takes up? I feel like I'm missing something simple, but I don't recall a method that does so. You would think that ...
22
votes
3answers
3k views

Running Python Script when opening MXD?

Can anyone tell me how to accomplish this? I want a Python script to run on opening the MXD which would pull an excel worksheet into a GDB and refresh the map. I only want this to happen in this ...
21
votes
5answers
21k views

Including variable in where clause of arcpy.Select_analysis()?

I am trying to loop through a shapefile, selecting each feature in turn and copying it to a temporary shapefile to by included in a union analysis. I'm using a cursor to find the ID name for each ...
21
votes
2answers
4k views

Using ArcPy to determine ArcMap document version?

Is there a way with ArcPy to identify the version of a Map Document (MXD). I am working on a solution to inventory our MXD's and would like to know if a document is 8.1, 9.2, 10.0, etc. I am ...
21
votes
3answers
8k views

Adding new group layer with ArcPy?

Does anyone now how to add a group layer with Python in ArcGIS Desktop 10? I can use arcpy.mapping.AddLayer but surely this is only for an actual layer as opposed to a group layer. so far I have ...
20
votes
6answers
8k views

Documentation for ArcPy site-package?

Has anyone found any informative documentation about Esri's ArcPy Python module?
20
votes
2answers
32k views

Adding shapefile or feature class as layer in ArcGIS Desktop using Python/ArcPy?

I am trying to automate various tasks in ArcGIS Desktop (using ArcMap generally) with Python, and I keep needing a way to add a shapefile to the current map. (And then do stuff to it, but that's ...
20
votes
6answers
6k views

How to make a GIS inventory?

My office will be seeing a big change in its GIS section. This section has been operational since the 1980's and has a huge collection of GIS data (i.e., shapefiles, raster files, data, etc) but never ...
20
votes
6answers
20k views

Obtaining extent of each polygon in shapefile using ArcPy?

In ArcGIS 10 and Python I want to get the extent (xmax, ymax, xmin, ymin) info of each of the polygons in a shapefile. I can get the extent of the whole shapefile using file=r"D:\SCRATCH\ARCGIS\...
20
votes
8answers
40k views

How to manually break statement execution in Python window of ArcMap?

How does one break the execution of a long-running process in the python console of ArcMap? For example, how do you break a long iteration like the one below once it is started? for i in range(1, 50)...
20
votes
1answer
2k views

ArcGIS 10.1 Python AddIn Using Multiprocessing crashes ArcMap?

I would like to run a multiprocessing task from a python add-in tool. My issue is that the process keeps failing. Basically crashes ArcMap. Here is my basic code: def function(startOID, endOID, fc)...
20
votes
1answer
3k views

How to Split a Concave Polygon Into Convex Polygons in Arcpy?

I'm looking for a tool or algorithm to detect concave polygons and split them into convex polygons. Like explained in the picture, the blue polygon is split into A and B polygons I'm using Arcpy ...
19
votes
7answers
4k views

Code-completing/auto-completing ArcPy scripts using Notepad++ (external editor)?

I have been scripting in Python for ArcGIS 10, and so far I have just been using Notepad++. I like how the Python command line interface code-completes arcpy functionality for you, showing you your ...
19
votes
2answers
22k views

Getting list of selected features in ArcGIS for Desktop using Python code?

I have a question regarding selections in ArcGIS for Desktop. Assumed I have one layer in ArcMap and I have selected two of five features. Is it possible to get a list of all selected features by ...
19
votes
4answers
17k views

Using ArcPy to zoom to selected feature?

Is there a way to zoom to the extent of a selected feature using the ArcPy module in ArcGIS Desktop 10.
19
votes
3answers
9k views

Finding angle between intersecting features in two feature classes using ArcGIS Desktop and Python? [closed]

I have two intersecting line featureclasses. I want to find the angle at each point of intersection using ArcGIS 10 and Python. Can anyone help?
18
votes
7answers
11k views

Listing feature classes with active domains?

I have an Esri file geodatabase with attribute domains defined. I need to delete some of the attribute domains but can't because "The domain is used by an attribute rule.". How might I discover which ...
18
votes
5answers
5k views

Comparing two geometries in ArcPy?

I am trying to compare two separate feature classes to identify differences between them (sort of a diff function). My basic workflow: I extract the geometries using a SearchCursor Save the ...
18
votes
2answers
2k views

How is the data access cursor performance so enhanced compared to previous versions?

The data access module was introduced with ArcGIS version 10.1. ESRI describes the data access module as follows (source): The data access module, arcpy.da, is a Python module for working with ...
17
votes
2answers
8k views

Casting ArcPy result object from arcpy.GetCount_management() as integer instead?

I am trying to get a number by counting how many points are in a shapefile. And this works, except I then am running into trouble using that number somewhere else. Eventually, I'll be using that count ...
17
votes
1answer
2k views

Is there ArcPy tool for polygon resizing like Scale tool of Advanced Editing toolbar in ArcMap?

I am writing a python script for ArcGIS 10.3. I know about Scale tool in ArcGIS interface but I can't find such arcpy command. It exists? As you can see on the picture the Scale tool works different ...
17
votes
1answer
5k views

Guidelines for organizing Python Toolboxes (.pyt) in ArcGIS

For one of my tasks I need to create a Toolbox with three tools (python scripts). Instead of ordinary tbx I've decided to write it as Python Toolbox (pyt). Everything is clear except the "good" way ...
17
votes
1answer
6k views

Self terminating Python script in ArcMap?

I have tried sys.exit, but it doesn't seem to work in ArcMap 10. Anyone know how to do it?
16
votes
3answers
6k views

Using ArcPy to get layer symbology?

Since ArcGIS 10 comes with the ArcPy package, I'm wondering it is possible to use ArcPy functions to get Symbology (i.e color, width...) of a layer?
16
votes
7answers
8k views

Bulk field renaming in file geodatabase? [duplicate]

I have a file geodatabase with several hundred feature classes in it. Some feature classes have a field that got named incorrectly, and it got named "SCHEMA_FEATURECLASS_ENTITY" instead of just ...
16
votes
5answers
2k views

How are people using Python data structures and classes in ArcPy?

This question may expose my ignorance on programming but I'm curious about how people are using different python data structures within ArcPy. This page lists the data structures in Python. I ...
16
votes
1answer
2k views

How can I utilize NumPy arrays to optimize big data geoprocessing?

I'm interested in learning how to utilize NumPy arrays to optimize geoprocessing. Much of my work involves "big data", where geoprocessing often takes days to accomplish certain tasks. Needless to ...
15
votes
3answers
4k views

Porting Avenue code for Producing Building Shadows to ArcPy/Python for ArcGIS Desktop? [duplicate]

Whuber provided an answer at Producing building shadows using ArcGIS Desktop? which required using Avenue code. Any idea how to make it work in ArcGIS Desktop 10?
15
votes
2answers
3k views

Calling arcpy/python from .NET?

Are there any available examples that show how python can be integrated into a .NET ArcGIS Addin or Extension? I have a series of python scripts that I would like to call from form events (e.g. button ...
15
votes
4answers
2k views

Re-compiling Python Addin after editing script?

I have been developing a few python addins and I'm just wondering what is the best way to re-compile the addin anytime I edit the script. Currently, if I make an edit to the script, it seems like I ...
15
votes
2answers
2k views

Refreshing imported modules in ArcGIS Python Toolbox?

When using a python toolbox (.pyt) in ArcMap, I'll typically follow a pattern where the .pyt file itself is simply a wrapper to collect input arguments and define the tools themselves. Supporting ...