ArcPY - Python
Follow
Find
41.5K views | +46 today
ArcPY - Python
Information and Tutorials about ArcGis Python
Your new post is loading...
Your new post is loading...
Scooped by Elpidio I F Filho
Scoop.it!

Another GIS Blog: Setup WING IDE for ArcPy 10.1

I've changed python IDE to WING. It's a very nice IDE, but it took sometime getting use to from pydev's eclipse add on.

Here is the basic setup of WING IDE with PyLint:

1. Download easy_install: http://pypi.python.org/pypi/setuptools/#windows
2. Install easy_install
3. Go to the install location of Python 2.7.x and run 'easy_install pylint'
4. Install WING IDE
5. Start WING IDE
6. Select Tools -> PyLint
7. Right click on the PyLint window and select 'configure'
8. Edit the 'command =' to be 'command = C:\Python27\ArcGIS10.1\Scripts\pylint.bat'
9. Run pylint on a .py file

* if you get an error, try adding the full

more...
No comment yet.
Scooped by Elpidio I F Filho
Scoop.it!

High Quality Printing with ArcPy « Dekho Resource Center

High Quality Printing with ArcPy « Dekho Resource Center | ArcPY - Python | Scoop.it

With some minor tweaks to the existing ArcPy print sample for Dekho, you can point the script at your source data as opposed to the map services that have references to the source data.

This not only improves the quality (as the map services ‘rasterise’ the raw data), but also dramatically speeds up the process.....

more...
No comment yet.
Scooped by Elpidio I F Filho
Scoop.it!

ESRI/arcpy – Locked Files

When working with geoprocessing tools in ArcGIS, especially using arcpy, you quickly learn about locked files. These files are locked because they are currently being edited, or being viewed in ArcCatalog, or otherwise accessed with ESRI products. This creates a LOCK files that is displayed in e.g. Windows Explorer. Typically, upon successful completion of your geoprocessing task, the lock is removed (the LOCk files disappears). Unfortunately, when you run arcpy scripts outside of ArcMap’s Python window, oftentimes this doesn’t work, especially with cursors. I have found that I was getting errors like:

 

ExecuteError: ERROR 000258: Output C:/temp/myfile.shp already exists
Failed to execute (CreateFeatureclass

 

That despite the fact that I had set

 

arcpy.env.overwriteOutput = True

 

.....

more...
No comment yet.
Scooped by Elpidio I F Filho
Scoop.it!

Data storage and retrieval in ArcGIS | GEOG 485: GIS Programming and Automation

Data storage and retrieval in ArcGIS | GEOG 485: GIS Programming and Automation | ArcPY - Python | Scoop.it

Providing paths in Python scripts

 

Often in a script you'll need to provide the path to a dataset. Knowing the syntax for specifying the path is sometimes a challenge because of the many different ways of storing data listed above. For example, below is an example of what a file geodatabase looks like if you just browse the file system of Windows Explorer. How do you specify the path to the dataset you need? This same challenge could occur with a shapefile, which, although more intuitively named, actually has three or more participating files.....

more...
No comment yet.
Scooped by Elpidio I F Filho
Scoop.it!

The ArcPy Mapping Module

The ArcPy Mapping Module | ArcPY - Python | Scoop.it
The ArcPy.Mapping module is new to ArcGIS 10 and brings some really exciting features for mapping automation including the ability to manage map documents and layer files as well as the data within these files. Support is also provided for automating map export and printing as well as the creation of PDF map books and publication of map documents to ArcGIS Server map services.

The free lecture for this module can be found by clicking here.
Note: The data and exercises will only work with ArcGIS 10 so unless you have a pre-release copy you'll need to wait until the final release to complete the exercises. You will also want to create the following directory structure in Windows Explorer: C:\GeoSpatialTraining\ArcGIS 10\GIS Programming 101\Exercises
It's not absolutely necessary to create this structure, but the exercises assume that it exists. Just keep that in mind if you unzip elsewhere.

There are 5 exercises for this module......

more...
No comment yet.
Scooped by Elpidio I F Filho
Scoop.it!

ArcGis : Toolbox to Python Toolbox Wrapper

ArcGis : Toolbox to Python Toolbox Wrapper | ArcPY - Python | Scoop.it

New to the Python Toolboxes introduced in 10.1? Need a starting point for your scripts? This Python Toolbox will take any existing TBX file, including system toolboxes, and create a roughly equivalent PYT file that contains the same tools with the same parameters. This is not an 100% automated solution and will require a fair amount of intervention and editing after creation, but will be an excellent starting point and teaching tool for authoring your own PYT files.

I've put the source up on bitbucket and enabled issue tracking, so if you'd like to report a bug or follow the development of this tool please go there.

more...
No comment yet.
Scooped by Elpidio I F Filho
Scoop.it!

ArcPy : Retrieving Total Counts « Café Python

ArcPy : Retrieving Total Counts « Café Python | ArcPY - Python | Scoop.it

In ArcGIS, the Summary Statistics tool is typically used to calculate a total count of unique occurrences in one field by a case field.
This is a table generated by the Summary Statistics tool showing the number of zip codes per state.

However, when you need this information in Python, you can avoid using the Summary Statistics tool and a search cursor. Instead, you can use the Counter class in the collections module. This will create a dictionary of keys and their counts. Here is the Python code and sample of the resulting dictionary: ..........

 

more...
No comment yet.
Scooped by Elpidio I F Filho
Scoop.it!

Configure PyScripter to use with QGIS (and still use arcpy) on Windows

Configure PyScripter to use with QGIS (and still use arcpy) on Windows | ArcPY - Python | Scoop.it
As many of you may already know, PyScripter is an excellent IDE for Python. For those of you who haven’t tried it… well, you don’t know what you are missing! I was using PyScripter quite happily with ArcGIS 10 and arcpy without ever having to tweak anything in PyScripter. All was well until I decided to explore PyQGIS, QGIS’ scripting language. I could not, for the life of me, get this initial statement to work in PyScripter although it was working fine in the QGIS Python console:

import qgis.core

......

more...
No comment yet.
Scooped by Elpidio I F Filho
Scoop.it!

How to Get Started Using Aptana Studio 3 for ArcPy Development

This is a short video that I made of how to set up Aptana Studio 3 and it's Pydev module for developing python scripts that use ESRI's ArcPy module.
more...
No comment yet.
Scooped by Elpidio I F Filho
Scoop.it!

Make an FTP tool – or any tool – the easy way.

Make an FTP tool – or any tool – the easy way. | ArcPY - Python | Scoop.it
Perhaps this is something that is inherently understood by “coders”, but as a newbie code writer, I had to figure this out on my own. It’s much more efficient to make your own tools and reference them over and over than it is to write the same code over and over in each little script you make.

 

I didn’t come to realize that I had things I wanted to do over and over until I had a library of scripts and started to see patterns. Some of the ‘do-overs’ are things like FTP all the files in a folder to our FTP site, or email myself a note once a script has completed (or even if it has failed), or log events into a table or file as the script progresses.

 

This sort of thing was intimidating as I was reading python tutorials and the samples use things like double underscores and references to “self” in a def statement. I still have no idea what those do (I”ll let you know if I figure it out!) but honestly I haven’t needed it yet. It doesn’t have to be that complicated...... 

more...
No comment yet.
Scooped by Elpidio I F Filho
Scoop.it!

ArcPy : Favorite Code Editor

ArcPy : Favorite Code Editor | ArcPY - Python | Scoop.it

In my progression from utter novice programmer to whatever stage you might say I’m at now, I’ve tried several editors. So far my favorite editor is Komodo. Once I started using this software, those pesky newbie mistakes dropped away. Never again did I forget I closing parantheses or bracket. Every if statement ends in a colon and every try is matched with an except. Komodo keeps track of all of these and makes it impossible to miss when you’ve left them out. And the tab guides are indispensible when you are more than a few tabs deep in a loop inside a loop inside a try/except statement. The keyboard shortcuts for indent/outdent and comment/uncomment are life savers too. It’s also possible to wire up Komodo to read and help with predictive text with the Arcpy modules.

more...
No comment yet.
Rescooped by Elpidio I F Filho from Geoprocessing
Scoop.it!

GIS Surveyor: Working with BLOB data at 10.1 (arcpy.da)

GIS Surveyor: Working with BLOB data at 10.1 (arcpy.da) | ArcPY - Python | Scoop.it

Reading and writing BLOB data has always been an issue previous to 10.1, but now it's not a problem. A reader pointed out that fact the other day, so I thought why not point this out to everyone.
From the help (source: resourcebeta.arcgis.com):
A BLOB is data stored as a long sequence of binary numbers. ArcGIS stores annotation and dimensions as BLOBs, and items such as images, multimedia, or bits of code can be stored in this type of field. You can use a cursor to load or view the contents of a BLOB field.
In Python, BLOB fields can accept strings, bytearray, and memoryviews. When reading BLOB fields, a memoryview object is returned.
So what does this mean to you. We'll it's time to store those documents, pictures from vacation, and videos with geo tags in a spatial database........

more...
No comment yet.
Scooped by Elpidio I F Filho
Scoop.it!

GIS Surveyor: SearchCursor (arcpy.da) 10.1 Continued

GIS Surveyor: SearchCursor (arcpy.da) 10.1 Continued | ArcPY - Python | Scoop.it
The new cursor objects contain a very helpful property called fields. This property returns a tuple of field names defined in the field_names argument. This means that if you pass "*" for all fields you can then get the associated field to the associated value.

Remember, cursor objects will ignore BLOB and Raster fields.....

more...
No comment yet.
Scooped by Elpidio I F Filho
Scoop.it!

Getting arcpy.da rows back as dictionaries

Getting arcpy.da rows back as dictionaries | ArcPY - Python | Scoop.it
Though arcpy.da‘s cursors return rows as lists, you can easily transform these on-the-fly with just a little code on your part: Or if you’d like to be able to use a syntax similar to th...
more...
No comment yet.
Scooped by Elpidio I F Filho
Scoop.it!

Using ArcPy for multi-page exports « Dekho Resource Center

Using ArcPy for multi-page exports « Dekho Resource Center | ArcPY - Python | Scoop.it

It is great to see that the generic ArcPy sample we provided is getting a lot of download hits.

On a previous post, I did a video on how you can setup your Layout MXD to sync multiple data frames to the main data frame, so that you can display a variety of basemaps in separate data frames, all in the one printout.....

more...
No comment yet.
Scooped by Elpidio I F Filho
Scoop.it!

Accessing data fields | GEOG 485: GIS Programming and Automation

Discovering field names

 

When you write a script, you'll need to provide the names of the particular fields you want to read and write. You can get a Python list of field names using arcpy.ListFields().

 

# Reads the fields in a feature class

 

import arcpy

 

featureClass = "C:\\Data\\Alabama\\Alabama.gdb\\Cities"
fieldList = arcpy.ListFields(featureClass)
# Loop through each field in the list and print the name
for field in fieldList:
     print field.name

........

more...
No comment yet.
Scooped by Elpidio I F Filho
Scoop.it!

Reading through records | GEOG 485: GIS Programming and Automation

Reading through records | GEOG 485: GIS Programming and Automation | ArcPY - Python | Scoop.it

Now that you know how to traverse the table horizontally, reading the fields that are available, let's examine how to read up and down through the table records.

The search cursor

The arcpy module contains some objects called cursors that allow you to move through records in a table. Cursors are not unique to ArcGIS scripting; in fact, if you've worked in ArcObjects before, this concept of a cursor is probably familiar to you. The first cursor we'll look at is the search cursor, since it's designed for simple reading of data. The common workflow is:

1- Create the search cursor. This is done through the method arcpy.SearchCursor(). This method takes several parameters in which you specify which dataset and, optionally, which specific rows you want to read.
2 - Call SearchCursor.next() to read the first row.
3 - Start a loop that will exit when there are no more rows available to read.
4 - Do something with the values in the current row.
5 - Call SearchCursor.next() to move on to the next row. Because you created a loop, this puts you back at the previous step if there is another row available to be read. If there are no more rows, the loop condition is not met and the loop terminates.

 

When you first try to understand cursors, it may help to visualize the attribute table with an arrow pointing at the "current row." When the cursor is first created, that arrow is pointing just above the first row in the table. The first time the next() method is called, the arrow moves down to the first row (and returns a reference to that row). Each time next() is called, the arrow moves down one row. If next() is called when the arrow is pointing at the last row, a special data type called None is returned.....

more...
No comment yet.
Scooped by Elpidio I F Filho
Scoop.it!

Script de python para generar y rotar rectángulos a partir de puntos en QGIS-GRASS

Script de python para generar y rotar rectángulos a partir de puntos en QGIS-GRASS | ArcPY - Python | Scoop.it
El siguiente código python es una traducción del correspondiente a bash basado en el mismo objetivo: generar y rotar rectángulos a partir de puntos en QGIS-GRASS. La motivación fue producto de la curiosidad en conocer la manera de traducir la instrucción al lenguaje de grass.script correspondiente a db.execute. Ello es factible, a modo de ejemplo, con algo similar a esto:


1 grass.write_command("db.execute", stdin = 'UPDATE rectangulo_area SET x=coor_x WHERE cat = 1')


Sin embargo, fue imposible lograr que x tomara el valor de coor_x; a menos que lo colocara explícitamente en la instrucción. Finalmente opté por v.db.update.

more...
No comment yet.
Scooped by Elpidio I F Filho
Scoop.it!

Sorting alphanumeric strings in Python « Café Python

Sorting alphanumeric strings in Python « Café Python | ArcPY - Python | Scoop.it

In a recent project, I had to sort a list of alphanumeric strings which looked like this:


['AL13, 'AL3', 'AA14', 'AA4']

 

My first thought was to use the sorted function, and that returned the following result:

 

>>> sorted(['AL13, 'AL3', 'AA14', 'AA4'])
['AA14', 'AA4', 'AL13', 'AL3']

 

What I really wanted was it to give me back the list with the numbers sorted in a smarter way:

 

['AA4', 'AA14', 'AL3', 'AL13']

 

After searching Stack Overflow, I found this post, which worked perfectly! See Mark Byers variation of Jeff Atwood’s natural sort....

more...
No comment yet.
Scooped by Elpidio I F Filho
Scoop.it!

Open Source Marine GeoTools from NOAA and other Open Source GIS News - All Points Blog

Marine Geospatial Ecology Tools (MGET), also known as the GeoEco Python package, is an open source geoprocessing toolbox that includes over 250 tools useful for a variety of tasks. These tasks include downloading popular oceanographic datasets in GIS-compatible formats, identifying fronts and eddies in satellite images, building statistical habitat models from species observations and creating habitat maps, modeling biological connectivity by simulating hydrodynamic larval dispersal, and building grids that summarize fishing effort, catch per unit effort, and other statistics......

more...
No comment yet.
Scooped by Elpidio I F Filho
Scoop.it!

Manejo de arrays y matrices en python

Manejo de arrays y matrices en python | ArcPY - Python | Scoop.it

He leído constantemente que python es un lenguaje muy poderoso con el cual se puede hacer prácticamente lo que uno desee. Recientemente, me adentré en su mundo tratando de programar algunas aplicaciones para GRASS, sin embargo, esa “zambullida” fue prácticamente sin conocer muchos detalles del lenguaje y eso me ha traído algunos problemas. Por esta razón me propuse identificar algunos aspectos que tenía que aprender mejor y ese correspondía al de arrays y matrices.....

more...
No comment yet.
Scooped by Elpidio I F Filho
Scoop.it!

Using ipython with ArcPy

Using ipython with ArcPy | ArcPY - Python | Scoop.it

Many of us GIS profressionals rely on python to get the job done in a faster, and more fun way. I myself do some developing of arcgis tools in python for various organizations/individuals/ and the general public.

Several months ago I learned about ipython while watching pycon2012 videos. I tried it out and I have been using it all the time in linux environments and on pythonanywhere.com. It is great, does tab completion, you can type ?anything and get help on 'anything'.

It occured to me that using this with ArcPy would be great. It would allow me to test and develop using ESRI's arcpy environment quicker and easier than the built in console.

After a little trail and error, I got ipython working with arcpy.

Install the Windows 32bit ipython package. You will have to run this as admin and it should autodetect the arcgis python environment.
Check out this page. You will need to get pyreadline for the tab completion to work (highly recommend it).
You also need to install setuptools from here. Make sure you get the correct python version. ArcGIS 10.0 uses Python 2.6, while 10.1 will be 2.7 I believe.
Once you get all that finished and instaled, open up cmd.exe or console and type the following

 

cd C:\Python26\ArcGIS10.0
python.exe Scripts\ipython-script.py -pylab

 

Now you should be in the ipython shell. Here is a photo of me using tab autocomplete to find the ListDataset function.......

more...
No comment yet.
Scooped by Elpidio I F Filho
Scoop.it!

Zipping files in python

Zipping files in python | ArcPY - Python | Scoop.it

Every so often I run an automated process that copies all of our clients data to file geodatabases and then zips them up to post to the web. Previously I used PKZip as a command line zipper, calling it from my python script in a batch file. I decided to explore the possibility of zipping from within python. Turns out there is a module called zipfile that does just what I need. A fellow blogger got me started on the right path with a very helpful blog posting....

more...
No comment yet.
Scooped by Elpidio I F Filho
Scoop.it!

iPhone Photos to Esri File Geodatabase via arcPy Python Script

Here’s a rough script (but it does work) that reads EXIF information from already downloaded photos (tested with an iPhone) and creates a file geodatabase using the latitude and longitude stored with the photo.

You have to have had your GPS active while taking the photos. The pictures are moved into the file geodatabase and a hardcoded path is stored. Eventually I’d like to calc that as a relative path and leave the photos where they are. The benefit to moving them into the geodatabase means they won’t get lost, but you duplicate the photos and increase storage needs.

The settings for running the script to accept arguments, or to run with a hard coded path, are near the bottom. Be sure to modify the paths to be what you want....

more...
No comment yet.
Scooped by Elpidio I F Filho
Scoop.it!

Another GIS Blog: SearchCursor (arcpy.da) 10.1 Continued

The new cursor objects contain a very helpful property called fields. This property returns a tuple of field names defined in the field_names argument. This means that if you pass "*" for all fields you can then get the associated field to the associated value.

Remember, cursor objects will ignore BLOB and Raster fields.

Example:
import arcpy
from arcpy import da
fc = r"c:\temp\demo_polygon.shp"
with da.SearchCursor(fc,"*") as rows:
for field in rows.fields:
print field

So in this example, the cursor will print all the fields being accessed. It will also show the type of Shape field is being returned. If all fields is used ("*"), then the SHAPE@XY property returned by default.

more...
No comment yet.