ArcPY - Python
11
Information and Tutorials about ArcGis Python
Follow
Scooped by Elpidio I F Filho onto ArcPY - Python
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.....

No comment yet.
Elpidio I F Filho is also curating
Geoprocessing Greve Universidades Federais 2012 Remote Sensing News #Geoprocessamento em Foco Digital Cartography Digital Soil Mapping
and 6 others
Discover Topics Elpidio I F Filho is following
Geography Education Classemapping ipadsineducation geoinformação Geo-visualization Geolocalización y Realidad Aumentada en educación
and 72 others
Your new post is loading...
Scooped by Elpidio I F Filho
Scoop.it!

Building feature classes from NumPy arrays

Building feature classes from NumPy arrays | ArcPY - Python | Scoop.it
With ArcGIS 10.1, a NumPy array can be easily converted into a point feature class using the arcpy.da.NumPyArrayToFeatureClass function.

 

Notable is that other geometry types such as Polygon, Polyline or Multipoint are not supported by NumPyArrayToFeatureClass. However, all the tools needed to create other geometry types from NumPy are there. The numpy_array_to_features function below combines the new arcpy.da.InsertCursor and NumPy methods to turn a NumPy array into features.......

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

A simple approach for including 3rd party Python libraries with your scripts | ArcGIS Resource Center

A simple approach for including 3rd party Python libraries with your scripts | ArcGIS Resource Center | ArcPY - Python | Scoop.it

Often times, your Python scripts require 3rd party Python libraries. For example, the sample tools located here: http://www.arcgis.com/home/item.html?id=f3d91b8f852042e289e09a7ec8342431 requires xlrd, xlwt, and openpyxl Python libraries. This sample includes all of the dependent libraries, and demonstrates just how easy it is.

 

The secret to most Python modules and packages: they’re just files. You can copy any Python library into the same folder as the .py file that imports them and it will just work (Note: in the case of C extensions and compiled bytecode, the Python version and architecture must match). Here is the layout of the folder with the libraries we mentioned before:

 

Finding the install location of a library

 

Usually the Python library is located in the site-packages folder within the Python install directory, however, if it is not located in the site-packages folder and you are uncertain where it is installed, here is a Python sample to locate Python modules installed on your computer.....

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

ArcGIS 10.1 arcpy Wall Reference Poster

ArcGIS 10.1 arcpy Wall Reference Poster | ArcPY - Python | Scoop.it

This is an automatically generated diagram of arcpy as it is shipped in ArcGIS 10.1. This document is not the official reference: please refer to the ArcGIS 10.1 online help for an accurate, complete, actively maintained source of documentation. arcpy is big: a piece of paper with full of boxes of names out of context will not be as useful as the official help with explanations and code samples.

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...
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.....

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

........

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.....

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.

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....

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......

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.....

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.......

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....

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

Clip, Zip and Ship your image service, using Python | ArcGIS Resource Center

Clip, Zip and Ship your image service, using Python | ArcGIS Resource Center | ArcPY - Python | Scoop.it

Here is a Python sample that can be used to clip items from your image service, package them into a mosaic dataset with all the metadata field values, and then ship them to a client or colleague. As with all other code samples that we add to our gallery, it is meant to help show you how something can be done in code; the actual implementation may need some altering in order for it to work for your particular example.

 

Description:
This python sample application accepts a input image service layer or URL as input. You can draw a polygon feature to define an area on the image service that you want to clip.

 

The program will start creating a local mosaic dataset with all metadata field recovered from the image service. And then it will download the image service item one by one according to the geometry of the polygon, and clip the image using the polygon.

You also have the option to clip the image using the default raster function if there is any. And you can also define the output image’s cell size.

 

The downloaded image will be added back to the local mosaic dataset along with all the metadata field values from the image service.

 

Note:
This python scripting tool uses the 10.1 Image Server REST API. Some of the functionality, such as define output image spatial reference in the ExportImage REST request is not available in 10.0. This is only a sample, and you may need to alter it, order for it to work for your particular case.

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

Field mapping and Python scripting | ArcGIS Resource Center

Field mapping and Python scripting | ArcGIS Resource Center | ArcPY - Python | Scoop.it

A number of geoprocessing tools including Spatial Join (Analysis), Append (Management), Merge (Management), Feature Class To Feature Class (Conversion), and Table To Table (Conversion), have a parameter for controlling how fields from the input dataset(s) are processed and written, or mapped, to the output dataset – the Field Map parameter. In addition to the simple moving of attributes from input to output, field mapping can also be useful for some common tasks such as field concatenation and calculating statistics like mean, sum, and standard deviation.

 

If you haven’t used the Field Map before, you should! Understanding and using field mapping will often reduce the number of processing steps in a workflow, and ensure that, in any scenario, attributes are handled in an appropriate way. Yes, the Field Map parameter is a complicated one, but it is well worth the time it takes to figure it out.

Because the Field Map is a complicated parameter, working with it in Python can also be complicated. The best way to interact with field mapping in Python scripting is with the FieldMappings object. In Python, most geoprocessing tool parameter types are seen as simple numbers or strings (specifying a feature class input is as easy as providing the feature class’ path). But several of the more complex parameters have objects that exist to help you effectively work with the parameter. The Field Map parameter can accept a long structured string indicating the field map settings (you may have seen this long string equivalent in geoprocessing messages), however, working with the field mapping string is inefficient and error-prone, so use the FieldMappings object for the best experience.

 

Problem

I was recently presented with a data migration problem where field mappings and Python scripting literally saved me weeks of work. The goal was to convert a collection of hundreds of VPF (Vector Product Format) databases containing many feature classes to a handful of geodatabases, and because of the large scale of the migration it had to be accomplished in an automated fashion (this is where the many weeks of work would be saved). The schema of the geodatabases was already set up with a number of feature datasets and empty feature classes into which the VPF feature class data would be imported using the Append (management) tool.

The iteration through the collection of VPF databases was solved with some simple looping techniques involving the arcpy.ListDatasets() and arcpy.ListFeatureClasses() functions. However, there was a fundamental problem that nearly derailed the automation of this process: VPF feature classes can have spaces in their field names, while geodatabase datasets cannot. When the empty geodatabase feature classes were created from the schema of the VPF feature classes, the spaces in the field names were automatically changed to underscores ( _ ) in the geodatabase feature classes. This very subtle difference caused huge ripples in the automated process, since the Append (Management) tool can not automatically match fields like ‘mcc description’ to ‘mcc_description’; in the output geodatabase feature class, all the values in the ‘mcc_description’ field are NULL because the fields were not matched.

 

 

 

No comment yet.
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

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.....

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

 

.....

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.....

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......

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.

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: ..........

 

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

......

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.
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...... 

No comment yet.