<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.esri.com/Dev/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Geoprocessing : UNIX/Linux</title><link>http://blogs.esri.com/Dev/blogs/geoprocessing/archive/tags/UNIX_2F00_Linux/default.aspx</link><description>Tags: UNIX/Linux</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP2 (Debug Build: 61120.2)</generator><item><title>Send us your feedback</title><link>http://blogs.esri.com/Dev/blogs/geoprocessing/archive/2009/03/25/Send-us-your-feedback.aspx</link><pubDate>Wed, 25 Mar 2009 23:47:00 GMT</pubDate><guid isPermaLink="false">b60b3f0a-e2bd-4be5-8a18-822c697649ab:2779</guid><dc:creator>dmhoneycutt</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.esri.com/Dev/blogs/geoprocessing/comments/2779.aspx</comments><wfw:commentRss>http://blogs.esri.com/Dev/blogs/geoprocessing/commentrss.aspx?PostID=2779</wfw:commentRss><description>&lt;p&gt;You may not have noticed, but you can send us feedback about this site. There's
a feedback link at the bottom right of the home page, as illustrated at the bottom 
of this post.&lt;/p&gt;


&lt;p&gt;We're particularly interested in hearing from you about blog post topics
you'd like to see and suggestions on how we could make this site more useful.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;a href="http://blogs.esri.com/Dev/photos/geoprocessing/picture2780.aspx" target="_blank"&gt;&lt;img src="http://blogs.esri.com/Dev/photos/geoprocessing/images/2780/408x480.aspx" border="0"&gt;&lt;/a&gt;&amp;nbsp;&lt;/p&gt;&lt;img src="http://blogs.esri.com/Dev/aggbug.aspx?PostID=2779" width="1" height="1"&gt;</description><category domain="http://blogs.esri.com/Dev/blogs/geoprocessing/archive/tags/beginner/default.aspx">beginner</category><category domain="http://blogs.esri.com/Dev/blogs/geoprocessing/archive/tags/advanced/default.aspx">advanced</category><category domain="http://blogs.esri.com/Dev/blogs/geoprocessing/archive/tags/New+at+9.3/default.aspx">New at 9.3</category><category domain="http://blogs.esri.com/Dev/blogs/geoprocessing/archive/tags/Spatial+Analysis/default.aspx">Spatial Analysis</category><category domain="http://blogs.esri.com/Dev/blogs/geoprocessing/archive/tags/script+tools/default.aspx">script tools</category><category domain="http://blogs.esri.com/Dev/blogs/geoprocessing/archive/tags/Python/default.aspx">Python</category><category domain="http://blogs.esri.com/Dev/blogs/geoprocessing/archive/tags/ArcSDE/default.aspx">ArcSDE</category><category domain="http://blogs.esri.com/Dev/blogs/geoprocessing/archive/tags/Geostatistical+Analyst/default.aspx">Geostatistical Analyst</category><category domain="http://blogs.esri.com/Dev/blogs/geoprocessing/archive/tags/Digging+deeper/default.aspx">Digging deeper</category><category domain="http://blogs.esri.com/Dev/blogs/geoprocessing/archive/tags/Tips+and+tricks/default.aspx">Tips and tricks</category><category domain="http://blogs.esri.com/Dev/blogs/geoprocessing/archive/tags/UNIX_2F00_Linux/default.aspx">UNIX/Linux</category><category domain="http://blogs.esri.com/Dev/blogs/geoprocessing/archive/tags/3D+Lidar+Point+Data/default.aspx">3D Lidar Point Data</category><category domain="http://blogs.esri.com/Dev/blogs/geoprocessing/archive/tags/ModelBuilder/default.aspx">ModelBuilder</category><category domain="http://blogs.esri.com/Dev/blogs/geoprocessing/archive/tags/2009+Developers+Summit/default.aspx">2009 Developers Summit</category></item><item><title>Tips and tricks - Unix, Python, and Geoprocessing</title><link>http://blogs.esri.com/Dev/blogs/geoprocessing/archive/2008/10/27/Tips-and-tricks-_2D00_-Unix_2C00_-Python_2C00_-and-Geoprocessing.aspx</link><pubDate>Mon, 27 Oct 2008 22:41:00 GMT</pubDate><guid isPermaLink="false">b60b3f0a-e2bd-4be5-8a18-822c697649ab:2865</guid><dc:creator>dmhoneycutt</dc:creator><slash:comments>4</slash:comments><comments>http://blogs.esri.com/Dev/blogs/geoprocessing/comments/2865.aspx</comments><wfw:commentRss>http://blogs.esri.com/Dev/blogs/geoprocessing/commentrss.aspx?PostID=2865</wfw:commentRss><description>&lt;p&gt;&lt;i&gt;This posting was written by Mark Zollinger, a Product Engineer and long time 
UNIX user with the Geoprocessing team.&lt;/i&gt;
&lt;/p&gt;


&lt;p&gt;Do you like Solaris or Linux?  Do you "do GIS" on one of those platforms? 
Maybe you've been asked to convert some ArcGIS Workstation AML applications 
over to ArcGIS Engine.  Are you a command-line junkie?  (There are more of us 
than you might think)&lt;/p&gt;

&lt;p&gt;If, for one of the above or any other reason, you find yourself wondering 
if you should try developing GIS on Solaris or Linux, then it's time to stop 
wondering.  Join in with others who include a flavor of *nix in their list of 
working development platforms.&lt;/p&gt;

&lt;p&gt;There are several approaches to GIS development that work very well on 
Solaris and Linux.  &lt;/p&gt;

&lt;p&gt;If you are into low-level programming, you should consider Java or C++, 
both of which can access ArcGIS's ArcObjects API.  
I've used Java quite a bit over the years, and can tell you that the doors 
are wide open on what you can do with it. If this sound like the thing for you, 
then you can move along now, there's nothing to see here.  
This post isn't about ArcObjects at all.&lt;/p&gt;

&lt;p&gt;If you lean towards scripting and higher level abstractions, then geoprocessing's 
more coarse-grained object model, then you are in the right place.  
The rest of this post will show you how to set up an IDE for Python 
development and write a very simple geoprocessing script.&lt;/p&gt;

&lt;p&gt;I mentioned a moment ago that I've written my share of Java ArcObjects code.  
I've got to confess though, that I've always been a fan of scripting languages.  
Python and GP is where I spend most of my time these days.&lt;/p&gt;

&lt;h4&gt;Setting up&lt;/h4&gt;
&lt;p&gt;"Okay", you ask, "How do I start writing GP code in Python on non-Windows platforms?"&lt;/p&gt;

&lt;p&gt;You can do Python and GP from the command line, and I often prefer the focus this brings.  
I've found, however, that most folks prefer to work in a graphic 
IDE (Integrated Development Environment).&lt;/p&gt;

&lt;h5&gt;Setting up an IDE that you can use&lt;/h5&gt;
&lt;p&gt;Probably your best choice is the Eclipse IDE with the Pydev plugin.  
Eclipse is an Open Source IDE, intended to work with a wide variety of programming languages.  
Pydev is the plugin that specifically enables Python development in Eclipse.  &lt;/p&gt;


&lt;p&gt;The latest version of Eclipse, named Ganymede, has not been fully tested by ESRI for use with ArcGIS 9.3, and is not available for some older UNIX releases.  We recommend using version 3.3.2, which you can find in the archive at:&lt;/p&gt;

&lt;a href="http://archive.eclipse.org/eclipse/downloads/" target="_blank"&gt;http://archive.eclipse.org/eclipse/downloads/&lt;/a&gt;

&lt;p&gt;To install Eclipse, 
follow the instructions in the "Installing Eclipse" paragraph at:&lt;/p&gt;

&lt;a href="http://wiki.eclipse.org/FAQ_Where_do_I_get_and_install_Eclipse%3F" target="_blank"&gt;http://wiki.eclipse.org/FAQ_Where_do_I_get_and_install_Eclipse%3F&lt;/a&gt;

&lt;p&gt;(These instructions are for Ganymede, but they basically the same for version 3.3.2)&lt;/p&gt;

&lt;p&gt;Once you have Eclipse installed and running, you need to add the Pydev plugin.  
Just follow the "Getting Started" link on the left side of the Pydev homepage.&lt;/p&gt;
&lt;a href="http://pydev.sourceforge.net/" target="_blank"&gt;http://pydev.sourceforge.net/&lt;/a&gt;

&lt;p&gt;Note that you need the Open Source Pydev plugin.  The Pydev Extensions 
plugin is commercial trialware, and is optional.&lt;/p&gt;

&lt;p&gt;When you get to the "Configuring the interpreter" page, you are told to choose 
the Python interpreter that Pydev should use to run Python programs.  Use the 
Python installation you use for Engine development/testing. In most cases, this 
is the one that got installed with the Engine Runtime:&lt;/p&gt;

&lt;font size="2" face="courier new, courier, mono"&gt;$ARCGISHOME/python25/bin/python&lt;/font&gt;&lt;br&gt;

&lt;p&gt;Note: you might get an error message while trying to choose the interpreter.  
If you do, click the error dialog's Details button.  The message probably includes something like this:&lt;/p&gt;
&lt;font size="2" face="courier new, courier, mono"&gt;ld.so.1: python: fatal: libpython2.5.so.1.0: open failed: No such file or directory&lt;/font&gt;&lt;br&gt;

&lt;p&gt;This is an indication that the python interpreter is not correctly set up.  
The most likely cause is that your ArcGIS Engine environment has not yet been established.  
Exit Eclipse and source the init_engine shell script that applies to the shell 
you are using.  When you start Eclipse the problem should go away.
&lt;/p&gt;

&lt;p&gt;Also, item 3 on the "Configuring the interpreter" page asks you to set the 
SYSTEM PYTHONPATH.  When you do this, make sure to include $ARCGISHOME/bin.  
This matches the PYTHONPATH that gets set when you source init_engine.&lt;/p&gt;

&lt;h4&gt;Writing a Python script that does GP stuff&lt;/h4&gt;

&lt;p&gt;Now that you have a development environment, how do you use all this great 
GP stuff?  Let's create a very simple Python script to get you started on the 
road to GP development.  In most Python scripts, the first thing to do is to 
import the modules that you will need.  
For GP, we need to import the arcgisscripting module.  Let's also import the 
os and system modules:
&lt;/p&gt;
&lt;font size="2" face="courier new, courier, mono"&gt;import arcgisscripting&lt;br&gt;
import os, sys&lt;br&gt;&lt;/font&gt;

&lt;p&gt;To access GP, we need to create a Geoprocessor object.  This is the object 
through which you will call any GP functions or objects&lt;/p&gt;

&lt;font size="2" face="courier new, courier, mono"&gt;
gp = arcgisscripting.create(9.3)&lt;/font&gt;

&lt;p&gt;By passing in the 9.3 argument, you are getting the newer version of the 
Geoprocessor object, which is a little more Python friendly.  For this example 
we won't be using any of the Python friendly features, but it is never too early 
to start a good habit.&lt;/p&gt;

&lt;p&gt;Now that you have a GP object, what do you do with it? Let's set GP's workspace 
property and print it out, just to prove to ourselves that it really worked.  
For this example, let's set the workspace to a "data" directory just underneath 
the current Python directory.&lt;/p&gt;

&lt;font size="2" face="courier new, courier, mono"&gt;gp.workspace = os.path.join (sys.path[0], "data")&lt;br&gt;print "GP Workspace = " + gp.workspace&lt;br&gt;&lt;/font&gt;

&lt;p&gt;(Of course you can set
the workspace to any accessible directory, not just the one returned 
by &lt;font size="2" face="courier new, courier, mono"&gt;sys.path[0]&lt;/font&gt;.  I'm just using
&lt;font size="2" face="courier new, courier, mono"&gt;sys.path[0]&lt;/font&gt; because I know it's accessible.)&lt;/p&gt;

&lt;p&gt;sys.path is a list of strings where Python looks for modules.  The first item 
in the list is the current Python directory.  Calling os.path.join is a great 
way to build up filesystem paths, since it correctly handles all the path separator issues.  
(More on path separators later.)
When you run this script (Run -&amp;gt; Run As -&amp;gt; Python Run), you should see "GP Workspace= /some/path/data" 
printed in the Console tab near the bottom of the Eclipse window.  
&lt;/p&gt;

&lt;p&gt;You can use Eclipse or the operating system to create the data directory, 
since it probably doesn't exist yet.&lt;/p&gt;

&lt;p&gt;For this example, let's suppose you have point data representing hawk sitings 
in a national forest.  Your study area is a subset of the forest where a particular 
plant in known to grow.  What you need to do is clip your point data using the 
polygon of your study area.&lt;/p&gt;

&lt;p&gt;Once you have copied your data into the aforementioned data directory, 
your script could execute the clip tool like this:&lt;/p&gt;

&lt;font size="2" face="courier new, courier, mono"&gt;
&lt;pre&gt;gp.clip_analysis("nat_for.gdb/hawk_sightings", "study_area.shp", "nat_for.gdb/study_sightings")&lt;/pre&gt;&lt;/font&gt;

&lt;p&gt;Just to be sure it worked, you can print out the messages that the tool generated like this:&lt;/p&gt;

&lt;font size="2" face="courier new, courier, mono"&gt;
print (gp.getmessages())&lt;/font&gt;

&lt;p&gt;Notice that in calling the clip tool, we used forward slashes (/).  Back slashes (\) 
and forward slashes work equally well in ArcGIS on ALL platforms, so you don't 
need to worry about switching back and forth when you change to Windows.  You can 
even use back slashes on Linux and Solaris. The problem is that in Python, back 
slashes are a special character, so to use them, you have to treat them differently 
than most other characters.&lt;/p&gt;

&lt;ol&gt;- You can escape them: "\\some\\path"&lt;br&gt;
- You can use raw strings: r"\some\path"&lt;br&gt;
- You can use unicode strings: u"\some\path"&lt;br&gt;
&lt;/ol&gt;

&lt;p&gt;If you stick to forward slashes on all platforms, you improve the look of your code 
and reduce the effort it takes to type it.&lt;/p&gt;

&lt;p&gt;So now you have a script that looks like this:&lt;/p&gt;


&lt;blockquote&gt;&lt;font size="2" face="courier new, courier, mono"&gt;
import arcgisscripting&lt;br&gt;import os, sys&lt;br&gt;&lt;br&gt;gp = arcgisscripting.create(9.3)&lt;br&gt;&lt;br&gt;gp.workspace = os.path.join (sys.path[0], "data")&lt;br&gt;print "GP Workspace = " + gp.workspace&lt;br&gt;&lt;br&gt;gp.clip_analysis("nat_for.gdb/hawk_sightings", "study_area.shp", "nat_for.gdb/study_sightings")&lt;br&gt;print (gp.getmessages())&lt;/font&gt;&lt;/blockquote&gt;

&lt;p&gt;Run it, and it works, creating a new featureclass in the file geodatabase.
Now wasn't that easy?
To get more complicated, you just string together as many of those tools as you need to get the job done.  
&lt;/p&gt;

&lt;p&gt;Welcome to the world of Geoprocessing with Python!&lt;/p&gt;

&lt;h4&gt;Links&lt;/h4&gt;
&lt;a href="http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=An_overview_of_writing_geoprocessing_scripts"&gt;Automating workflows with scripts&lt;/a&gt; - Introduction to writing Python scripts for geoprocessing&lt;br&gt;
&lt;a href="http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=Techniques_for_sharing_Python_scripts"&gt;Techniques for sharing Python scripts&lt;/a&gt; - Useful techniques for sharing Python scripts&lt;br&gt;
&lt;a href="http://docs.python.org/tutorial/"&gt;The Python Tutorial&lt;/a&gt; - If you're new to Python, this is a good tutorial to start&lt;br&gt;
&lt;a href="http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=Python_equivalents_to_AML_functions"&gt;How to duplicate AML functions in Python&lt;/a&gt; - For AML programmers&lt;br&gt;
&lt;a href="http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=Python_equivalents_to_AML_directives"&gt;How to duplicate AML directives in Python&lt;/a&gt;- For AML programmers&lt;br&gt;

&lt;h4&gt;Troubleshooting&lt;/h4&gt;
&lt;h5&gt;Color issues&lt;/h5&gt;
&lt;p&gt;Upon using Eclipse on Solaris for the first time, you may see some color problems. 
For example, the text insertion caret might be white on a white background, making it invisible.
Another common symptom is that you cannot see the outline of text input fields.
If you run into this or something similar, check the color depth of your display.
If it is set to 8 bits, change it to 24.
&lt;/p&gt;

&lt;h5&gt;init_engine&lt;/h5&gt;
&lt;p&gt;You should have your Engine environment already established in the shell in 
which you start Eclipse. (&lt;font size="2" face="courier new, courier, mono"&gt;source init_engine.sh&lt;/font&gt; 
or &lt;font size="2" face="courier new, courier, mono"&gt;source init_engine.csh&lt;/font&gt;)
  If you see inexplicable error messages, this is the most likely cause.&lt;/p&gt;&lt;img src="http://blogs.esri.com/Dev/aggbug.aspx?PostID=2865" width="1" height="1"&gt;</description><category domain="http://blogs.esri.com/Dev/blogs/geoprocessing/archive/tags/beginner/default.aspx">beginner</category><category domain="http://blogs.esri.com/Dev/blogs/geoprocessing/archive/tags/advanced/default.aspx">advanced</category><category domain="http://blogs.esri.com/Dev/blogs/geoprocessing/archive/tags/Python/default.aspx">Python</category><category domain="http://blogs.esri.com/Dev/blogs/geoprocessing/archive/tags/Tips+and+tricks/default.aspx">Tips and tricks</category><category domain="http://blogs.esri.com/Dev/blogs/geoprocessing/archive/tags/UNIX_2F00_Linux/default.aspx">UNIX/Linux</category></item></channel></rss>