Check to see if a field exists using Python

Ever wanted to know if a certain field exists in a feature class or attribute table? This could be to either populate it with something if it does exist or create it first if it does not exist, then populate it. The easy steps below will show you how to check if a field exists. If it does not exist, it will be created then perform a field calculation on it.

First is the code (function) to check if a field exists (Note that the green text is purely some metadata about this function):

Next we will work with this code (known as calling this function) to check if a specific field name exists in our feature class. The path to our feature class is C:\data\MyData.gdb\TestFeatureClass and the field name we are going to check for is CATEGORY. These we will set in a variable as such:

Because the fieldExists function with return a Boolean of True, we can use an if statement to do something if it does
exist. We do that by using the following:

Now we need to do something if it does exist. For now we will just return a message to say that it does exit (if it actually does exist in the feature class):

If this field does exist in the feature class, the message returned will look like this:

image005
At the moment, if the field does not exist, no message will be shown. This also means that if it does not exist, you cannot do anything else. What we now need to do is write something to say that if the field does not exist in my feature class, I must do something else. This is done by using the else statement under the if statement (that’s logical, don’t you think). This is done like so:

Pretty simple so far? Great!

Now we need to add a message to say that the field does not exist in the feature class:

If this field does not exist in the feature class, the message returned will look like this:
image008
After that and using the same indentation as the print statement you can now use something like arcpy.AddField_management() to add the missing field which needs to be populated.

The completed script looks like this (You can copy and paste the code below and re-use it in your own script):

6 things you can do with ArcGIS in 60 minutes or less

Stopwatch

The ArcGIS product stack can sometimes be overwhelming. Quite often I get asked if we “can do something” – before I even hear the “thing” my answer is yes! The challenge is always how to do it and with which set of tools. So, with all this amazing technology, we sometimes forget how easy it is to do the basic things – getting data into the system and sharing it in powerful and meaningful ways. So here is my list of 6 things you can do in a very short amount of time with ArcGIS, do you have any other ideas?

1

Make your own field data app

Want to capture pictures and the location of graffiti in your neighbourhood? The location and a photo of birds on a walk in the bush? Just open an editable web map on Collector for ArcGIS (iOS and Android) and start capturing! More info here.

2Create a website that tells a story with maps

Want to show your friends all the places you have visited this year? Or maybe want to show off sights of your neighbourhood in your local community meetings? Use a web map and create a story map using a template and your data and share! More info here.

3

Configure a mobile-ready web app

You want to be able to create a native mobile app for your children’s school to use on their outings? Or to brand an information app for your cousin’s tour company? Use a web map and configure the app with the AppStudio for ArcGIS! More info here.

4Deploy an app to any mobile platform

Want to create a basic mapping app that allows people to click on a feature and get a popup? Or change the basemap to imagery and view their own house using their mobile phone? Use a web map and configure a web app using the Web AppBuilder for ArcGIS! More info here.

5Add your Excel data to a map

Have some Excel data about schools in your province and want to add them to a map? Or maybe you have some Excel information about households in your local club and want to add them to a map? Use Excel with Esri Maps for Office and you can quickly add that data to the map using a wizard! More info here.

6Embed a map into your existing website

Have an existing website and want to include a map with directions to your office or house? Use a web map and embed it using code provided for you! More info here.

Adding a Custom Widget to the Web App Builder

Note that the functionality to deploy custom widgets in the Portal-hosted Web AppBuilder is now supported at 10.5.1. See this Esri blog for more details: https://blogs.esri.com/esri/arcgis/2017/06/30/web-appbuilder-for-arcgis-now-supports-custom-widgets-in-arcgis-enterprise-10-5-1/

The Web AppBuilder from Esri has already proven to be a powerful tool for creating new web mapping apps incredibly quickly – for us and many of our users. One challenge we keep coming across is that ‘it provides us with 80% of what the users actually need’. So, how do we go about giving them the last 20%, without building a new app from scratch with the SDKs? Well, the answer is to create your own custom widgets – this is fairly well documented by Esri (see link). But what if you have Portal for ArcGIS in your organisation and want to embed the widget in there? Well, let’s walk through the steps on how to go about doing this.

For detailed instructions and screenshots of every step, please click on the link below to view the pdf documentation:
Portal Widget Install Guide rev02

P.S. Please remember to make a backup of all the files we will be editing in these steps.

Step 1:

First copy your custom widget with all its files into the following widgets directories:

“<install_location>\ArcGIS\Portal\apps\webappbuilder\stemapp\widgets\”

“<install_location>\ArcGIS\Portal\apps\webappviewer\widgets\”

 Widget_Picture01

If you are uncertain about the structure in which your widget should be, have a look at some of the other widgets in these directories.

Step 2:

Next you will want to add your widget to the config.json files:

“<install_location>\ArcGIS\Portal\apps\webappbuilder\stemapp\”

“<install_location>\ArcGIS\Portal\apps\webappviewer\”

 Widget_Picture02

  • Set “widgetManifestsMerged”: true

  • Add custom widget to the “WidgetPool”\”widgets” section

Step 3:

Add your widget’s manifest to the widget manifest file “widgets-manifest-builder.json” to the following locations:

“<install_location>\ArcGIS\Portal\apps\webappbuilder\stemapp\widgets\”

“<install_location>\ArcGIS\Portal\apps\webappviewer\widgets\”

To save time you can copy one of the existing widget’s manifests and change the details accordingly.

Step 4:

Congratulation, you are all done!

Now all that is left is to restart Portal for ArcGIS or JavaScript Application Builder and you will be able to use your custom widget in your app builder.

Widget_Picture03

Getting domains into the Geodatabase the easy way

verosha1We are often faced with the challenge of having to create (or update) a vast number of domains within a Geodatabase. The common way to do this is through the Properties dialog in Catalog – but this is not helpful if you have tens or hundreds of domain values to type in.

Table to Domain to the rescue! This is a tool in the Data Management toolbox that you can use to directly translate a table (Excel, csv, database table, etc.) into a Geodatabase domain. Since it is a GP tool, you could add it to a model and schedule it to run periodically too – this is handy if you ever need to keep your domains up-to-date from another system.

The tool aims to save the user time, specifically if the original state of data is in an excel format. With this tool users are able to create or update a coded value domain with values from the table. One of the main benefits of domains is to reduce errors in data entry by eliminating invalid data entries. It also reduces data entry time by creating a series of automated drop-down menus.

Here is an easy 3-step guide:

Step 1: Add the table to ArcMap

Input data in Excel

Step 2: Search for the geoprocessing tool, Table to Domain. Fill out the parameters as follows:

Geoprocessing Tool

Step 3: Click OK, the tool will take a moment to complete

You can now see the domains in the Geodatabase properties window as follows:

Domains in the Geodatabase

For more information, see the online help at http://resources.arcgis.com/en/help/main/10.1/index.html#//001700000025000000

IDEAL data for location analytics

Many government organizations and commercial businesses that deliver a product or service to the public have the challenge of understanding their “customer” better. We have found that using the exclusive IDEAL dataset offers them a competitive edge over their competitors. Esri customers use the IDEAL dataset to get the most granular data available for demographics, land use and population growth, this has tremendous business value because customers can take more informed decisions on where the build or market their business.

The data is “IDEAL” to empower our customers with a unique dataset to support them in making better decisions.

There are three major advantages in using this dataset compared to other “similar” datasets like the STATS SA data.

  • The dataset is presented at Enumerated Area (EA) which is the most granular level available for this type of information, it uses the same frame as the STATS SA data so it can be aggregated to higher level if required.
  • The most commonly used information in demographics is the population figures, the IDEAL dataset provides the Daytime and Night time population which is not available in any other dataset and offers major advantages in terms of understanding an area.
  • The data is maintained and updated on an annual basis.

The picture below gives you an indication of the difference between (sub place and enumerator area) the +/- 50 EA’s fall within one Sub place, this gives our users a much better picture on what is happening on the ground.

EA's_Sub Place

Interested? Want more information regarding the IDEAL dataset? Click below!

Advanced Measure of Land Activity

Demographics

Growth

Enterprise Exit: Google to Esri

In February 2015 Google Maps celebrated their 10th birthday and a decade of spatially enabling the world. While Google’s ongoing investment in mapping and the beloved street view is assured, they have decided to abandon their enterprise products as a revenue generator.  Following this business decision Google announced that they would no longer support the Google Earth API, Google Earth Enterprise and Google Maps Engine, which will all be discontinued at the end of this year. They have also made Google Earth Pro available for free.

Google has reached out to fellow Californian based mapping company Esri between them they provided a path for Google enterprise customers to transition to Esri software. Esri provides a scalable geo-spatial technology stack that enables individuals to discover, make, use and share maps from any device, at any place, any time.

An overview of Google Maps for Work products and the equivalent Esri products are tabled on a dedicated page that will help businesses to transition from Google technology to Esri. Esri’s web mapping platform and out of the box applications will ensure a smooth transition to this leader in geospatial technology. So, if you have been using google for your business, you will be glad to know that …

You can already move data easily between Google and Esri

For a number of years it was already possible to move data easily between Google to Esri using the existing ArcGIS desktop geoprocessing tools. Available at all license levels there are conversion tools to convert a KML or KMZ file into feature classes and layer files. The layer file maintains the symbology found within the original KML/KMZ file. There is also geoprocessing tools available for the reverse conversion.

Moving to the server and online platform, it is possible create KML from your map and image services in ArcGIS for Server. This process involves authoring maps in ArcGIS for Desktop, publishing the service with KML capabilities enabled, then making the service available for others to view.

But, what about Google Earth?

Esri are in the process of developing ArcGIS Earth. This will be a free, lightweight, installable desktop app that makes viewing 3D maps instant and easy for anyone in the enterprise. It will be similar in functionality and ease of use as Google Earth.

ArcGIS Earth

ArcGIS Earth will support KML/KMZ files, but in addition you can also in the first release view Shapefiles, CSV files, Feature services shared in ArcGIS Online and web layers.

An advantage of this product is that it will be fully integrated with the ArcGIS platform allowing users to take advantage of data already published to ArcGIS Online or Portal for ArcGIS. The launch is planned for the end of 2015.