Questions tagged [arcpy]
A site-package created by Esri to expose ArcGIS Desktop (ArcMap and ArcGIS Pro) geoprocessing, mapping, etc, to Python.
10,577
questions
9
votes
2
answers
1k
views
Creating summary table of symbology of all datasets in multiple MXDs?
This is related to the following Retain ESRI symbology in Mapinfo TAB . As an initial step (in arcpy) I want to access the symbology of all the datasets and create a document which has the details of ...
9
votes
1
answer
4k
views
What is the difference between data access's "SHAPE@XY" and "SHAPE@TRUECENTROID" tokens?
Data Access Search Cursor.
What, if anything, is the difference between the tokens "SHAPE@XY" and "SHAPE@TRUECENTROID"?
They returned the same coordnates on a test polygon:
>>> cursor = ...
9
votes
1
answer
785
views
Length of line differs depending on query method
We are doing a check of a length attribute against the Shape Length in all our line feature classes (maybe 40 feature classes and 200,000+ features).
In the length attribute we round the Shape Length ...
9
votes
1
answer
4k
views
Prompting for user input during ArcGIS Python script tool execution?
I want to prompt for user input after all parameters have been specified for the script tool. I've seen many forum posts and stackexchange questions about this, and they all conclude that it's ...
9
votes
3
answers
5k
views
python.exe has stopped working
A python script was written about 18 months ago by a person who has now left. It produced the required outputs then. I've been asked to run it again but with different (finer resolution) data inputs....
8
votes
4
answers
29k
views
Python Script to Add Fields to Feature Classes
I have to try to add a field called 'Name' to a bunch of different feature classes using python, and then access the name of the feature class to fill in the field. I have no idea how to even start ...
8
votes
3
answers
10k
views
Deleting feature class features faster using ArcPy?
I have written this script that recurses through all feature classes in a given set of feature datasets and deletes all their features. It appears to do the job but it runs pretty slowly. Is there ...
8
votes
4
answers
2k
views
Performing Feature to Point (no advanced license) using ArcPy?
I have a set of polygons I have calculated the centroids of, but am having trouble finding a way to output these values to a point shapefile. I dabbled with arcpy.MakeXYEvents_management, but it only ...
8
votes
4
answers
413
views
Subset Folder Contents ArcPy
I have about 1500 .txt files within a folder named 3410001ne => 3809962sw. I need to subset about 470 of these files to process with a Python script. Below is the section of code prior to my for ...
8
votes
1
answer
13k
views
Converting ArcGIS date value to string reading in mm/dd/yyyy format using ArcPy?
I am writing an arcpy tool script in ArcGIS 10.0. In a fGDB feature class, I have a Date type field. I gather that the values in the Date field are stored as long integer dates, but they display in ...
8
votes
7
answers
41k
views
Debugging ImportError: No module named arcpy
I have written a script and am trying to run it in Python IDLE 2.7.6.
I first try to import arcpy, but I get an error message saying:
ImportError: No module named arcpy
Why does it not work?
I am ...
8
votes
2
answers
20k
views
How to get sum of table column values into Python variable?
Im creating a script to calculate some new fields in Arcgis10.1 using the arcpy library. I need to sum the total of a table column in order to calculate a new field. I wanted to ask if it is possible ...
8
votes
1
answer
8k
views
Using ArcPy to rename MXD layers?
I have a MXD with some layers that have parentheses in them. I'd like to rename them via script.
Is this a valid approach?
import re
map = arcpy.mapping.MapDocument("CURRENT")
layers = arcpy.mapping....
8
votes
5
answers
2k
views
Will there be a Python API for ArcGIS Server?
It seems like an obvious next step given the big push towards Python in ArcGIS Desktop at 10.0. Are there any limitations of Python compared to javascript, flex, etc that would prevent ESRI from ...
8
votes
2
answers
2k
views
getPart() method returns incorrect geometry from buffer in ArcGIS
I created 4 basic polygons:
And ran this script:
import arcpy
infc = r'D:\Scratch\POLYGONS.shp'
d=arcpy.Describe(infc)
SR=d.spatialReference
with arcpy.da.SearchCursor(infc, ("SHAPE@","...
8
votes
3
answers
4k
views
Calculating field in which null values may be present?
I would like to calculate a field (short integer) using other fields (short integer) present in the table. In some cases these fields may have null values for one or more of the fields. For example, ...
8
votes
2
answers
5k
views
List layers from current view using Arcpy
I am using ArcGIS 10.4.1 and Python 2.7.10.
I have a mxd file of a rather large area which contain hundred of layers. I wish to work in a specific sub-area in that workspace, where only a few layers ...
8
votes
2
answers
4k
views
Using PyQGIS, ArcPy, NumPy, SciPy Together in Windows Command Prompt
I ran across this slight issue when I was looking to access python installations from ArcGIS, QGIS, Anaconda (cited because SciPy & NumPy come with it), and version 2.7 vs 3. Sometimes, I find it ...
8
votes
3
answers
3k
views
Prevent newly created feature class being automatically added by ArcPy (Python AddIn) to Map Document?
I have a python addin, which as part of its function checks to see if a template point feature class exists on the user's machine. If it doesn't, it creates this file. This template file is used ...
8
votes
3
answers
34k
views
Python - formatting path strings and checking if a path exists
I would like to use the following code to determine if a path exists. The path I would like to check is being passed to my code via parameter on a ArcMap 10.0 tool dialog box. The parameters data ...
8
votes
1
answer
8k
views
Exporting .jpg files from Data Driven Pages using ArcPy? [closed]
I have generated about 90 maps through data driven pages(ArcGIS 10.0). I now want to export them as .jpg files in either landscape or portrait format.
I tried python but it is not working, it worked ...
8
votes
5
answers
1k
views
How to access adjacent rows with cursor?
In the attached screenshot, the attributes contain two field of interest "a" and "b". I want to write a script to access the adjacent rows in order to make some calculations. To access a single row, ...
8
votes
3
answers
2k
views
Is there a way to tell the geodatabase version using Python?
I want to find out if either a file or personal geodatabase is 9.3, 10.0, 10.1, etc
Is there a way to do this using Python?
8
votes
3
answers
20k
views
Clearing cache memory using python?
In this script I use 2 nested 'for' loops to extract a series of variables by month (month = 0 - 11) from 5 netcdf files and then mosaic together each extracted variable. The script runs but after ...
8
votes
2
answers
6k
views
Creating lines from polygon borders with polygon attributes using ArcGIS/ArcPy?
I have a shapefile of polygons that border each other perfectly, each with a numerical attriubte. I'd to create a shapefile of lines, where every line is created from the border between two polygons, ...
8
votes
2
answers
5k
views
Get shortest distance between two geometries in ArcPy
I'm using ArcPy and using a cursor to step through one polygon feature class. For each of these 'source' polygons, I am creating a SearchCursor to find all polygons in a second feature class that ...
8
votes
1
answer
3k
views
Why del cursor/row objects of ArcPy?
Can someone help me understand what the last 2 lines of this code does:
import arcpy
arcpy.env.workspace = "c:/esripress/python/data/exercise07"
arcpy.env.overwriteOutput = True
copy = arcpy....
8
votes
3
answers
6k
views
Is it possible to sort an arcpy.da.UpdateCursor()?
I have an ArcPy Data Access update cursor that I would like to sort before making updates to it.
The cursor makes updates if I don't sort, but if I add a sort to the cursor I get an error, "...
8
votes
3
answers
760
views
Move legend if it overlaps features within dataframe using ArcPy
Trying to find a way programmatically (arcpy) move the legend if it intercepts features within a data frame, in the scenario below, if the legend obscures the view of the AOI, then I want it to move ...
8
votes
2
answers
4k
views
Checking if feature class locked in ArcGIS using ArcPy?
I'm trying to find a way to determine whether a feature class is locked before trying to alter it.
In one database I want to remove a feature class completely, and in another I want to add extra ...
8
votes
1
answer
7k
views
Can multiprocessing with arcpy be run in a script tool?
I have been tinkering around with the multiprocessing module to resolve some processing of data in ArcMap 10.3.
I have created a script which works fine if I run it in IDLE. I see all my cores max ...
8
votes
1
answer
6k
views
Selecting specific row in attribute table using ArcPy (without iterating through whole table)? [closed]
I am using ArcGIS 10.2 and have assumed until now that it is possible to select a specific row in an attribute table. However, I can't seem to find a way to do this. The only available methods seem to ...
8
votes
2
answers
10k
views
Getting XY map coordinates on mouse clicks as input variables into a python script
This is my first time coding in python, so bear with me. I wrote a script to calculate an analytical solution to find the orientation of a plane based on three points. I'm using ArcGIS 10.1.
# Input ...
8
votes
2
answers
14k
views
ArcGIS ERROR 000824: The tool is not licensed in arcpy
I try to run the Zonal Statistic as a Table through ArcPy and it gives me:
ERROR 000824: The tool is not licensed.
Here is the doc for the function: http://resources.arcgis.com/en/help/main/10.1/...
8
votes
5
answers
3k
views
How to split points by polygon using ArcGIS Desktop?
I am looking for a way to split points by a county polygon feature class. The attached image shows two feature classes: one composed of points and the other a county polygon feature class. The split ...
8
votes
4
answers
11k
views
How to split single address field into 4 fields (House No., Direction, Name, Suffix)
I have to do some massaging of our parcel data to make it usable by a program in sheriff helicopters. The program requires one of the following address formats within the fields:
Our addresses are ...
8
votes
2
answers
922
views
Finding specific pixel values in ArcGIS using Python
I have a raster file containing some integer values.
I need to find all pixels whose values are not defined in list like this one:
l = [1,2,4,8,16,32,64,128].
Is there any easy way to solve that ...
8
votes
3
answers
5k
views
Writing world file when exporting TIFF using ArcPy Mapping?
According to documentation, the options are:
Syntax
ExportToTIFF (map_document, out_tiff, {data_frame}, {df_export_width},
{df_export_height}, {resolution}, {world_file}, {color_mode},
{...
8
votes
4
answers
12k
views
Debugging RuntimeError: workspace already in transaction mode from arcpy.da.UpdateCursor and ArcSDE feature classes?
I am making my first attempt at editing an ArcSDE feature class with python through a da.UpdateCursor. I'm essentially taking code I've written for a file geodatabase feature class and applying it to ...
8
votes
1
answer
5k
views
How to check if feature class or table contains field with specific name before adding it?
Im trying to write a script that finds out if the shapefile has a specific field and if not to add the field. I get it to show me the field, but the loop goes through each field, so it would create a ...
8
votes
2
answers
3k
views
Getting unique value of second field using arcpy.da.SearchCursor?
I have a feature class and using arcpy.da.SearchCursor I'm getting unique values of a field (e.g. Name). How can I use this method to get the associated row value of a different field (diff field = ...
8
votes
4
answers
2k
views
Finding centerline of peninsula? [closed]
Given a peninsula stretching north south and the two coast lines connecting in the south, I want to find out which is the place, or rather line, which is furthest away from both coastlines on the ...
8
votes
2
answers
3k
views
Deleting all fields from feature class with ArcPy?
How do I delete all of the fields from a feature class in a simple way?
I don't want to loop over the fields using the Delete Field tool because this method is very slow in ArcPy.
I am using a ...
8
votes
1
answer
1k
views
Converting point XY to page units XY using ArcPy
I am using ArcPy to export PDFs from my ArcGIS Server application. I want to move a TextElement in my layout view to the centroid of a selected feature. I can get the centroid of the feature, but that'...
8
votes
2
answers
1k
views
Reprojecting coordinates without building geometry object in ArcPy?
Is it possible with arcpy to reproject single x,y coordinates without building a complete geometry object?
For instance, something like this:
input = [[-8081441,5685214], [-8081446,5685216], [-...
8
votes
2
answers
618
views
Clean up attributes
I want to clean up the attribute table of a road shapefile for all the entries in the fields.
For example: As seen below I have a road feature with a "Name", Name From and Name To in the attribute ...
8
votes
1
answer
2k
views
How to select all values by default in arcgis tool's multivalue parameter using python?
I am using ArcGIS 10.2 and have three parameters, Feature class, field and a multivalue parameter respectively in ArcGIS tool. I populate multivalue parameter with unique values of feature class on ...
8
votes
1
answer
1k
views
Reduce extent of raster processing in ArcPy or ArcGIS Desktop?
I need to reduce the processing extent of my raster by some sort of automatic procedure in python. Currently the borders of the dataset I've been using has anomalies (due to the classification of the ...
8
votes
2
answers
6k
views
How do I calculate a weighted centroid with respect to a raster, e.g. population weighted centroid
In ArcGIS 10.0, how do I calculate the weighted centroid of a collection of polygons, where I want the weight to be a raster layer. In particular I am using a raster of population counts and would ...
8
votes
1
answer
6k
views
Problem with setValue() function in ArcGIS 10
I'm trying to add data to an attribute table in ArcGIS 10 using the following code:
def make_floor_no( shapefile ):
"Makes header for number of Floors (FLO) and calculates value"
fieldName = ...