Append Data to Hosted Feature Layer

12449
7
Jump to solution
02-09-2021 07:04 AM
LisaT
by
Occasional Contributor III

I would like to do something seemingly simple:  upload multiple features to a hosted feature service in Portal.  Weird thing is that I can do a search and I see that there is an "Append Data" option in AGOL. I do not see it in Portal, though??  I also see this tool: https://enterprise.arcgis.com/en/portal/latest/use/geoanalytics-append-data.htm , which looks perfect...but it is a geoanalytics tool.  I just want to upload multiple records to a feature layer.

I can see needing/wanting to use this in many cases, but in this particular case I have created a Hosted Feature Layer out of a CSV.  The user has continued to update his Excel spreadsheet, so I would like to append the new data to the Feature Layer.  In this example, we are just wanting to import more lat/lng values. The schema is the same.

2 Solutions

Accepted Solutions
jcarlson
MVP Esteemed Contributor

They state it clearly in the docs that Append is only an option in AGOL. They don't state why this is the case, however, and that has always bothered me. If you're going to hold back one of the more useful tools for dealing with hosted feature layers, I'd like to have a reason. And if it's a legit reason, I can live with it, but that's preferrable to not knowing.

Having dealt with this in the past, the only "easy" way of dealing with this situation is just to overwrite the hosted layer with the updated spreadsheet. As long as the user hasn't removed anything from the spreadsheet, or you haven't made significant changes to the data since adding it, you should be good.

If there have been changes or deletions since publishing the layer, you'll need some way of comparing the two datasets separately before submitting new features to the service. You can do this programmatically via python (we use pandas' compare function to do just this sort of thing), or you can bring in the CSV to Pro and copy/paste features, but that requires more manual looking, filtering, possibly spatial selections, and can be arduous if there are lots of records, and is prone to error.

- Josh Carlson
Kendall County GIS

View solution in original post

LisaT
by
Occasional Contributor III

As a follow-up to this, I was able to point my portal to use the geocoder in my AGOL account. It uses credits, but is the best way to do it because the lat/lng values are world-wide.  I was then able to use the Data Aggregator widget, which works great!  it allows my user to upload his csv, it finds duplicates, and then you can chose to download the lists of duplicates, the list of problem locations, and the list of ready-to-upload. Great tool!  If you can't use the data aggregator, I think Josh Carlson has the best explanation.

View solution in original post

7 Replies
jcarlson
MVP Esteemed Contributor

They state it clearly in the docs that Append is only an option in AGOL. They don't state why this is the case, however, and that has always bothered me. If you're going to hold back one of the more useful tools for dealing with hosted feature layers, I'd like to have a reason. And if it's a legit reason, I can live with it, but that's preferrable to not knowing.

Having dealt with this in the past, the only "easy" way of dealing with this situation is just to overwrite the hosted layer with the updated spreadsheet. As long as the user hasn't removed anything from the spreadsheet, or you haven't made significant changes to the data since adding it, you should be good.

If there have been changes or deletions since publishing the layer, you'll need some way of comparing the two datasets separately before submitting new features to the service. You can do this programmatically via python (we use pandas' compare function to do just this sort of thing), or you can bring in the CSV to Pro and copy/paste features, but that requires more manual looking, filtering, possibly spatial selections, and can be arduous if there are lots of records, and is prone to error.

- Josh Carlson
Kendall County GIS
JayantaPoddar
MVP Esteemed Contributor

Do you have access to ArcMap or ArcGIS Pro (connected to Portal for ArcGIS)?

If yes, check if the following workaround works for you.

Click on the Add item from your computer in ArcGIS Online
Browse for the CSV file
Make sure the box for "Publish as hosted feature service" is checked
Fill in all the required fields
Click on Publish
Add the both published hosted feature layers into ArcMap
Use Append (Data Management) tool
Use the hosted feature layer created from the CSV file as the input feature layer and the other hosted feature layer as the target layer
Hit on Run.

Reference: Appending CSV data to AGOL from Pro not showing geometry



Think Location
HenryLindemann
Esri Contributor

Hi @LisaT,

I don't know how comfortable you are with coding but it is quite simple to achieve with the ArcGIS Api for Python and it is all free.

index | ArcGIS for Developers

This is how you do it 

Upload your CSV the first time to create the service 

HenryLindemann_0-1612938781621.png

 

in the new service get the url displayed at the bottom of the page  

HenryLindemann_1-1612938854661.png

 

add /0 if there is only one layer in the service

Here is the code that you need if you run this in ArcGIS Pro not setup is required

from arcgis.gis import GIS
from arcgis.features import Feature
from arcgis.geometry import Point
from arcgis.features import FeatureLayer

"""
# Read the CSV and build the rows to append
"""
rows_to_append = []
# Read the csv and build the rows to append
with open('upload_data.csv', 'r') as read_file: # path should be full if the csv is not in the same folder c:/mypath/upload_data.csv
lines = read_file.readlines()
heading = True
for line in lines:
line = line.strip('\n')
if heading is True:
print(line) #heading
heading = False
continue
print(line) # Records
record = line.split(';') # splits the rows into parts
# build record to append
row_to_append = {"name": record[0], "surname": record[1]} # Create Attributes
geometry_point = Point({"x": record[2], "y": record[3], "spatialReference" : {"wkid" : 4326}}) # Create Geometry
rows_to_append.append(Feature(attributes=row_to_append, geometry=geometry_point))

"""
# log into AGOL and append new rows
"""
con = GIS('https://arcgis.com', 'username', 'password') # log in to AGOL
# connect to the layer to append
layer_to_append = FeatureLayer('https://services.arcgis.com/nZAAAAAAn0yqFPN/arcgis/rest/services/upload_data/FeatureServer/0', con)
# view Current Rows
view_rows = layer_to_append.query(where='1=1')
for row in view_rows:
print(row)

# append new rows
result = layer_to_append.edit_features(adds=rows_to_append)
print(result)

# view all rows
view_rows = layer_to_append.query(where='1=1')
for row in view_rows:
print(row)

 

Hope it helps

Henry

 

 

 

LisaT
by
Occasional Contributor III

Thanks for this Henry.  Unfortunately this is not going to work for us...unless I am missing something.  I need a way for my ArcGIS Portal users to be able to update.  These users are not GIS Analysts and do not use ArcGIS Pro.  This particular user just wanted a mapping interface to show his lat/lng fields that he had in an Excel spreadsheet.  He has been using Tableau.  I have created a Hosted Feature Service for him. He now has quite a few more rows of Excel data, in the same format, that he would like to upload.

It seems that using a Hosted Feature service for small updates is ideal, but when there are multiple features to append there are more challenges. I am just a bit confused as to why the tools are available in AGOL and not Portal. Has anyone used the Data Aggregation widget? https://doc.arcgis.com/en/web-appbuilder/create-apps/widget-data-aggregation.htm#ESRI_SECTION1_20B1B...

I will have to muddle through trying to figure out how to apply a global geocoder for this.  The layer we are working with shows locations world-wide. I'm not even sure if this will work for us, as the csv has lat/lng (web mercator) values and it seems to need the geocoder for address locations.  Anyway, this tool may be the closest thing I have found (if it works).

Any other ideas?  Could I publish the "Append" function as a geoprocessing service and use it from within Portal?

DavinWalker2
Esri Contributor

Hi Lisa,

This might help.

Geoanalytics Append Data 

0 Kudos
LisaT
by
Occasional Contributor III

Hi Davin, Thank you for this response.  I actually reference that link in my first post.  I am trying to find a way to append to a hosted service in my Enterprise Portal and we do not have GeoAnalystics server.  Is there a way to use this tool in my scenario?

0 Kudos
LisaT
by
Occasional Contributor III

As a follow-up to this, I was able to point my portal to use the geocoder in my AGOL account. It uses credits, but is the best way to do it because the lat/lng values are world-wide.  I was then able to use the Data Aggregator widget, which works great!  it allows my user to upload his csv, it finds duplicates, and then you can chose to download the lists of duplicates, the list of problem locations, and the list of ready-to-upload. Great tool!  If you can't use the data aggregator, I think Josh Carlson has the best explanation.