How to share joined layer to ArcGIS Online (and have it automatically update)

2704
7
Jump to solution
07-28-2020 05:44 AM
AnnaStam
New Contributor III

I am trying to work through the following problem - any insight would be greatly appreciated!

I want to join the JHU COVID-19 cases (US) layer to a county layer for the southern US. I also want the data to automatically sync with JHU's updates, and have those updates reflect on a dashboard in ArcGIS Online. I know I cannot share an in-memory joined feature class as a web map, so I tried:

1. Creating a view - this worked but then I could not make any further edits, such as calculating my "cases per 100,000 residents" field.

2. Creating a relationship class - I have no idea where the joined data is stored, if it even is stored? I want to use graduated color symbology for the counties by number of confirmed coronavirus cases, but I do not see the attributes from the JHU data.

Is there another way to solve this problem that I'm not thinking of? Thanks in advance!

0 Kudos
1 Solution

Accepted Solutions
JoshuaSharp-Heward
Occasional Contributor III

I don't think that is possible, and you are right - it does specify that you have to own both of the items to run this tool. In which case I would imagine creating a hosted feature with the same schema as JHU, and then have either an automated or manual process for updating your hosted feature service, may be the best solution. I can't really see any better way of achieving what you're hoping to achieve!

View solution in original post

0 Kudos
7 Replies
JoshuaSharp-Heward
Occasional Contributor III

Hi Anna,

Have you looked into the "Join Features" analysis tool in ArcGIS Online? Join Features—ArcGIS Online Help | Documentation 

I believe it makes a view layer joining two hosted feature services, and if you create the join based on a shared attribute (instead of a spatial join) then it will automatically update as changes are made to the two underlying services. 

Create results as hosted feature layer view allows the data to stay up to date as the source data changes. Hosted feature layer views containing joins will be read-only and do not consume credits for analysis and storage. If statistics are included as part of the output, the hosted feature layer view will contain an extra table layer in the view with the statistics. Attachments on the target layer will be preserved if the target layer has attachments enabled and a GlobalID field. For more information on hosted feature layer views, see Limitations.

Might very well be the best solution in this case.

0 Kudos
AnnaStam
New Contributor III

Hi Joshua, thanks for your response. I have looked into this, but I'm not sure how to create a hosted feature layer for something I don't own (the JHU COVID-19 cases layer). Is that possible?

0 Kudos
JoshuaSharp-Heward
Occasional Contributor III

I don't think that is possible, and you are right - it does specify that you have to own both of the items to run this tool. In which case I would imagine creating a hosted feature with the same schema as JHU, and then have either an automated or manual process for updating your hosted feature service, may be the best solution. I can't really see any better way of achieving what you're hoping to achieve!

0 Kudos
AnnaStam
New Contributor III

Thank you! I will explore that more.

0 Kudos
JoshuaSharp-Heward
Occasional Contributor III

No worries! I did a little playing because I was curious and it also seems quite important for you (COVID and all). If in AGOL content you go Create->Feature Layer->From URL and put in the url to the JHU service, it should create an exact replica but empty. Then I've written a little script using the ArcGIS API for Python that should update the data for you as long as the schemas match; if you have access to either ArcGIS Notebooks or ArcGIS Pro then the following should work to update the data for you:

from arcgis.gis import GIS

#gis = GIS("home") uncomment this if you run it from notebook in AGOL
#gis = GIS("pro")uncomment this if running from pro

id1 = "" #AGOL ItemID of JHU service item
id2 = "" #AGOL ItemID of your replica service

item1 = gis.content.get(id1)
item2 = gis.content.get(id2)

flayer1 = item1.layers[0] # assuming there is only one layer in the service?
flayer2 = item2.layers[0]

print("Querying JHU feature service")
fset = flayer1.query(where="1=1", out_fields="*", return_all_records=True)
print("{} features returned".format(len(fset.features))

print("Deleting features in replica JHU service")
flayer2.delete_features(where="1=1") # clearing out previous data

print("Adding features to replica JHU service")
flayer2.edit_features(adds=fset) # adding new data

This is very rudimentary and also not the most sensible way to solve it, as I'm nuking and appending all data instead of just taking changes from the last day etc., but it should do the trick.

AnnaStam
New Contributor III

Joshua,

This worked like a charm! Thanks so much for going above and beyond to help. Now I'm just waiting for ArcGIS notebooks to be schedule-able from the online environment

JoshuaSharp-Heward
Occasional Contributor III

Anna,

My pleasure, and glad to hear that it worked that easily  I'm assuming the JHU won't be making any changes to the schema of their service anytime soon, but if something ever stops working with that script that'd be the first thing I'd check! 

0 Kudos