<?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 : Python</title><link>http://blogs.esri.com/Dev/blogs/geoprocessing/archive/tags/Python/default.aspx</link><description>Tags: Python</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP2 (Debug Build: 61120.2)</generator><item><title>Using arcgisscripting's "9.3" switch</title><link>http://blogs.esri.com/Dev/blogs/geoprocessing/archive/2009/07/28/Using-arcscripting_2700_s-_2200_9.3_2200_-switch.aspx</link><pubDate>Tue, 28 Jul 2009 21:46:00 GMT</pubDate><guid isPermaLink="false">b60b3f0a-e2bd-4be5-8a18-822c697649ab:7294</guid><dc:creator>bbicking1</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.esri.com/Dev/blogs/geoprocessing/comments/7294.aspx</comments><wfw:commentRss>http://blogs.esri.com/Dev/blogs/geoprocessing/commentrss.aspx?PostID=7294</wfw:commentRss><description>&lt;P&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Calibri','sans-serif';mso-fareast-font-family:Calibri;mso-bidi-font-family:'Times New Roman';mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA;mso-bidi-font-weight:bold;"&gt;&lt;EM&gt;This blog post was written by Ghislain Prince, Product Engineer on the Geoprocessing Team in Redlands.&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Calibri','sans-serif';mso-fareast-font-family:Calibri;mso-bidi-font-family:'Times New Roman';mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA;mso-bidi-font-weight:bold;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Calibri','sans-serif';mso-fareast-font-family:Calibri;mso-bidi-font-family:'Times New Roman';mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Calibri','sans-serif';mso-fareast-font-family:Calibri;mso-bidi-font-family:'Times New Roman';mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA;"&gt;Hi Everybody!&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Calibri','sans-serif';mso-fareast-font-family:Calibri;mso-bidi-font-family:'Times New Roman';mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA;mso-bidi-font-weight:bold;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Calibri','sans-serif';mso-fareast-font-family:Calibri;mso-bidi-font-family:'Times New Roman';mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Calibri','sans-serif';mso-fareast-font-family:Calibri;mso-bidi-font-family:'Times New Roman';mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA;"&gt;&lt;/SPAN&gt;We learned in the Advanced Python Scripting Technical Workshops at UC that many of you who use ArcGIS 9.3 do not yet use the changes we made to the geoprocessor.&amp;nbsp; We just wanted you guys to be aware of this option when writing your Python scripts at 9.3.&amp;nbsp; The 9.3 switch option is specified when the geoprocessor is created; in code it looks like this &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;BLOCKQUOTE&gt;
&lt;BLOCKQUOTE&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Calibri','sans-serif';mso-fareast-font-family:Calibri;mso-bidi-font-family:'Times New Roman';mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA;mso-bidi-font-weight:bold;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Calibri','sans-serif';mso-fareast-font-family:Calibri;mso-bidi-font-family:'Times New Roman';mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier Italic';mso-fareast-font-family:Calibri;mso-bidi-font-family:'Times New Roman';mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA;"&gt;&lt;FONT face="Times New Roman"&gt;import arcgisscripting&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Calibri','sans-serif';mso-fareast-font-family:Calibri;mso-bidi-font-family:'Times New Roman';mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA;mso-bidi-font-weight:bold;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Calibri','sans-serif';mso-fareast-font-family:Calibri;mso-bidi-font-family:'Times New Roman';mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier Italic';mso-fareast-font-family:Calibri;mso-bidi-font-family:'Times New Roman';mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA;"&gt;&lt;FONT face="Times New Roman"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier Italic';mso-fareast-font-family:Calibri;mso-bidi-font-family:'Times New Roman';mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA;"&gt;gp = arcgisscripting.create(9.3)&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;/BLOCKQUOTE&gt;&lt;/BLOCKQUOTE&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Calibri','sans-serif';mso-fareast-font-family:Calibri;mso-bidi-font-family:'Times New Roman';mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA;mso-bidi-font-weight:bold;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Calibri','sans-serif';mso-fareast-font-family:Calibri;mso-bidi-font-family:'Times New Roman';mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier Italic';mso-fareast-font-family:Calibri;mso-bidi-font-family:'Times New Roman';mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA;"&gt;&lt;FONT face="Times New Roman"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Courier Italic';mso-fareast-font-family:Calibri;mso-bidi-font-family:'Times New Roman';mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Calibri','sans-serif';mso-fareast-font-family:Calibri;mso-bidi-font-family:'Times New Roman';mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA;"&gt;Existing (pre-9.3) scripts will obviously not have this option as it didn’t exist before the 9.3 release. We’re sure you’ve already noticed that they continue to work unchanged.&amp;nbsp; To get the 9.3 geoprocessor behavior, it is not enough to simply change &lt;EM&gt;gp = arcgisscripting.create()&lt;/EM&gt; to &lt;EM&gt;gp = arcgisscripting.create(9.3)&lt;/EM&gt;&amp;nbsp; &lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Calibri','sans-serif';mso-fareast-font-family:Calibri;mso-bidi-font-family:'Times New Roman';mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA;"&gt;-&amp;nbsp; that does not work, because your code needs to be &lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/SPAN&gt;updated elsewhere in your script to accommodate the changed behavior.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE:10pt;FONT-FAMILY:'Calibri','sans-serif';mso-fareast-font-family:Calibri;mso-bidi-font-family:'Times New Roman';mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA;mso-bidi-font-weight:bold;"&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Calibri','sans-serif';mso-fareast-font-family:Calibri;mso-bidi-font-family:'Times New Roman';mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA;"&gt;The main goal for this switch is that when you create new scripts in ArcGIS &lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp;&lt;/SPAN&gt;9.3, you will use the “9.3” geoprocessor and get a much nicer coding experience.&amp;nbsp; This “nicer” experience is achieved because the geoprocessor uses more of Python’s native structures as inputs and outputs.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Calibri','sans-serif';mso-fareast-font-family:Calibri;mso-bidi-font-family:'Times New Roman';mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Calibri','sans-serif';mso-fareast-font-family:Calibri;mso-bidi-font-family:'Times New Roman';mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA;"&gt;&lt;A href="http://blogs.esri.com/Dev/photos/geoprocessing/picture7296.aspx" target=_blank&gt;&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Calibri','sans-serif';mso-fareast-font-family:Calibri;mso-bidi-font-family:'Times New Roman';mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA;"&gt;&lt;A href="http://blogs.esri.com/Dev/photos/geoprocessing/picture7298.aspx" target=_blank&gt;&lt;IMG src="http://blogs.esri.com/Dev/photos/geoprocessing/images/7298/578x295.aspx" border=0&gt;&lt;/A&gt;It’s obvious that the improvements to the geoprocessor make it easier for you to write code and resulting code is easier to read and maintain.&amp;nbsp; Of course the changes are not limited to the List functions; here’s the complete list of &lt;A class="" title=differences href="http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=Differences_between_geoprocessor_versions" target=_blank&gt;differences&lt;/A&gt; and a &lt;A class="" title=comparison href="http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=Creating_the_geoprocessor_object&amp;amp;anchor=comparing_93_and_92_geoprocessors" target=_blank&gt;comparison&lt;/A&gt; &lt;SPAN style="FONT-SIZE:11pt;FONT-FAMILY:'Calibri','sans-serif';mso-fareast-font-family:Calibri;mso-bidi-font-family:'Times New Roman';mso-ansi-language:EN-US;mso-fareast-language:EN-US;mso-bidi-language:AR-SA;"&gt;with several code examples.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;img src="http://blogs.esri.com/Dev/aggbug.aspx?PostID=7294" width="1" height="1"&gt;</description><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/Python/default.aspx">Python</category><category domain="http://blogs.esri.com/Dev/blogs/geoprocessing/archive/tags/2009+User+Conference/default.aspx">2009 User Conference</category></item><item><title>2009 Developers Summit</title><link>http://blogs.esri.com/Dev/blogs/geoprocessing/archive/2009/03/25/2009-Developers-Summit.aspx</link><pubDate>Wed, 25 Mar 2009 23:54:00 GMT</pubDate><guid isPermaLink="false">b60b3f0a-e2bd-4be5-8a18-822c697649ab:4302</guid><dc:creator>dmhoneycutt</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.esri.com/Dev/blogs/geoprocessing/comments/4302.aspx</comments><wfw:commentRss>http://blogs.esri.com/Dev/blogs/geoprocessing/commentrss.aspx?PostID=4302</wfw:commentRss><description>&lt;p&gt;The 2009 Developers Summit has come and gone.&amp;nbsp; Thanks to all who attended!&amp;nbsp; We enjoyed meeting with you.&amp;nbsp; We've uploaded the geoprocessing presentations to the Model and Script tool gallery. Session videos have been posted to the Media Gallery.&amp;nbsp; &lt;br&gt;&lt;/p&gt;&lt;p&gt;Slides, scripts, and data from the two workshops on Designing and Building geoprocessing tools are available in the Model and Script tool gallery, or by clicking &lt;a href="http://resources.esri.com/geoprocessing/index.cfm?fa=codeGalleryDetails&amp;amp;scriptID=16168"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;Slides and other materials from the Building Geoprocessing Services session are available &lt;a href="http://resources.esri.com/geoprocessing/index.cfm?fa=codeGalleryDetails&amp;amp;scriptID=16177"&gt;here&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;Slides and scripts for the Python Scripting Advanced Techniques session are available &lt;a href="http://resources.esri.com/geoprocessing/index.cfm?fa=codeGalleryDetails&amp;amp;scriptID=16184"&gt;here&lt;/a&gt;.&amp;nbsp; &lt;br&gt;&lt;/p&gt;&lt;img src="http://blogs.esri.com/Dev/aggbug.aspx?PostID=4302" width="1" height="1"&gt;</description><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/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/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/2009+Developers+Summit/default.aspx">2009 Developers Summit</category><category domain="http://blogs.esri.com/Dev/blogs/geoprocessing/archive/tags/Geoprocessing+services/default.aspx">Geoprocessing services</category><category domain="http://blogs.esri.com/Dev/blogs/geoprocessing/archive/tags/ArcGIS+Server/default.aspx">ArcGIS Server</category></item><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 - accessing feature shape in Calculate Field</title><link>http://blogs.esri.com/Dev/blogs/geoprocessing/archive/2009/03/06/Tips-and-tricks-_2D00_-accessing-feature-shape-in-Calculate-Field.aspx</link><pubDate>Fri, 06 Mar 2009 23:44:00 GMT</pubDate><guid isPermaLink="false">b60b3f0a-e2bd-4be5-8a18-822c697649ab:3997</guid><dc:creator>dmhoneycutt</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.esri.com/Dev/blogs/geoprocessing/comments/3997.aspx</comments><wfw:commentRss>http://blogs.esri.com/Dev/blogs/geoprocessing/commentrss.aspx?PostID=3997</wfw:commentRss><description>&lt;p&gt;With the &lt;a href="http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?id=1737&amp;amp;pid=1733&amp;amp;topicname=Calculate_Field_%28Data_Management%29" target="_blank"&gt;Calculate Field tool&lt;/a&gt;, you can easily create expressions that use 
some property of a feature's shape, such as length or area.  You can also convert 
length and area to different units.  The illustration below shows calculating 
the MILES field to the length (in miles) of each line feature.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.esri.com/Dev/photos/geoprocessing/picture3998.aspx" target="_blank"&gt;&lt;img src="http://blogs.esri.com/Dev/photos/geoprocessing/images/3998/381x447.aspx" border="0"&gt;&lt;/a&gt;&amp;nbsp;&lt;/p&gt;

&lt;h5&gt;Details about the Expression syntax&lt;/h5&gt;

&lt;p&gt;The expression syntax -- 
&lt;font face="courier new, courier, mono"&gt;!shape.length@miles!&lt;/font&gt; -- 
starts and ends with the special 'decode field' character.  
This decode field character is different 
depending on the value of the Expression Type parameter.  For Expression Type 
of PYTHON or PYTHON_9.3, the character is an exclamation point ("!"), as shown 
in the illustration above.  For VB, the decode field characters 
are "[" and "]".&lt;/p&gt;

&lt;p&gt;Inside the decode field characters, you can put the name of any field 
found on the input table.  You can also use the reserved field name "&lt;font face="courier new, courier, mono"&gt;shape&lt;/font&gt;" 
followed by a period and an attribute of the shape.  In this case, we're 
using the length attribute:  &lt;font face="courier new, courier, mono"&gt;!shape.length!&lt;/font&gt;  &lt;/p&gt;

&lt;p&gt;Finally, we convert shape.length to miles with the use of the special 
unit conversion syntax '&lt;font face="courier new, courier, mono"&gt;@&amp;lt;unit&amp;gt;&lt;/font&gt;'.  
 Unit can be any of the following: 
CENTIMETERS | DECIMALDEGREES | DECIMETERS | FEET | INCHES | KILOMETERS | 
METERS | MILES | MILLIMETERS | NAUTICALMILES | POINTS | YARDS.  &lt;/p&gt;

&lt;p&gt;If your shape type is polygon, you can use these areal unit keywords:  
ACRES | ARES | HECTARES | SQUARECENTIMETERS | SQUAREDECIMETERS | SQUAREINCHES | 
SQUAREFEET | SQUAREKILOMETERS | SQUAREMETERS | SQUAREMILES | SQUAREMILLIMETERS | 
SQUAREYARDS&lt;/p&gt;

&lt;h5&gt;More things you can do with the shape object and its attributes&lt;/h5&gt;

&lt;p&gt;The shape field is actually a &lt;a href="http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=The%20geometry%20object" target="_blank"&gt;geometry object&lt;/a&gt; with the following properties.  &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.esri.com/Dev/photos/geoprocessing/images/3999/original.aspx" target="_blank"&gt;&lt;img src="http://blogs.esri.com/Dev/photos/geoprocessing/images/3999/215x271.aspx" border="0"&gt;&lt;/a&gt;&amp;nbsp;&lt;/p&gt;


&lt;p&gt;If, for example, you wanted the X-coordinate of the first point of a line, 
you would use &lt;font face="courier new, courier, mono"&gt;!shape.firstpoint.x!&lt;/font&gt;  
To find the minimum X-coordinate of the line, 
use &lt;font face="courier new, courier, mono"&gt;!shape.extent.xmin!&lt;/font&gt;&lt;/p&gt;

&lt;h5&gt;Simple equations&lt;/h5&gt;
&lt;p&gt;The expression can contain simple equations.  For example, to calculate  
 minutes it would take to traverse a street segment going 30 miles per hour, 
 use:&lt;/p&gt;
 
&lt;p&gt;&lt;font face="courier new, courier, mono"&gt;!shape.length@miles! / (30.0 / 60.0)&lt;/font&gt;&lt;/p&gt;
   
 
&lt;p&gt;&amp;nbsp;Note that:
 &lt;/p&gt;

&lt;p&gt;&lt;font face="courier new, courier, mono"&gt;!shape.length@miles! / (30 / 60)&lt;/font&gt; &lt;/p&gt;
 
&lt;p&gt;won't work - when doing real arithmetic you need the decimal point after 30 and 60.&lt;/p&gt;
&lt;h5&gt;Code blocks&lt;/h5&gt;
&lt;p&gt;See &lt;a href="http://www.esri.com/news/arcuser/0507/files/pythonscript.pdf" target="_blank"&gt;http://www.esri.com/news/arcuser/0507/files/pythonscript.pdf&lt;/a&gt; for information on using code blocks in Calculate Field&lt;br&gt;&lt;/p&gt;&lt;img src="http://blogs.esri.com/Dev/aggbug.aspx?PostID=3997" 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></item><item><title>Tips and tricks - Error handling in Python script tools</title><link>http://blogs.esri.com/Dev/blogs/geoprocessing/archive/2008/12/01/Tips-and-tricks-_2D00_-Error-handling-in-Python-script-tools.aspx</link><pubDate>Mon, 01 Dec 2008 17:43:00 GMT</pubDate><guid isPermaLink="false">b60b3f0a-e2bd-4be5-8a18-822c697649ab:3169</guid><dc:creator>dmhoneycutt</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.esri.com/Dev/blogs/geoprocessing/comments/3169.aspx</comments><wfw:commentRss>http://blogs.esri.com/Dev/blogs/geoprocessing/commentrss.aspx?PostID=3169</wfw:commentRss><description>&lt;p&gt;I recently had a project that involved creating lots of Python script tools.  
Since other people were going to use these tools, I wanted my error handling to 
be robust and informative.  This post is about some tips and tricks I discovered 
during this project.&lt;/p&gt;

&lt;h4&gt;Error handling basics&lt;/h4&gt;
&lt;p&gt;The basics of handling Python errors are covered in the 9.3 help topic 
&lt;a href="http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=Error_handling_with_Python"&gt;Error handling with Python&lt;/a&gt;.  
The Python.org document &lt;a href="http://www.python.org/doc/2.5.2/tut/node10.html#SECTION0010200000000000000000"&gt;Errors and Exceptions&lt;/a&gt; has more detailed information.&lt;/p&gt;

&lt;h4&gt;Tip #1 - Use the arcgisscripting.ExecuteError exception&lt;/h4&gt;
&lt;p&gt;In version 9.2, we introduced the arcgisscripting object along with a new exception class, 
arcgisscripting.ExecuteError.  (This arcgisscripting.ExecuteError exception class wasn't 
documented in version 9.2, so few people knew about it.)&amp;nbsp;
The arcgisscripting.ExecuteError exception is thrown whenever a geoprocessing tool 
or geoprocessing function encounters an error.   What this means is that you can divide errors 
into two groups, 
geoprocessing errors (those that throw the arcgisscripting.ExecuteError exception) and everything else.&amp;nbsp; You can then handle the errors differently, as 
demonstrated in the code below:&lt;/p&gt;

&lt;blockquote&gt;
&lt;pre&gt;&lt;font size="2" face="courier new, courier, mono"&gt;import arcgisscripting&lt;br&gt;gp = arcgisscripting.create(9.3)&lt;br&gt;try:&lt;br&gt;    result = gp.getcount("C:/blah.shp")&lt;br&gt;    &lt;i&gt;&lt;font color="#006600"&gt;# x = y&lt;/font&gt;&lt;/i&gt;&lt;br&gt;        &lt;br&gt;&lt;i&gt;&lt;font color="#006600"&gt;# Return GEOPROCESSING specific errors&lt;br&gt;#&lt;/font&gt;&lt;/i&gt;&lt;br&gt;except arcgisscripting.ExecuteError:&lt;br&gt;    gp.AddError(gp.GetMessages(2))&lt;br&gt;    &lt;br&gt;&lt;i&gt;&lt;font color="#006600"&gt;# Return any PYTHON or system specific errors&lt;br&gt;#&lt;/font&gt;&lt;/i&gt;&lt;br&gt;except:&lt;br&gt;    gp.AddError("Python or system error occurred")&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;
	
&lt;p&gt;The code above is used as the source for a script tool.  To keep things simple, 
the script tool has no parameters.  When the script tool is executed, the call to 
getcount produces an error because the dataset
"C:/blah.shp" doesn't exist.  As a result, the progress dialog
looks as follows:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.esri.com/Dev/photos/geoprocessing/images/3164/original.aspx" target="_blank"&gt;&lt;img src="http://blogs.esri.com/Dev/photos/geoprocessing/images/3164/591x271.aspx" border="0"&gt;&lt;/a&gt;&amp;nbsp;&lt;/p&gt;


&lt;p&gt;To prove how geoprocessing errors and Python errors are handled differently, 
change the two lines of code as follows:&lt;/p&gt;

&lt;pre&gt;&lt;font size="2" face="courier new, courier, mono"&gt;    &lt;i&gt;&lt;font color="#006600"&gt;# result = gp.getcount("C:/blah.shp")&lt;/font&gt;&lt;/i&gt;&lt;br&gt;    x = y&lt;/font&gt;&lt;/pre&gt;

&lt;p&gt;Now when the script is executed, an error will occur because the variable
'y' is undefined, and the progress dialog will display as follows:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.esri.com/Dev/photos/geoprocessing/images/3166/original.aspx" target="_blank"&gt;&lt;img src="http://blogs.esri.com/Dev/photos/geoprocessing/images/3166/591x221.aspx" border="0"&gt;&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;h4&gt;Tip #2 - Beware of getting error messages from a result object&lt;/h4&gt;	
&lt;p&gt;Before moving on, a quick word about the result object, shown below:&lt;/p&gt;

&lt;pre&gt;&lt;font size="2" face="courier new, courier, mono"&gt;    result = gp.getcount("C:/blah.shp")&lt;/font&gt;&lt;/pre&gt;

&lt;p&gt;If the call to getcount above raises an exception, the result object is null.
This means you cannot retrieve error messages from the result object.  For
example:&lt;/p&gt;

&lt;blockquote&gt;
&lt;pre&gt;&lt;font size="2" face="courier new, courier, mono"&gt;import arcgisscripting&lt;br&gt;gp = arcgisscripting.create(9.3)&lt;br&gt;try:&lt;br&gt;    result = gp.getcount("C:/blah.shp")&lt;br&gt;        &lt;br&gt;&lt;i&gt;&lt;font color="#006600"&gt;# Return GEOPROCESSING specific errors&lt;br&gt;# (this method is INCORRECT!)&lt;/font&gt;&lt;/i&gt;&lt;br&gt;except arcgisscripting.ExecuteError:&lt;br&gt;    &lt;b&gt;gp.AddError(result.GetMessages(2))&lt;/b&gt;&lt;br&gt;    &lt;br&gt;&lt;i&gt;&lt;font color="#006600"&gt;# Return any PYTHON or system specific errors&lt;br&gt;#&lt;/font&gt;&lt;/i&gt;&lt;br&gt;except:&lt;br&gt;    gp.AddError("Python or system error occurred")&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;


&lt;p&gt;The above code will fail with the message "name 'result' is not defined".
This is due to the fact that the result object is null.  Since the result
object is null, a Python error will be 
raised since a null object doesn't have a GetMessages() method.  
Note -- a result object created by calling
a &lt;i&gt;geoprocessing service&lt;/i&gt; on an ArcGIS Server is never null.  Null result objects
a created only when a tool is run &lt;i&gt;locally&lt;/i&gt; and it raises an error.&amp;nbsp; For more information about using the result object, see &lt;a href="http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=Getting_results_from_a_geoprocessing_tool"&gt;Getting results from a geoprocessing tool&lt;/a&gt;.&lt;br&gt;&lt;/p&gt;

	
&lt;h4&gt;Tip #3 - Use AddReturnMessage() to preserve links to error codes&lt;/h4&gt;
In version 9.3, geoprocessing error numbers shown in the progress dialog are 
hyperlinks to a help page that further describes the error.  To enable hyperlinks
for errors in your script, you need to use the AddReturnMessage() method instead of the
AddError method, as follows:

&lt;blockquote&gt;
&lt;pre&gt;&lt;font size="2" face="courier new, courier, mono"&gt;import arcgisscripting&lt;br&gt;gp = arcgisscripting.create(9.3)&lt;br&gt;try:&lt;br&gt;    result = gp.getcount("C:\\blah.shp")&lt;br&gt;        &lt;br&gt;&lt;i&gt;&lt;font color="#006600"&gt;# Return GEOPROCESSING specific errors&lt;br&gt;#&lt;/font&gt;&lt;/i&gt;&lt;br&gt;except arcgisscripting.ExecuteError:&lt;br&gt;    &lt;b&gt;for msg in range(0, gp.MessageCount):&lt;br&gt;        if gp.GetSeverity(msg) == 2:&lt;br&gt;            gp.AddReturnMessage(msg)&lt;/b&gt;&lt;br&gt;    &lt;br&gt;&lt;i&gt;&lt;font color="#006600"&gt;# Return any PYTHON or system specific errors&lt;br&gt;#&lt;/font&gt;&lt;/i&gt;&lt;br&gt;except:&lt;br&gt;    gp.AddError("Python or system error occurred")&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;

&lt;p&gt;Now when the script is executed, the progress dialog will look as follows:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.esri.com/Dev/photos/geoprocessing/picture3165.aspx" target="_blank"&gt;&lt;/a&gt;&lt;a href="http://blogs.esri.com/Dev/photos/geoprocessing/images/3165/original.aspx" target="_blank"&gt;&lt;img src="http://blogs.esri.com/Dev/photos/geoprocessing/images/3165/592x224.aspx" border="0"&gt;&lt;/a&gt;&lt;br&gt;&amp;nbsp;&lt;/p&gt;

&lt;h4&gt;Tip #4 -- Use traceback to return more information about the error&lt;br&gt;&lt;/h4&gt;

&lt;p&gt;The help system topic &lt;a href="http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=Error_handling_with_Python"&gt;Error handling with Python&lt;/a&gt; shows you how to use Python's traceback to retrieve the line number causing the error, the name of the .py file,
and, for Python errors, a description of the error.
&lt;/p&gt;

&lt;p&gt;At version 9.3, you can run script tools in-process, as described in &lt;a href="http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=Running_a_script_in_process"&gt;Running a script in process&lt;/a&gt;. Scripts run in-process execute much faster than scripts run out-of-process, so you 
always want to run the script in-process.  When a script is run in-process,
ArcGIS reads the .py file into memory and then executes it.  Because ArcGIS puts
the .py files into memory, the Python traceback module doesn't know the name of the
.py file and will report the file name as "&amp;lt;string&amp;gt;".  If you want to report 
the name of the .py file causing the error (very useful for debugging), you'll have to provide it yourself.
&lt;/p&gt;

&lt;p&gt;The script below has a local routine, trace(), that uses traceback to return the
line number, the file name, and the error description. The routine also contains
the the hard-coded file name (shown in bold) which you must change for your script.&lt;/p&gt;

&lt;blockquote&gt;
&lt;pre&gt;&lt;font size="2" face="courier new, courier, mono"&gt;import arcgisscripting&lt;br&gt;gp = arcgisscripting.create(9.3)&lt;br&gt;try:&lt;br&gt;    def trace():&lt;br&gt;        import os, sys, traceback&lt;br&gt;        tb = sys.exc_info()[2]&lt;br&gt;        tbinfo = traceback.format_tb(tb)[0]  # script name + line number&lt;br&gt;        line = tbinfo.split(", ")[1]&lt;br&gt;        &lt;br&gt;        &lt;i&gt;&lt;font color="#006600"&gt;# Construct the pathname to this script.  Get the pathname&lt;br&gt;        #  to the folder containing the script using sys.path[0]. &lt;br&gt;        #  Modify line below and replace 'myscript.py' with the name of&lt;br&gt;        #  this script. &lt;br&gt;        #&lt;/font&gt;&lt;/i&gt;&lt;br&gt;        filename = sys.path[0] + os.sep + &lt;b&gt;"myscript.py"&lt;/b&gt;&lt;br&gt;        &lt;br&gt;        &lt;i&gt;&lt;font color="#006600"&gt;# Get Python syntax error&lt;br&gt;        #&lt;/font&gt;&lt;/i&gt;&lt;br&gt;        synerror = traceback.format_exc().splitlines()[-1]&lt;br&gt;        return line, filename, synerror&lt;br&gt;    if __name__ == '__main__':  &lt;br&gt;        &lt;i&gt;&lt;font color="#006600"&gt;# y = x&lt;/font&gt;&lt;/i&gt;&lt;br&gt;        result = gp.getcount("C:/blah.shp")&lt;br&gt;        &lt;br&gt;except arcgisscripting.ExecuteError:&lt;br&gt;    &lt;i&gt;&lt;font color="#006600"&gt;# Call our trace routine to retrieve line number and filename.&lt;br&gt;    #  (returned variable 'err' is ignored since this is a gp error.&lt;br&gt;    #&lt;/font&gt;&lt;/i&gt;&lt;br&gt;    &lt;b&gt;line, filename, err = trace()&lt;/b&gt;&lt;br&gt;    gp.AddError("Geoprocessing error on " + line + " of " + filename + " :")&lt;br&gt;    for msg in range(0, gp.MessageCount):&lt;br&gt;        if gp.GetSeverity(msg) == 2:&lt;br&gt;            gp.AddReturnMessage(msg)&lt;br&gt;    &lt;br&gt;except:&lt;br&gt;    &lt;b&gt;line, filename, err = trace()&lt;/b&gt;&lt;br&gt;    gp.AddError("Python error on " + line + " of " + filename)&lt;br&gt;    gp.AddError(err)&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;


&lt;p&gt;Below are illustrations of the progress dialog showing the line number
and file name for both a geoprocessing error and a Python syntax error (by commenting out
the "y = x" statement).&lt;/p&gt;

&lt;p&gt;&amp;nbsp;&lt;a href="http://blogs.esri.com/Dev/photos/geoprocessing/images/3167/original.aspx" target="_blank"&gt;&lt;img src="http://blogs.esri.com/Dev/photos/geoprocessing/images/3167/640x222.aspx" border="0"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&amp;nbsp;&lt;a href="http://blogs.esri.com/Dev/photos/geoprocessing/images/3168/original.aspx" target="_blank"&gt;&lt;img src="http://blogs.esri.com/Dev/photos/geoprocessing/images/3168/640x226.aspx" border="0"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;Tip #5 -- Use Finally statement to clean up cursors&lt;br&gt;&lt;/h4&gt;
&lt;p&gt;Something I discovered by reading the Python doc &lt;a href="http://www.python.org/doc/2.5.2/tut/node10.html#SECTION0010200000000000000000"&gt;Errors and Exceptions&lt;/a&gt;
is the 'finally' statement.  No matter what happens in your Python script, code 
in a 'finally:' block always gets executed.  It's a great place to put clean-up 
actions, such as deleting cursors, as shown in the code below.  &lt;/p&gt;


&lt;blockquote&gt;&lt;pre&gt;&lt;font size="2" face="courier new, courier, mono"&gt;import arcgisscripting&lt;br&gt;gp = arcgisscripting.create(9.3)&lt;br&gt;&lt;br&gt;def trace():&lt;br&gt;    import os, sys, traceback&lt;br&gt;    tb = sys.exc_info()[2]&lt;br&gt;    tbinfo = traceback.format_tb(tb)[0] &lt;br&gt;    line = tbinfo.split(", ")[1]&lt;br&gt;    filename = sys.path[0] + os.sep + "testscript.py"&lt;br&gt;    synerror = traceback.format_exc().splitlines()[-1]&lt;br&gt;    return line, filename, synerror&lt;br&gt;&lt;br&gt;if __name__ == '__main__':&lt;br&gt;    &lt;i&gt;&lt;font color="#006600"&gt;# Define variables for a cursor and its row&lt;br&gt;    #&lt;/font&gt;&lt;/i&gt;&lt;br&gt;    &lt;b&gt;cursor, row = None, None&lt;/b&gt;&lt;br&gt;    try:&lt;br&gt;        cursor = gp.searchcursor("E:/Data/CityOfSanFrancisco.gdb/FireStations")&lt;br&gt;        row = cursor.Next()&lt;br&gt;        while row:&lt;br&gt;          &lt;i&gt;&lt;font color="#006600"&gt;# Code here...&lt;br&gt;          # for demonstration...this next statement will cause an error&lt;/font&gt;&lt;/i&gt;&lt;br&gt;          y = x&lt;br&gt;          row = cursor.Next()&lt;br&gt;    except arcgisscripting.ExecuteError:&lt;br&gt;        line, filename, err = trace()&lt;br&gt;        gp.AddError("Geoprocessing error on " + line + " of " + filename + " :")&lt;br&gt;        for msg in range(0, gp.MessageCount):&lt;br&gt;            if gp.GetSeverity(msg) == 2:&lt;br&gt;                gp.AddReturnMessage(msg)&lt;br&gt;    except:&lt;br&gt;        line, filename, err = trace()&lt;br&gt;        gp.AddError("Python error on " + line + " of " + filename)&lt;br&gt;        gp.AddError(err)&lt;br&gt;    &lt;b&gt;finally:&lt;/b&gt;&lt;br&gt;        &lt;i&gt;&lt;font color="#006600"&gt;# Close cursor and row objects.&lt;br&gt;        #&lt;/font&gt;&lt;/i&gt;&lt;br&gt;        &lt;b&gt;del row, cursor&lt;/b&gt;&lt;br&gt;            &lt;br&gt;        &lt;i&gt;&lt;font color="#006600"&gt;# Print a message for demo purposes&lt;br&gt;        #&lt;/font&gt;&lt;/i&gt;&lt;br&gt;        gp.AddMessage("\n   ** Cursor and row have been deleted ** \n")&lt;/font&gt;&lt;/pre&gt;&lt;/blockquote&gt;
	  
&lt;p&gt;As illustrated below, the cursor gets deleted even if there is an error in
the script.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.esri.com/Dev/photos/geoprocessing/images/3163/original.aspx" target="_blank"&gt;&lt;/a&gt;&lt;a href="http://blogs.esri.com/Dev/photos/geoprocessing/images/3163/original.aspx" target="_blank"&gt;&lt;img src="http://blogs.esri.com/Dev/photos/geoprocessing/images/3163/640x242.aspx" border="0"&gt;&lt;/a&gt;&lt;br&gt;&lt;/p&gt;

&lt;p&gt;In the main body of the script, the cursor and row object variables are declared and initialized to None (shown in bold in the above code).&amp;nbsp; This ensures that these two variables exist when the del statement in the finally clause is executed; if you try to delete a non-existent variable, an exception will be thrown.&amp;nbsp;&amp;nbsp; &lt;br&gt;&lt;/p&gt;

&lt;h5&gt;About cursors and the del statement&lt;/h5&gt;

&lt;p&gt;The Python &lt;a href="http://www.python.org/doc/2.5.2/ref/del.html"&gt;del statement&lt;/a&gt; deletes a variable.  You can use it to delete any
Python variable, such as a list or dictionary.  However, you rarely need to delete native Python
variables.&amp;nbsp; The del statement is mainly used for deleting non-native
variables, such as geoprocessing cursors and rows obtained from the cursor.  When you delete a cursor and its row, all pending changes to the row (caused by an update or insert cursor) are flushed and all locks on the dataset are removed.&amp;nbsp; &lt;i&gt;You should always delete cursors and rows obtained from the cursor.&lt;/i&gt;&amp;nbsp; When deleting a cursor, delete the row object first, then the cursor.&lt;/p&gt;

&lt;span style="font-weight:bold;"&gt;&lt;br&gt;&lt;/span&gt;&lt;img src="http://blogs.esri.com/Dev/aggbug.aspx?PostID=3169" width="1" height="1"&gt;</description><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/Tips+and+tricks/default.aspx">Tips and tricks</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><item><title>Tips and Tricks - Debugging Python script tools</title><link>http://blogs.esri.com/Dev/blogs/geoprocessing/archive/2008/09/01/Tips-and-Tricks-_2D00_-Debugging-Python-script-tools.aspx</link><pubDate>Mon, 01 Sep 2008 22:02:00 GMT</pubDate><guid isPermaLink="false">b60b3f0a-e2bd-4be5-8a18-822c697649ab:2573</guid><dc:creator>dmhoneycutt</dc:creator><slash:comments>4</slash:comments><comments>http://blogs.esri.com/Dev/blogs/geoprocessing/comments/2573.aspx</comments><wfw:commentRss>http://blogs.esri.com/Dev/blogs/geoprocessing/commentrss.aspx?PostID=2573</wfw:commentRss><description>&lt;p&gt;If you create your own script tools using Python, you'll appreciate these tips 
and tricks on debugging.&lt;/p&gt;

&lt;p&gt;Coding errors are inevitable and there are two basic ways to find out where the 
error occurred:&lt;/p&gt;

&lt;ol&gt;- Add some form of print statements to your code that help you isolate the problem.&lt;br&gt;
- Use an interactive debugger.&lt;/ol&gt;

&lt;p&gt;Using print statements to discover bugs is an obvious and common method.  Since script 
tools have access to the tool progress dialog, you can edit your script to include 
calls to AddMessage(), AddWarning(), or AddError() to print values and checkpoint 
messages to the progress dialog.  Another variation is to use an independent method 
of returning messages, like the win32ui module's MessageBox method.  This method 
displays a popup dialog.  Since you have to click OK on the dialog to continue 
execution, this method allows you to pace the execution of the script.  Here's an 
example using both methods:
&lt;/p&gt;

&lt;blockquote&gt;
&lt;pre&gt;&lt;font size="2" face="courier new, courier, mono"&gt;import arcgisscripting, win32ui, win32con&lt;br&gt;gp = arcgisscripting.create()&lt;br&gt;n = 5&lt;br&gt;&lt;br&gt;# Print message to progress dialog&lt;br&gt;#&lt;br&gt;gp.AddMessage("Value of n = " + str(n))&lt;br&gt;&lt;br&gt;# Issue a popup dialog with OK and Cancel button&lt;br&gt;#&lt;br&gt;val = win32ui.MessageBox("Value of n = " + str(n), "title", win32con.MB_OKCANCEL)&lt;br&gt;&lt;br&gt;# Based on the button clicked, you can branch execution&lt;br&gt;#&lt;br&gt;if val == 1:&lt;br&gt;    gp.AddMessage("You clicked OK")&lt;br&gt;else:&lt;br&gt;    gp.AddError("You clicked Cancel")&lt;br&gt;    raise arcgisscripting.ExecuteError, "Execution stops due to Cancel button click"&lt;br&gt;&lt;br&gt;gp.AddMessage("This statement reached")&lt;br&gt;&lt;/font&gt;&lt;br&gt;&lt;/pre&gt;
&lt;/blockquote&gt;


&lt;p&gt;The other method is to use a Python IDE (Integrated Development Environment) 
that supports debugging, such as:&lt;/p&gt;

&lt;ol&gt;- Python IDE that is installed with Python&lt;br&gt;
- PythonWin, available on the web at &lt;a href="https://sourceforge.net/projects/pywin32"&gt;https://sourceforge.net/projects/pywin32&lt;/a&gt;&lt;br&gt;
- Commercial systems, such as Wing IDE (&lt;a href="http://wingware.com/"&gt;http://wingware.com&lt;/a&gt;)&lt;/ol&gt;


&lt;p&gt;Debuggers allow you to set breakpoints, step in, out, and over individual lines 
of code, and examine the contents of variables, all without modifying your code.  
Compared to inserting print statements, debuggers are much more efficient and 
usually allow you to quickly isolate your bug.&amp;nbsp; The illustration below shows how to use debug mode in PythonWin.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.esri.com/Dev/photos/geoprocessing/picture2576.aspx" target="_blank"&gt;&lt;img src="http://blogs.esri.com/Dev/photos/geoprocessing/images/2576/450x341.aspx" border="0"&gt;&lt;/a&gt;&amp;nbsp;&lt;/p&gt;

&lt;p&gt;One way to use a debugger is to open your script directly in your IDE, modify 
it so that all parameters have values, and then proceed with debugging.  This works 
reasonably well in simple cases.  However, if your script uses layer or table view 
parameters, these variables need created on the fly.  Complex parameters like a 
Field Map or Spatial Reference are hard to create as variables. &lt;/p&gt;

&lt;p&gt;Ideally, you'd like to be able to open your script tool dialog, enter parameters, 
and then have the Python IDE launch with your code ready to be debugged.  You can 
do this with a few simple changes,&amp;nbsp; described below.&lt;/p&gt;

&lt;h4&gt;Use GetParameterAsText()&lt;/h4&gt;

&lt;p&gt;The first step is to modify your script so that it used GetParameterAsText() 
instead of sys.argv[], as discussed in &lt;a href="http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=Understanding_script_tool_parameters" target="_blank"&gt;Understanding script tool parameters&lt;/a&gt;&lt;br&gt;&lt;/p&gt;

&lt;p&gt;This is a modification you can keep - there is no need to change your code 
back to using sys.argv[]. 
&lt;/p&gt;
&lt;h4&gt;Create a .bat file that launches your IDE with your .py as an argument&lt;/h4&gt;
&lt;p&gt;The next step is to create a one-line batch file that will be the source of 
your script tool (instead of your .py file).  This single line contains the pathname 
to your IDE plus the full path to the .py file, as illustrated below.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.esri.com/Dev/photos/geoprocessing/picture2571.aspx" target="_blank"&gt;&lt;img src="http://blogs.esri.com/Dev/photos/geoprocessing/images/2571/505x124.aspx" border="0"&gt;&lt;/a&gt;&amp;nbsp;&lt;/p&gt;


&lt;p&gt;Below are 3 examples of how to set your batch (.bat) file for commonly used IDEs.  
You'll need to confirm that the path is correct for your computer.  Other debuggers 
are of course valid options, and can be called in a similar fashion.&lt;/p&gt;

&lt;i&gt;Python IDLE&lt;/i&gt;&lt;br&gt;
&lt;font face="courier new, courier, mono"&gt;"C:\Python25\pythonw.exe" "C:\Python25\Lib\idlelib\idle.pyw" "C:\mytools\myscript.py"&lt;/font&gt;&lt;br&gt;
&lt;br&gt;
&lt;i&gt;PythonWin&lt;/i&gt;&lt;br&gt;
&lt;font face="courier new, courier, mono"&gt;"C:\Python25\Lib\site-packages\pythonwin\Pythonwin.exe" "C:\mytools\myscript.py"&lt;/font&gt;&lt;br&gt;
&lt;br&gt;
&lt;i&gt;Wing IDE 2.1&lt;/i&gt;&lt;br&gt;
&lt;font face="courier new, courier, mono"&gt;"C:\Program Files\Wing IDE 2.1\bin\wing.exe" "C:\mytools\myscript.py"&lt;/font&gt;&lt;br&gt;
&lt;h4&gt;Reset script tool path to the .bat file&lt;/h4&gt;
&lt;p&gt;The next step is to change your script tool properties to use this new batch file.  
In the ArcToolbox window, right-click your script tool and click Properties.  
Click the Source tab and change the script file to be the new .bat file you created, as illustrated below.  
Click OK.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.esri.com/Dev/photos/geoprocessing/picture2572.aspx" target="_blank"&gt;&lt;/a&gt;&lt;a href="http://blogs.esri.com/Dev/photos/geoprocessing/picture2572.aspx" target="_blank"&gt;&lt;img src="http://blogs.esri.com/Dev/photos/geoprocessing/images/2572/328x193.aspx" border="0"&gt;&lt;/a&gt;&lt;br&gt;&amp;nbsp;&lt;/p&gt;

&lt;h4&gt;Execute and debug your tool&lt;/h4&gt;
&lt;p&gt;Now you can open the script tool from the ArcToolbox window, enter the parameters, 
and click OK.  Shortly afterwards, the debugging application specified in your batch 
file will open with your Python script displayed.  At this point, you are free to interact 
with the debugging application as you would normally.  You can set a breakpoint and
let the script run to the breakpoint and use any other options the debugger allows.  
Parameter values you entered in the dialog will get picked up by GetParameterAsText().&lt;/p&gt;

&lt;p&gt;When running the script, any interaction you would normally expect between the script 
and the application will still occur.  So, if you're using methods like AddMessage(), 
AddWarning(), or AddError(), these messages will show up in the application.  If you are 
using progressor methods (new at 9.3), the progressor will be updated in the tool 
dialog as you walk through your script.  Once the script is finished, you can return 
back to the application by closing your debugger.  
&lt;/p&gt;

&lt;h4&gt;Reset the script tool source&lt;/h4&gt;
&lt;p&gt;Once you have fixed your bugs, you can reset the source to the script file from 
the .bat file back to the .py file.&lt;/p&gt;

&lt;br&gt;
&lt;p&gt;Looking ahead to future releases, we will have integrated options that will 
make this process smoother.  But for now, and with a few little tricks, you can 
easily perform your script tool debugging.&lt;/p&gt;&lt;img src="http://blogs.esri.com/Dev/aggbug.aspx?PostID=2573" width="1" height="1"&gt;</description><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/script+tools/default.aspx">script tools</category><category domain="http://blogs.esri.com/Dev/blogs/geoprocessing/archive/tags/Python/default.aspx">Python</category></item></channel></rss>