{"id":153702,"date":"2019-02-07T08:47:33","date_gmt":"2019-02-07T16:47:33","guid":{"rendered":"https:\/\/www.esri.com\/about\/newsroom\/?post_type=arcuser&#038;p=153702"},"modified":"2024-09-27T16:34:26","modified_gmt":"2024-09-27T23:34:26","slug":"avoid-gui-headaches","status":"publish","type":"arcuser","link":"https:\/\/www.esri.com\/about\/newsroom\/arcuser\/avoid-gui-headaches","title":{"rendered":"Avoid GUI Headaches"},"author":1432,"featured_media":0,"menu_order":0,"template":"","format":"standard","meta":{"_acf_changed":false,"sync_status":"","episode_type":"","audio_file":"","podmotor_file_id":"","podmotor_episode_id":"","castos_file_data":"","cover_image":"","cover_image_id":"","duration":"","filesize":"","filesize_raw":"","date_recorded":"","explicit":"","block":"","itunes_episode_number":"","itunes_title":"","itunes_season_number":"","itunes_episode_type":"","_links_to":"","_links_to_target":""},"categories":[10382],"tags":[295842,283122,201052],"arcuser_issues":[194992],"class_list":["post-153702","arcuser","type-arcuser","status-publish","format-standard","hentry","category-esri-technology","tag-arcpy","tag-geoprocessing","tag-python","arcuser_issues-spring-2013"],"acf":{"short_description":"Sometimes the repetitive nature of a task can make using a tool dialogtime-consuming and inefficient.","pdf":{"host_remotely":false,"file":153732,"file_url":""},"flexible_content":[{"acf_fc_layout":"content","content":"<h2>A case for scripting geoprocessing tools<\/h2>\r\nSometimes the repetitive nature of a task can make using a tool dialogtime-consuming and inefficient.\r\n\r\nOne example would be selecting a large number of fields for the Statistics Field(s) parameter of the Summary Statistics (Analysis) tool. With this parameter, you select fields from the input table that you want to summarize on (e.g., calculate the mean or sum of a numeric field). While this interaction for a single field is quick and easy, imagine if you had to do this for hundreds of fields in a demographic dataset. Repeatedly picking a single field and the corresponding statistic is time-consuming, inefficient, and frustrating.\r\n\r\nLuckily there is more than one way to run a geoprocessing tool. One of those\u2014Python scripting\u2014is a very good way to make repetitive tasks easy. Let's consider how Python scripting can accomplish the task of getting a sum statistic for every numeric field in a dataset.\r\n\r\nThe ArcGIS scripting package ArcPy has functions for doing all kinds of GIS tasks. One, the ListFields function, is especially important for this scenario. The ListFields function, as its name suggests, returns a list of all the attribute fields in a specified dataset. Listing a dataset's fields and checking that the field type is numeric are key steps in scripting this task.\r\n\r\nAnother key step in writing the script is constructing the Statistics Field(s) parameter with the correct Python syntax. In a Python script, the Statistics Field(s) parameter is best represented by a list of lists. You can think of the outer\/main list as the full Statistics Field(s) parameter table in the tool dialog box and each sublist as a single row in that table.\r\n\r\nJust like the Summary Statistics (Analysis) tool dialog box, the Statistics Field(s) parameter table has two columns. The first column is for the field name, and the second column is the statistic to calculate for that field.\r\n\r\nIn Python scripting, each sublist (row) has two elements that correspond directly to the columns in the parameter table. The sublists are constructed by putting together the field name and sum statistic type while iterating through the list of fields. But remember, this is only done after checking whether the field type is numeric, because it is impossible to calculate the Sum of other types such as text or dates.\r\n\r\nAs Listing 1 illustrates, in just a few lines of code, this repetitive and time-consuming task has been automated.\r\n\r\nPython scripting is one of several ways to run ArcGIS geoprocessing tools. Scripting a geoprocessing tool can often help work around problems that occur because a tool dialog parameter is tricky or requires repetitive action.\r\n\r\nYou can use the powerful and wide-ranging functions available in ArcPy to help you with many GIS tasks, such as using the ListFields function to return a list of all attribute fields in a dataset, which can be subsequently looped through. Using ArcPy functions together with geoprocessing tools can help you be more productive and avoid those awful GUI headaches. Learn more about the ways Python can make your life easier at Python for ArcGIS on the\u00a0<a href=\"https:\/\/resources.arcgis.com\/en\/communities\/python\/\">ArcGIS Resources site<\/a>."},{"acf_fc_layout":"sidebar","layout":"code_snippet","image_reference":null,"image_reference_figure":"","spotlight_image":null,"section_title":"","spotlight_name":"","position":"Center","content":"Listing 1: Python script automating parameter input for the Summary Statistics (Analysis) tool","snippet":"# Script that runs the Summary Statistic tool to Sum every numeric attribute\r\n# of Census tracts by unique County IDs\r\nimport arcpy\r\n\r\n# Local variables\r\nintable = \"C:\/Data\/f.gdb\/CensusTracts\"\r\nouttable = \"C:\/Data\/f.gdb\/CensusTracts_SumStats_Counties\"\r\ncasefield = \"CNTY_FIPS\"\r\n# Create a new empty list to store pairs of field + statistic\r\nstats = []\r\n\r\n# Loop through all fields in the Input Tablew\r\nfor field in arcpy.ListFields(intable):\r\n    # Just find the fields that have a numeric type\r\n    if field.type in (\"Double\", \"Integer\", \"Single\", \"SmallInteger\"):\r\n        # Add the field name and Sum statistic type as a list\r\n        # to the list of fields to summarize (makes a list of lists)\r\n        stats.append([field.name, \"Sum\"])\r\n\r\n# After looping, the Statistics list of lists will look like\r\n# [[\"HOUSEHOLDS\", \"Sum\"], [\"MALES\", \"Sum\"], ...]\r\n\r\n# Run the Summary Statistics tool with the Statistics list of lists\r\narcpy.Statistics_analysis(intable, outtable, stats, casefield)"}],"references":null},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.9 (Yoast SEO v25.9) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Avoid GUI Headaches | Spring 2013 | ArcUser<\/title>\n<meta name=\"description\" content=\"Sometimes the repetitive nature of a task can make using a tool dialogtime-consuming and inefficient.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.esri.com\/about\/newsroom\/arcuser\/avoid-gui-headaches\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Avoid GUI Headaches\" \/>\n<meta property=\"og:description\" content=\"Sometimes the repetitive nature of a task can make using a tool dialogtime-consuming and inefficient.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.esri.com\/about\/newsroom\/arcuser\/avoid-gui-headaches\" \/>\n<meta property=\"og:site_name\" content=\"Esri\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/esrigis\/\" \/>\n<meta property=\"article:modified_time\" content=\"2024-09-27T23:34:26+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.esri.com\/about\/newsroom\/app\/uploads\/2019\/09\/topography-dark-grey-card.jpg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@Esri\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\n\t    \"@context\": \"https:\/\/schema.org\",\n\t    \"@graph\": [\n\t        {\n\t            \"@type\": \"WebPage\",\n\t            \"@id\": \"https:\/\/www.esri.com\/about\/newsroom\/arcuser\/avoid-gui-headaches\",\n\t            \"url\": \"https:\/\/www.esri.com\/about\/newsroom\/arcuser\/avoid-gui-headaches\",\n\t            \"name\": \"Avoid GUI Headaches | Spring 2013 | ArcUser\",\n\t            \"isPartOf\": {\n\t                \"@id\": \"https:\/\/www.esri.com\/about\/newsroom\/#website\"\n\t            },\n\t            \"datePublished\": \"2019-02-07T16:47:33+00:00\",\n\t            \"dateModified\": \"2024-09-27T23:34:26+00:00\",\n\t            \"description\": \"Sometimes the repetitive nature of a task can make using a tool dialogtime-consuming and inefficient.\",\n\t            \"breadcrumb\": {\n\t                \"@id\": \"https:\/\/www.esri.com\/about\/newsroom\/arcuser\/avoid-gui-headaches#breadcrumb\"\n\t            },\n\t            \"inLanguage\": \"en-US\",\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"ReadAction\",\n\t                    \"target\": [\n\t                        \"https:\/\/www.esri.com\/about\/newsroom\/arcuser\/avoid-gui-headaches\"\n\t                    ]\n\t                }\n\t            ]\n\t        },\n\t        {\n\t            \"@type\": \"BreadcrumbList\",\n\t            \"@id\": \"https:\/\/www.esri.com\/about\/newsroom\/arcuser\/avoid-gui-headaches#breadcrumb\",\n\t            \"itemListElement\": [\n\t                {\n\t                    \"@type\": \"ListItem\",\n\t                    \"position\": 1,\n\t                    \"name\": \"Home\",\n\t                    \"item\": \"https:\/\/www.esri.com\/about\/newsroom\"\n\t                },\n\t                {\n\t                    \"@type\": \"ListItem\",\n\t                    \"position\": 2,\n\t                    \"name\": \"Avoid GUI Headaches\"\n\t                }\n\t            ]\n\t        },\n\t        {\n\t            \"@type\": \"WebSite\",\n\t            \"@id\": \"https:\/\/www.esri.com\/about\/newsroom\/#website\",\n\t            \"url\": \"https:\/\/www.esri.com\/about\/newsroom\/\",\n\t            \"name\": \"Esri\",\n\t            \"description\": \"Esri Newsroom\",\n\t            \"potentialAction\": [\n\t                {\n\t                    \"@type\": \"SearchAction\",\n\t                    \"target\": {\n\t                        \"@type\": \"EntryPoint\",\n\t                        \"urlTemplate\": \"https:\/\/www.esri.com\/about\/newsroom\/?s={search_term_string}\"\n\t                    },\n\t                    \"query-input\": {\n\t                        \"@type\": \"PropertyValueSpecification\",\n\t                        \"valueRequired\": true,\n\t                        \"valueName\": \"search_term_string\"\n\t                    }\n\t                }\n\t            ],\n\t            \"inLanguage\": \"en-US\"\n\t        },\n\t        {\n\t            \"@type\": \"Person\",\n\t            \"@id\": \"https:\/\/www.esri.com\/about\/newsroom\/#\/schema\/person\/b7332d419608ac1a0291ec30de119efb\",\n\t            \"name\": \"April Mann\",\n\t            \"image\": {\n\t                \"@type\": \"ImageObject\",\n\t                \"inLanguage\": \"en-US\",\n\t                \"@id\": \"https:\/\/www.esri.com\/about\/newsroom\/#\/schema\/person\/image\/\",\n\t                \"url\": \"https:\/\/secure.gravatar.com\/avatar\/28d21cf04453f95cd2d8a0f053e5cd18ccf684320f6a4974f358b8109264e80b?s=96&d=blank&r=g\",\n\t                \"contentUrl\": \"https:\/\/secure.gravatar.com\/avatar\/28d21cf04453f95cd2d8a0f053e5cd18ccf684320f6a4974f358b8109264e80b?s=96&d=blank&r=g\",\n\t                \"caption\": \"April Mann\"\n\t            },\n\t            \"url\": \"\"\n\t        }\n\t    ]\n\t}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Avoid GUI Headaches | Spring 2013 | ArcUser","description":"Sometimes the repetitive nature of a task can make using a tool dialogtime-consuming and inefficient.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.esri.com\/about\/newsroom\/arcuser\/avoid-gui-headaches","og_locale":"en_US","og_type":"article","og_title":"Avoid GUI Headaches","og_description":"Sometimes the repetitive nature of a task can make using a tool dialogtime-consuming and inefficient.","og_url":"https:\/\/www.esri.com\/about\/newsroom\/arcuser\/avoid-gui-headaches","og_site_name":"Esri","article_publisher":"https:\/\/www.facebook.com\/esrigis\/","article_modified_time":"2024-09-27T23:34:26+00:00","og_image":[{"url":"https:\/\/www.esri.com\/about\/newsroom\/app\/uploads\/2019\/09\/topography-dark-grey-card.jpg","type":"","width":"","height":""}],"twitter_card":"summary_large_image","twitter_site":"@Esri","twitter_misc":{"Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.esri.com\/about\/newsroom\/arcuser\/avoid-gui-headaches","url":"https:\/\/www.esri.com\/about\/newsroom\/arcuser\/avoid-gui-headaches","name":"Avoid GUI Headaches | Spring 2013 | ArcUser","isPartOf":{"@id":"https:\/\/www.esri.com\/about\/newsroom\/#website"},"datePublished":"2019-02-07T16:47:33+00:00","dateModified":"2024-09-27T23:34:26+00:00","description":"Sometimes the repetitive nature of a task can make using a tool dialogtime-consuming and inefficient.","breadcrumb":{"@id":"https:\/\/www.esri.com\/about\/newsroom\/arcuser\/avoid-gui-headaches#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.esri.com\/about\/newsroom\/arcuser\/avoid-gui-headaches"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.esri.com\/about\/newsroom\/arcuser\/avoid-gui-headaches#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.esri.com\/about\/newsroom"},{"@type":"ListItem","position":2,"name":"Avoid GUI Headaches"}]},{"@type":"WebSite","@id":"https:\/\/www.esri.com\/about\/newsroom\/#website","url":"https:\/\/www.esri.com\/about\/newsroom\/","name":"Esri","description":"Esri Newsroom","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.esri.com\/about\/newsroom\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.esri.com\/about\/newsroom\/#\/schema\/person\/b7332d419608ac1a0291ec30de119efb","name":"April Mann","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.esri.com\/about\/newsroom\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/28d21cf04453f95cd2d8a0f053e5cd18ccf684320f6a4974f358b8109264e80b?s=96&d=blank&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/28d21cf04453f95cd2d8a0f053e5cd18ccf684320f6a4974f358b8109264e80b?s=96&d=blank&r=g","caption":"April Mann"},"url":""}]}},"sort_order":"0","_links":{"self":[{"href":"https:\/\/www.esri.com\/about\/newsroom\/wp-json\/wp\/v2\/arcuser\/153702","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.esri.com\/about\/newsroom\/wp-json\/wp\/v2\/arcuser"}],"about":[{"href":"https:\/\/www.esri.com\/about\/newsroom\/wp-json\/wp\/v2\/types\/arcuser"}],"author":[{"embeddable":true,"href":"https:\/\/www.esri.com\/about\/newsroom\/wp-json\/wp\/v2\/users\/1432"}],"version-history":[{"count":0,"href":"https:\/\/www.esri.com\/about\/newsroom\/wp-json\/wp\/v2\/arcuser\/153702\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.esri.com\/about\/newsroom\/wp-json\/wp\/v2\/media?parent=153702"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.esri.com\/about\/newsroom\/wp-json\/wp\/v2\/categories?post=153702"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.esri.com\/about\/newsroom\/wp-json\/wp\/v2\/tags?post=153702"},{"taxonomy":"arcuser_issues","embeddable":true,"href":"https:\/\/www.esri.com\/about\/newsroom\/wp-json\/wp\/v2\/arcuser_issues?post=153702"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}