﻿{"id":8524,"date":"2019-04-11T04:41:15","date_gmt":"2019-04-11T02:41:15","guid":{"rendered":"http:\/\/www.sigterritoires.fr\/?p=8524"},"modified":"2019-04-11T07:41:41","modified_gmt":"2019-04-11T05:41:41","slug":"arcgis-and-python-2-for-a-good-start","status":"publish","type":"post","link":"https:\/\/www.sigterritoires.fr\/index.php\/en\/arcgis-and-python-2-for-a-good-start\/","title":{"rendered":"ArcGis and Python (2 ): for a good start"},"content":{"rendered":"\n<p>Have you decided to get started? It&rsquo;s time to put all the assets on your\nside . It&rsquo;s already enough complicated to learn a new language, it is useless\nto add pitfalls! This is a checklist and a few tips to start smoothly. Firstly\n, if you are accustomed to program and Python or another language leaves you\ncompletely indifferent , just take a look at the few traps described below and tackle\ndown the Python tutorial of your choice . <\/p>\n\n\n\n<p>On the other side, &nbsp;if you back\noff, start by convincing yourself that it is not necessary to master Python in\norder to use it for our tasks with ArcGis. It is quite possible to link the\nprocessing in a Python script by only knowing the basics of the language . <\/p>\n\n\n\n<!--more-->\n\n\n\n<p><strong>Get<\/strong> <strong>rid<\/strong> <strong>of the<\/strong> <strong>syntax<\/strong> \n\nFirstly, &nbsp;we will rely on the predictive code features\nby using the Python console or an integrated development environment . This allows\nyou to have the exact syntax without having to know them by heart . &nbsp;\n\n\n\n<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"630\" height=\"494\" data-attachment-id=\"8525\" data-permalink=\"https:\/\/www.sigterritoires.fr\/index.php\/en\/arcgis-and-python-2-for-a-good-start\/111-6\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2019\/04\/111.png?fit=630%2C494&amp;ssl=1\" data-orig-size=\"630,494\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"111\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2019\/04\/111.png?fit=630%2C494&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2019\/04\/111.png?resize=630%2C494&#038;ssl=1\" alt=\"\" class=\"wp-image-8525\" srcset=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2019\/04\/111.png?w=630&amp;ssl=1 630w, https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2019\/04\/111.png?resize=300%2C235&amp;ssl=1 300w\" sizes=\"auto, (max-width: 630px) 100vw, 630px\" \/><\/figure>\n\n\n\n<p>If you have not, yet, &nbsp;read our article\n<a href=\"https:\/\/translate.google.com\/translate?hl=fr&amp;prev=_t&amp;sl=fr&amp;tl=en&amp;u=http:\/\/www.sigterritoires.fr\/index.php\/arcgis-et-python-avant-de-faire-vos-premiers-pas\/\">ArcGis and Python before making your first steps<\/a> &nbsp;please read it to understand the difference\nbetween python consoles that allows you to write and execute a single command\nline at a time, and the scripts publishers. <\/p>\n\n\n\n<p>In ArcGis you have installed by default, the Python Console. On the\nother side, &nbsp;you have no integrated development\nenvironment by default . Therefore, you will have to install one . On the\nArcGis installation support you have PythonWin . You can install it from ArrGis\nsupport. If you do not have the support at hand, you can install it from <a href=\"https:\/\/translate.google.com\/translate?hl=fr&amp;prev=_t&amp;sl=fr&amp;tl=en&amp;u=http:\/\/sourceforge.net\/projects\/pywin32\/\">this<\/a> <a href=\"https:\/\/translate.google.com\/translate?hl=fr&amp;prev=_t&amp;sl=fr&amp;tl=en&amp;u=http:\/\/sourceforge.net\/projects\/pywin32\/\">address<\/a> . <\/p>\n\n\n\n<p>Using an IDE provides you with: <\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>An editor with code completion <\/li><li>The syntax highlighting <\/li><li>Codes of models <\/li><li>A code explorer for functions and classes <\/li><li>Testing tools and debugging scripts <\/li><\/ul>\n\n\n\n<p>Here we will install another IDE, PyScripter . You can download it at <a href=\"https:\/\/translate.google.com\/translate?hl=fr&amp;prev=_t&amp;sl=fr&amp;tl=en&amp;u=https:\/\/code.google.com\/p\/pyscripter\/\">this<\/a> <a href=\"https:\/\/translate.google.com\/translate?hl=fr&amp;prev=_t&amp;sl=fr&amp;tl=en&amp;u=https:\/\/code.google.com\/p\/pyscripter\/\">address<\/a> . <br>\nWhy this one? Because you have to choose one and when using them, they are all quite\nsimilar . By cons it is easier find the first big problem. Do you do not rush when\ndownloading the pages ! Read the following lines &#8230; <\/p>\n\n\n\n<p><strong>32<\/strong> <strong>or64 bit ???<\/strong> <\/p>\n\n\n\n<p>If you have a 32-bit machine, no problem. You can only use 32-bit\nsoftware versions . <br>\nBy cons, if you have a 64-bit machine, depending on the installations chosen you\ncan you find, for a same software, versions 32 or 64. For example Python! And\nwhen you go to the download page for PyScripter or PythonWin , the first thing\nyou have to do is to choose between the 32 or 64 bits. As it is ArcGis that installs\nPython, in general you do not know which version you have . Yes, because for\nArcGIS Desktop the normally installed version, even on a 64-bit machine, is the\nPython 32-bit version! By cons, if you install the 64-bit, ArcGis will install\nthe Python 64-bit version &#8230; <\/p>\n\n\n\n<p>So which version do I have? <br>\nOpen ArcMap, click the Python Console button, and enter both lines following : <strong><em>import<\/em><\/strong><strong><em>sys<\/em><\/strong><br><strong><em>print (<\/em><\/strong><strong><em>sys.version<\/em><\/strong><strong><em>)<\/em><\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"630\" height=\"80\" data-attachment-id=\"8526\" data-permalink=\"https:\/\/www.sigterritoires.fr\/index.php\/en\/arcgis-and-python-2-for-a-good-start\/112-7\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2019\/04\/112-1.png?fit=630%2C80&amp;ssl=1\" data-orig-size=\"630,80\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"112\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2019\/04\/112-1.png?fit=630%2C80&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2019\/04\/112-1.png?resize=630%2C80&#038;ssl=1\" alt=\"\" class=\"wp-image-8526\" srcset=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2019\/04\/112-1.png?w=630&amp;ssl=1 630w, https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2019\/04\/112-1.png?resize=300%2C38&amp;ssl=1 300w\" sizes=\"auto, (max-width: 630px) 100vw, 630px\" \/><\/figure>\n\n\n\n<p>\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nThen,\nyou will see not only if it is 32 or 64 bits, but also the version number\n(2.7.x). You will need , if you install PyScrypter , at launching &nbsp;time because if you start with the default\noption, it will use the latest available version of Python (3.4). On the other\nside for ArcGis you must, absolutely, use version 2.7 &nbsp;&nbsp;\n\n\n\n<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"286\" height=\"378\" data-attachment-id=\"8527\" data-permalink=\"https:\/\/www.sigterritoires.fr\/index.php\/en\/arcgis-and-python-2-for-a-good-start\/113-6\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2019\/04\/113.png?fit=286%2C378&amp;ssl=1\" data-orig-size=\"286,378\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"113\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2019\/04\/113.png?fit=286%2C378&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2019\/04\/113.png?resize=286%2C378&#038;ssl=1\" alt=\"\" class=\"wp-image-8527\" srcset=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2019\/04\/113.png?w=286&amp;ssl=1 286w, https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2019\/04\/113.png?resize=227%2C300&amp;ssl=1 227w\" sizes=\"auto, (max-width: 286px) 100vw, 286px\" \/><\/figure>\n\n\n\n<p>For the curious who want to know why , here is a link <a href=\"https:\/\/translate.google.com\/translate?hl=fr&amp;prev=_t&amp;sl=fr&amp;tl=en&amp;u=https:\/\/wiki.python.org\/moin\/Python2orPython3\">Python page<\/a> . <\/p>\n\n\n\n<p>Now you have all the necessary information to download your IDE and to\nbe able to run it for ArcGis. <\/p>\n\n\n\n<p><strong>How to<\/strong> <strong>proceed<\/strong> <strong>with<\/strong> <strong>your<\/strong> <strong>IDE?<\/strong> \n\nWhen you open PyScripter you have the following interface:\n&nbsp;&nbsp;\n\n\n\n<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"630\" height=\"449\" data-attachment-id=\"8528\" data-permalink=\"https:\/\/www.sigterritoires.fr\/index.php\/en\/arcgis-and-python-2-for-a-good-start\/114-5\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2019\/04\/114.png?fit=630%2C449&amp;ssl=1\" data-orig-size=\"630,449\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"114\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2019\/04\/114.png?fit=630%2C449&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2019\/04\/114.png?resize=630%2C449&#038;ssl=1\" alt=\"\" class=\"wp-image-8528\" srcset=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2019\/04\/114.png?w=630&amp;ssl=1 630w, https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2019\/04\/114.png?resize=300%2C214&amp;ssl=1 300w\" sizes=\"auto, (max-width: 630px) 100vw, 630px\" \/><\/figure>\n\n\n\n<p>The goal is to describe a script that will be executed in ArcGis. The\nscript, the succession of code lines of linking the different operations and processes\n, will be written in the main window. <\/p>\n\n\n\n<p>The bottom window corresponds to the Python console. It allows you to\nenter a code line and run it immediately . This allows you to test the code\nbefore adding it in the main window. <\/p>\n\n\n\n<p>Once completed and validated , you will include the script in the ArcGis\nToolbox or you will create an ArcGis add-in. Theoretically, &nbsp;PyScripter will only be used during the\ndevelopment phase of the script. <\/p>\n\n\n\n<p><strong>Save<\/strong> <strong>time:<\/strong> <strong>Get<\/strong> <strong>the<\/strong> <strong>code<\/strong> <strong>samples<\/strong> \n\nOnce you have found which tool you want to use, go\nto ArcGIS support and type the name of the tool . In a previous article, we have\nused, as example, the FeatureToLine tool . Here is what is find at the bottom\nof the tool support page (and this is true for all tools):\n\n\n\n<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"630\" height=\"368\" data-attachment-id=\"8529\" data-permalink=\"https:\/\/www.sigterritoires.fr\/index.php\/en\/arcgis-and-python-2-for-a-good-start\/115-5\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2019\/04\/115.png?fit=630%2C368&amp;ssl=1\" data-orig-size=\"630,368\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"115\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2019\/04\/115.png?fit=630%2C368&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2019\/04\/115.png?resize=630%2C368&#038;ssl=1\" alt=\"\" class=\"wp-image-8529\" srcset=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2019\/04\/115.png?w=630&amp;ssl=1 630w, https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2019\/04\/115.png?resize=300%2C175&amp;ssl=1 300w\" sizes=\"auto, (max-width: 630px) 100vw, 630px\" \/><\/figure>\n\n\n\n<p>You have always a line example command with all the options and that a\nlittle script or one can see how to include this tool in a real script. Do not\nhesitate to \u00ab\u00a0inspire\u00a0\u00bb by copying and pasting the examples. <\/p>\n\n\n\n<p><strong>A few<\/strong> <strong>specifics<\/strong> <strong>of Python for ArcGis<\/strong> <\/p>\n\n\n\n<p>Here are a few items you will not find in books or classic Python\ntutorials . <\/p>\n\n\n\n<p>1- In order for your script to use ArcGis tools , start all your scripts\nwith the line <\/p>\n\n\n\n<p><strong><em>arcpy<\/em><\/strong> <strong><em>import<\/em><\/strong> <\/p>\n\n\n\n<p>2- ArcGis tools respect a Rule name strict <\/p>\n\n\n\n<p><strong>arcpy<\/strong> <strong>.<\/strong> &nbsp;&nbsp; <em>the<\/em> <em>name\nof<\/em> <em>the tool<\/em> &nbsp; <strong>_<\/strong> &nbsp; <em>the name of the toolbox that<\/em>\n<em>contains it<\/em> <\/p>\n\n\n\n<p>For example &nbsp; <strong><em>arcpy.FeatureToLine<\/em><\/strong> <strong><em>_management<\/em><\/strong>\n<\/p>\n\n\n\n<p>3-In the tool syntax display, its settings are displayed in brackets . If\nthe parameter is mandatory he will be surrounded by <strong>&lt;&gt;<\/strong> , if he is optional\nby <strong>{}<\/strong> . If the tool has multiple settings optional and you want , for\nexample , to inform the fourth parameter optional , you are obliged to inform\nthe three previous ones , even with chains empty . <\/p>\n\n\n\n<p>4-Be careful with the file paths. If you use <strong>\\<\/strong> in the paths ,\nthat will be a problem because Python uses this symbol in her syntax . You can opt\nby <strong>\/<\/strong> instead of <strong>\\<\/strong> ( <strong>\u00ab\u00a0C: \/<\/strong> <strong>ArcGIS \/ Data\u00a0\u00bb)<\/strong>\nor you can double <strong>\\\\<\/strong> in the paths ( <strong>\u00ab\u00a0C; \\\\ ArcGis \\\\ Data\u00a0\u00bb<\/strong>\n). You can also to precede the chain containing a file path with <strong>r<\/strong> ( <strong>r<\/strong>\n<strong>\u00ab\u00a0C<\/strong> <strong>; \\ ArcGis \\ Data\u00a0\u00bb<\/strong> ). <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Have you decided to get started? It&rsquo;s time to put all the assets on your side . It&rsquo;s already enough complicated to learn a new language, it is useless to add pitfalls! This is a checklist&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"give_campaign_id":0,"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"sfsi_plus_gutenberg_text_before_share":"","sfsi_plus_gutenberg_show_text_before_share":"","sfsi_plus_gutenberg_icon_type":"","sfsi_plus_gutenberg_icon_alignemt":"","sfsi_plus_gutenburg_max_per_row":"","_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[1260],"tags":[],"class_list":["post-8524","post","type-post","status-publish","format-standard","hentry","category-non-classe-en"],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p6XU0A-2du","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.sigterritoires.fr\/index.php\/wp-json\/wp\/v2\/posts\/8524","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sigterritoires.fr\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sigterritoires.fr\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sigterritoires.fr\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sigterritoires.fr\/index.php\/wp-json\/wp\/v2\/comments?post=8524"}],"version-history":[{"count":0,"href":"https:\/\/www.sigterritoires.fr\/index.php\/wp-json\/wp\/v2\/posts\/8524\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sigterritoires.fr\/index.php\/wp-json\/wp\/v2\/media?parent=8524"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sigterritoires.fr\/index.php\/wp-json\/wp\/v2\/categories?post=8524"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sigterritoires.fr\/index.php\/wp-json\/wp\/v2\/tags?post=8524"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}