Select to view content in your preferred language

Updating ArcGIS Online hosted feature layer with Smartsheets using ArcGIS API for Python

7285
7
11-04-2021 07:32 PM
MehdiPira1
Esri Contributor
14 7 7,285

 

Introduction

Smartsheet is a dynamic workspace that empowers teams to manage projects, automate workflows, and rapidly build new solutions. Smartsheet uses spreadsheets, referred to as sheets, as the basis of everything it does, but the difference between Smartsheet and spreadsheet programs like Microsoft Excel or Google Sheets is that Smartsheet has all sorts of collaboration functionality incorporated into it.

The screenshot below is a sample Smartsheet data.

MehdiPira1_0-1636077173116.png

In this blog, we will update a point feature layer in ArcGIS Online (AGOL) with a Smartsheet dataset using ArcGIS API for Python. In the process, first we will convert this Smartsheet into a Pandas Data Frame, remove rows with no coordinates and then update the feature layer. It is notable that the data contains longitude and latitude in X and Y columns.

The following screenshot is the feature layer that has already been published as a hosted feature layer from the Smartsheet into AGOL before and after updates. As such both the hosted feature layer and the Smartsheet have the same schema and fields. This Smartsheet gets updated on a weekly basis. Therefore the hosted feature layer needs to be updated as well to reflect the updates on the web map. Using ArcGIS API for Python, this process can be automated.

ezgif.com-gif-maker.gif

 

Requirements

There are three items that are required before data conversion:

  1. Install Smartsheet library by running this command “pip install smartsheet-python-sdk” in Python Command Prompt (here python is in D drive: “D:\ArcGIS\Server\framework\runtime\ArcGIS\bin\Python\envs\arcgispro-py3\Scripts>”)
  2. Smartsheet Access Token - here’s a link which shows how to create one
  3. Sheet ID – to obtain the sheet ID, in Smartsheet go to File > Properties > Sheet ID

 

Methodology

1. Smartsheet Conversion into a Data Frame

First import the modules.

MehdiPira1_15-1636011751820.png

Input the access token generated from the Smartsheet in the script below. After the Smartsheet authentication, a function is used to implement the Smartsheet to data frame conversion.

MehdiPira1_16-1636011900915.png

Input the sheet ID copied from the properties into the following script, then we call the function to create the data frame.

MehdiPira1_19-1636012319136.png

The rows with no latitudes or longitudes are removed.

MehdiPira1_20-1636012378136.png

MehdiPira1_1-1636078995890.png

Note that X and Y columns are the longitude and latitude coordinates respectively.

 

2. Export Data Frame into a CSV

Once the data frame is created, it is output as a temporary csv file in a folder. Here, a TEMP folder in C drive is used.

MehdiPira1_23-1636012690999.png

 

3. Upload CSV to AGOL

Connect to AGOL, then remove any existing csv item with the same title from AGOL.

MehdiPira1_24-1636012777395.png

When properties are set with title, description, and tags, upload the csv file to the Smartsheet's folder in AGOL. We can skip the description and tags here and can just use the title since this item is temporary and gets deleted when a new csv is added.

MehdiPira1_25-1636012894946.png

 

4. Truncate and Append

After that we get the hosted feature layer by id and we truncate it. This hosted feature layer becomes empty but still retains all the properties and settings.

Finally, we use the Append method to update this feature layer with the newly added csv file.

MehdiPira1_26-1636012995111.png

The good thing about using Append method is that the feature layer’s id does not change. This means that if the feature layer is already used in a web map or a web application, it will not break.

Now the hosted feature layer updated with the Smartsheet is displayed in the web map.

screentshot3.png

There are some points to note:

  • The hosted feature layer has initially been created from the same Smartsheet. Hence the schema, field names and types of both data are the same.
  • Append is currently only available in AGOL and cannot be used in Portal for ArcGIS.
  • I did not talk about the data used here as it can be any data as long as it contains coordinates since the emphasis is predominantly on the methodology.

This script can be used in e.g., Windows Task Scheduler to run on a regular basis for automation of the whole process.

 

Summary

Smartsheet integration with AGOL has been made easier and more efficient using ArcGIS API for Python with just a few lines of code. Therefore, when there are some updates in Smartsheet, these updates will automatically occur in the hosted feature layer whenever the script is run. This ensures the web maps and web applications such as Operations Dashboard display the latest features.

7 Comments
John_Spence
Frequent Contributor

Pretty slick stuff.  Thanks for sharing.

Juan_Toro-Killion
Regular Contributor

Hi! Trying to replicate your workflow here because my job started using SmartSheet and we need it to populate a hosted feature layer that gets updated whenever the sheet gets updated.

Would to ask you a couple questions, one being about how to precisely input the access_token into the script and the other about that gis.content.get(hosted_feature.id) line towards the end of the script.

 

Please let me know if we can chat/email/etc. about this? Thank you.

jmcewen_rphc
Emerging Contributor

I don't even remotely begin to have any clue how this works. Can't even figure out how to get the smartsheet module installed in an IDE. I've been banging my head against this stuff for years googling, watching youtube, paying for Udemy classes. Nothing. I'm not a programmer/developer. But I'm not an idiot either. I've gotten some decent Arcade and VBS scripts to work in the past. Someone please actually explain this stuff. 🙂

WardHively
Emerging Contributor

Skyway Consulting Co. excels in advanced integration, notably in achieving bidirectional synchronization between ArcGIS and Esri. While our current focus lies in land acquisition projects, we’re keen on diversifying our portfolio. Our standout feature is our ability to establish a no-code integration tailored to your workflow in under 5 hours. With our integration, Smartsheet seamlessly transforms into the ArcGIS attribute table, allowing users to stay within their Smartsheet dashboards at all times.


https://calendly.com/take-the-skyway/30min

WardHively
Emerging Contributor

Clearly we don’t specialize in spell check🫣 That is, we specialize in bidirectional integration between ArcGIS and Smartsheet.  

NeilKY
by
New Contributor

Does anyone have a pre-built integration solution between ESRI and Smartsheet?

WardHively
Emerging Contributor

@NeilKY Yes, please don't hesitate to reach out. 

Contributors
About the Author
I specialize in GIS and Data Science and integration of both, particularly in the fields of Remote Sensing and Data Engineering. I’m part of Esri Australia’s Professional Services team. I have passion in applications of Machine Learning and Deep Learning in GIS.