Blog Archives

Setting up Anaconda, PySAL with ArcGIS Python environment

This tutorial shows you how to set up conda environment to work with ArcGIS 10.4 and ArcGIS Pro 1.3. You can download a pdf copy of the tutorial with screenshots HERE. At the 2016 Esri International User Conference in San Diego last month, Esri released ArcGIS Pro 1.3, which can now use conda for packaging Python libraries. This allows support of python under multiple Python environments. You no longer need to install a separate Python install to get the full Python capability with ArcGIS as you did with past versions.

Workflow to set up Anaconda with ArcGIS 10.4

  • Install Anaconda without fouling the Windows environment (paths, registry) to break Esri’s python stack
  • Configure Anaconda with the particular add-ons you want, and
  • Configure ArcGIS’s Python so that it is aware of the appropriate Anaconda content.

1) Install Anaconda for All Users

  1. Go to http://continuum.io/downloads
  2. Download the 32-bit version of Anaconda (Python 2.7)
  3. In the install dialogs:
    • Select install for All Users
    • conda01
    • Install to a folder by default (C:\Anaconda2)
    • conda02
    • IMPORTANT: To avoid breaking ArcGIS (or other software), uncheck the checkboxes (a) make Anaconda the default Python and (b) add Anaconda’s Python to the PATH.
    • conda03
  4. Go to Start > All Programs(apps) > Anaconda2(32-bit) > Anaconda Prompt. Right click, run as administrator

2) Configure an Anaconda environment for use with ArcGIS

  1. Find the versions of numpy and matplotlib ArcGIS is using.

Open ArcMap and its Python window, and enter these commands:

    • >>> import sys, numpy, matplotlib
    • >>> print(sys.version, numpy.__version__, matplotlib.__version__)
    • (‘2.7.10 (default, May 23 2015, 09:40:32) [MSC v.1500 32 bit (Intel)]’, ‘1.9.2’, ‘1.4.3’)
    • conda04
  1. Create an Anaconda environment that is compatible with ArcGIS
    • Get to the Anaconda Command Prompt (Start > All Programs(apps) > Anaconda2(32-bit), pick “Anaconda Prompt“), Right click, Run as Administrator.
    • Type (depending on ArcGIS version, I am using ArcGIS 10.4 as an example here):
    • “conda create -n arc104 python=2.7.10 numpy=1.9.2 matplotlib=1.4.3 pyparsing xlrd xlwt pandas scipy ipython ipython-notebook ipython-qtconsole”
    • conda05
    • Enter y to proceed.
    • Anaconda’s conda command will then set up an environment subdirectory, ex: ” C:\Anaconda2\envs\arc104 “, installing the downloaded packages into it.
    • conda06
  2. Test the virtual environment
    • At the Anaconda Command Prompt, type: activate arc104
    • Type: conda list. You can see the list of packages installed.conda07
  3. Add more packages
    • You can add more packages using conda install, but make sure you specify version numbers for these that won’t change the environment’s version of python or numpy (or ArcGIS will not be able to use that environment anymore).
    • Let’s add the Python Spatial Analysis Library (pysal) module.
    • Type the following command at the Anaconda Prompt:”conda install -n arc104 python=2.7.10 numpy=1.9.2 matplotlib=1.4.3 pysal”
    • conda08

3) Configure ArcGIS to see Anaconda and vice versa

  1. Anaconda Python to ArcPy
    • Copy the Desktop10.4.pth file to the Anaconda environment site-packages folder:
    • From: C:\Python27\ArcGIS10.4\Lib\site-packages\Desktop10.4.pth
    • To: C:\Anaconda2\envs\arc104\Lib\site-packages\Desktop10.4.pth
  2. Arcpy to Anaconda Python
    • Create a zconda.pth (path) file with the content “C:\Anaconda\envs\arc104\lib\site-packages” in it.
    • Then copy zconda.pth to C:\Python27\ArcGIS10.4\Lib\site-packages
  3. Testing in ArcMap
    • As a regular user, start ArcMap, open the Python window
    • type “import pysal”
    • type “pysal.” A popup menu with a list of pysal-provided functions is a pretty good sign the installation succeeded.
    • conda09
  4. Testing in PyCharm
    • Start PyCharm, in File\Settings…, choose Project then Project Interpreter
    • Ignore the drop down list for Project Interpreter, and click the cog button to Add Local, and in the file browser pick C:\Anaconda2\envs\arc104\python.exe
    • conda10
    • To run your script, right click it in the Project window, and choose either Run or Debug
    • Restart PyCharm for the Python Console to use the arc104 environment.
    • conda11

Workflow to set up Anaconda with ArcGIS Pro 1.3

1) Create an Anaconda environment that is compatible with ArcGIS Pro

  • Copy the folder arcgispro-py3 from C:\Program Files\ArcGIS\Pro\bin\Python\envs and paste to C:\Anaconda2\envs
  • Rename the copied folder arcgispro-py3 in C:\Anaconda2\envs to arcpro

2) Test the virtual environment

  • At the Anaconda Command Prompt, type: activate arcpro
  • Type: conda list. You can see the list of packages installed

3) Add more packages

  • Let’s add the Python Spatial Analysis Library (pysal) module.
  • Type the following command at the Anaconda Prompt:”conda install pysal”

4) Configure ArcGIS to see Anaconda and vice versa

  • Arcpy to Anaconda Python
    • Create a zconda.pth (path) file with the content “C:\Anaconda2\envs\arcpro\lib\site-packages” in it.
    • Then Copy zconda.pth to C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages
  • Testing in ArcGIS Pro
    • Start ArcGIS Pro, open the Python window
    • type “import pysal”
    • type “pysal.” A popup menu with a list of pysal-provided functions is a pretty good sign the install succeeded.
    • conda12
    • conda13
  •  Testing in PyCharm
    • Start PyCharm, in File\Settings…, choose Project then Project Interpreter
    • Ignore the drop down list for Project Interpreter, and click the cog button to Add Local, and in the file browser pick C:\Anaconda2\envs\arcpro\python.exe
    • conda14
    • To run your script, right click it in the Project window, and choose either Run or Debug
    • Restart PyCharm for the Python Console to use the arcpro environment.

References

  1. USGS: https://goo.gl/xd6xz2
  2. Esri: https://goo.gl/tYGHrw
  3. GeoNet: https://goo.gl/mTLWMG
  4. UC-Davis: http://goo.gl/3bdbwz

Whitebox GAT’s new website and other developments

Check out Prof. John Lindsay’s new Whitebox GAT website and the GoSpatial. A lot of cool and innovative stuff!!

“GoSpatial is a command-line interface program for analyzing and manipulating geospatial data. It has been developed using the Go programming language and is compiled to native code. The project is experimental and is intended to provide additional analytical support for the Whitebox Geospatial Analysis Tools open-source GIS software. GoSpatial can however be run completely independent of any other software and is run from a single self-contained executable file.”

Whitebox Geospatial Analysis Tools

There are a few exciting announcements related to new developments on the Whitebox GAT front. The first is that due to changes in the Google Code practices (it has become ‘read only’ and is no longer accepting new code commits), the Whitebox project has moved its source code repository to GitHub. I think that this will eventually make for improved source code management, although there may be some initial transition issues that we’ll need to work past. Some of the documentation will have to be updated to reflect this change.

The second announcement, which I am most excited about, is that I have finally found the time to update the Whitebox GAT website. There is a fresh new and more professional look to the site. I hope you enjoy the new webpage and as always, feedback is welcome. What would you like to see added or changed?

Lastly…

View original post 88 more words

New ESRI Book: GIS Tutorial for Python Scripting

Link: http://www.directionsmag.com/pressreleases/esri-press-announces-gis-tutorial-for-python-scripting/408444

Esri Press Announces GIS Tutorial for Python Scripting

Python is a key tool for scripting geoprocessing functions and tasks in ArcGIS for Desktop, but many GIS professionals have not had the opportunity to learn it. New from Esri Press, GIS Tutorial for Python Scripting, by David W. Allen, is a workbook filled with hands-on programming exercises. It will help GIS users become comfortable working with Python, whether on-the-job or within an advanced GIS course. Python helps make workflows in ArcGIS for Desktop more efficient and saves countless hours by automating repetitive tasks.

GIS specialists who develop Python proficiency, particularly those who do not have a programming background, benefit by

  • Saving time on many GIS tasks by using Python scripts to automate workflows.
  • Customizing ArcGIS for Desktop to better match the work at hand with custom menus and add-ins.
  • Easily sharing Python toolboxes and scripting tools with others in the organization.

 

To gain the most value from the book, some prior experience using ArcGIS for Desktop is required. Exercise data is provided and instructors can request supplemental resources for coursework.

Allen is the GIS manager for the City of Euless, Texas. He has taught at Tarrant County College since 1999, where he helped found one of the first GIS degree programs in Texas and establish a state standard for GIS degree programs. He is the author of GIS Tutorial 2: Spatial Analysis Workbook (Esri Press, 2013) and Getting to Know ArcGIS ModelBuilder (Esri Press, 2011) and the coauthor of GIS Tutorial 3: Advanced Workbook (Esri Press, 2011).

GIS Tutorial for Python Scripting is available in print (ISBN: 9781589483569, 288 pages, US$69.99) and e-book format (ISBN: 9781589483972, 288 pages, US$69.99). The book is available at online retailers worldwide, atesri.com/esripress, or by calling 1-800-447-9778. Outside the United States, visit esri.com/esripressorders for complete ordering options, or visit esri.com/distributors to contact your local Esri distributor. Interested retailers can contact Esri Press book distributor Ingram Publisher Services.

 

How to configure Eclipse for ArcPy

  1. Download and install Eclipse
    1. Download Eclipse standard version: http://www.eclipse.org/downloads/packages/eclipse-standard-432/keplersr2 
    2. Extract the downloaded zip file, copy the unzip “eclipse” folder to C:\Program Files\.
  2. Install PyDev for Eclipse
    1. Go to Eclipse –> Help –> Install New Software
    2. Enter http://pydev.org/updates in the Work with:  field.
    3. After several seconds, two options should appear. Select the PyDev for Eclipse option. Do not select the “PyDev Mylyn Integration” flag.
    4. Click “Next” and “OK” to continue installing PyDev
  3. Configure PyDev
    1. Go to Window → Preferences. In the Preferences window, expand PyDev and select Interpreter-Python.
    2. Click “New…” and type Python27 for the Interpreter name. For the Interpreter executable, browse to your copy of Python C:\Python27\ArcGIS10.2\python.exe), and press Open.Image
    3. Click “OK” and the  Selection Needed Window will appear.Image
    4. Click “Select All” and “OK”.
    5. The Interpreter is now set up so that the code you write can be interpreted for the computer to run. You are now ready to start running code.
  4. Open Perspective as PyDev
    1. Go to Eclipse –> Window –> Open Perspective –> Other
    2. Select PyDev on the Open Perspective Dialog
    3. Image

Seven easy ways to start learning Python and ArcPy

I have some great news: you don’t have to be a programmer to write code! Thanks to languages like Python, coding is now available to the masses, and the GIS world is one of its newest audiences. The ArcPy site package provides access to the geoprocessing tools found in ArcGIS for Desktop. Using it can be a challenge if you are unfamiliar with Python, but with some basic knowledge, you can start using it to make your ArcGIS work flows faster and easier.

This post is broken up into sections based on different learning styles. You can choose to read, watch, or code your way into the world of Python, and each section will empower you with the knowledge for getting started with ArcPy. Here are some recommended resources I’ve used for teaching myself Python and ArcPy.

 

Learn by Reading

1. Learn Python the Hard Way (LPTHW)

Don’t be scared by the title – Learn Python the Hard Way (LPTHW) is probably the most popular online tutorial for learning Python. In fact, many “Pythonistas” at Esri started learning Python with this website! This exercise-oriented guide reinforces its teachings through repetition and practical usage of basic Python functionality, even if you have no prior experience. I recommend completing the first 32 exercises to equip yourself with the knowledge you need.

2. Think Python: How to Think Like a Computer Scientist

I recommend this site for those users who are used to a more “textbook” approach to learning. The book is produced by O’Reilly and is now free to the public. The approach is different than LPTHW, and some people may find it to be less fun to learn from, but it’s packed with useful information. The chapters up to, and including, “Files”, will be the most useful for ArcPy users, but reading subsequent chapters will help you understand a little bit about what’s going on “under the hood” in a Python module such as ArcPy.

Learn by Watching

3. The New Boston

The videos in this series are perfect for their format. They are concise (each video runs about five minutes), thorough, and show practical coding examples that you can follow along with or practice on your own. In the first 31 videos, this series covers just about all of the concepts you will need for getting started.

4. Khan Academy

Khan Academy has made free education available to everyone for a variety of topics, and their Python course was one of the first “classes” offered. The curriculum is similar to what you can expect from a Computer Science class, so it may seem a little challenging at first. However, if you stick with it, you’ll be thinking like a programmer.

Learn by Doing

5. Code Academy

This is an interactive Python course that teaches the basic concepts of Python by having you complete coding exercises. All the work is done online –you don’t even need Python installed on your computer to complete it! The site prompts you to complete small lessons and challenges, and is great for those users who don’t always have a consistent amount of time to contribute to studying. I would recommend completing the first 15 lessons if you want to understand more about Python.

Learn ArcPy

6. Esri Python Training

Esri’s training site is the best way to see Python in action, apply it to ArcPy and GIS workflows, and hear some great questions from users like you and I. The courses are designed for users with any level of experience with Python and ArcPy, so you’ll come back to this site time and again to learn new tricks or brush up on your skillset.

7. Python Scripting for ArcGIS

This is one of the only educational textbooks out there for learning the basics of ArcPy, and it helped me a lot when I started using ArcPy for the first time. The first four chapters are devoted to learning the ins-and-outs of basic Python functionality, and the rest of the book focuses on specific scripts. You’ll get a cohesive and complete introduction to ArcPy as you work your way through this book.


In addition, this Support Services Blog post talks about learning ArcPy, and very nicely outlines all the resources that are out there. Once you’ve finished reading my blog entry, you can concentrate on the one above!

Andrew O. – Desktop Support Analyst

– See more at: http://blogs.esri.com/esri/supportcenter/2014/03/26/8-easy-ways-learning-python-arcpy/?WT.mc_id=EmailCampaignh32401#sthash.kKYpz7Zk.dpuf

REDD+ for the Guiana Shield

Technical Cooperation Project

LidarBlog.com

Dr. Qiusheng Wu @ SUNY Binghamton

Writing Science

How to write papers that get cited and proposals that get funded

GIS In Ecology

Providing Training, Advice And Consultation On The Use Of GIS In Ecology

metrhispanic

On cities, land, ...

GeoAcademy

Open GIS: No Bounds

Scientia Plus Conscientia

Thoughts on Science and Nature

r4hydrology

Learning hydrology with R

Karl Hennermann

GIS at the University of Manchester

GIS and Science

Applications of geospatial technology for scientific research and understanding.

GISblog.com

GIS, Mapping, Remote Sensing, Geodata, Geospatial news

Whitebox Geospatial Analysis Tools

Open-source GIS development and spatial analysis with Whitebox GAT

TopoToolbox

MATLAB-based software for topographic analysis

Anything Geospatial – AnyGeo

Dr. Qiusheng Wu @ SUNY Binghamton

GeospatialPython.com

Dr. Qiusheng Wu @ SUNY Binghamton

Another GIS Blog

Dr. Qiusheng Wu @ SUNY Binghamton

ArcPy Café

Get all your ArcGIS Python Recipes here!

Planet Python

Dr. Qiusheng Wu @ SUNY Binghamton