Updating enterprise feature class using ArcGIS API for Python

1232
4
10-22-2019 06:39 AM
by Anonymous User
Not applicable

I have created a Python script that will turn some CSVs to features in a GDB and I am trying to get the feature class on my local machine to overwrite the feature on our enterprise portal. I have imported the arcgis.gis library and I think that I need to be using the arcgis.gis.Datastore().update.

   gis = ag.GIS(portal, user, password)
   print(f'Connected to {portal}')
   print(ag.Datastore('ArcGIS_Data_Store', '\\portal-url\arcgisdatastore)').datasets)

It seems like I am getting logged in alright, but when I run this script I get the following error. I am unable to find any examples for this. How do others update their files in the datastore.

Traceback (most recent call last):
Connected to https://portal-url/arcgis/
File "W:/Research&Development/Data-Share/layers/trapeze/MetroBusStops/AutomationExports/py/CSV_2_FeatureClass_2_DataStore.py", line 65, in <module>
print(ag.Datastore(datastore='ArcGIS_Data_Store', path='https://portal-url/arcgis/arcgisdatastore').datasets)
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\__init__.py", line 955, in __init__
self._portal = datastore._portal
AttributeError: 'str' object has no attribute '_portal'

UPDATE:

I have started using the FeatureLayerCollection module. I have imported at the top and have appended the following


current_file = FeatureLayerCollection.fromitem.fromitem('https://url/arcserver/rest/services/MetroBusStopsByLine_191021/MapServer/0')

current_file.manager.overwrite(current_file.manager.overwrite('AutomationExports.gdb/MetroBusStopsByLine_191021'))

and I am getting the following error

Traceback (most recent call last):
File "W:/Research&Development/Data-Share/layers/trapeze/MetroBusStops/AutomationExports/py/CSV_2_FeatureClass_2_DataStore.py", line 69, in <module>
current_file = FeatureLayerCollection.fromitem('https://url/arcserver/rest/services/MetroBusStopsByLine_191021/MapServer/0')
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\__init__.py", line 9509, in fromitem
if not item.type.lower().endswith('service'):
AttributeError: 'str' object has no attribute 'type'

0 Kudos
4 Replies
MicahBabinski
Occasional Contributor III

Is that your entire code? Based on the AttributeError I think something might have gone awry earlier in your code.

Micah

0 Kudos
by Anonymous User
Not applicable

So the rest of my code is not related to this. The only thing that has happened is I have declared some variables associated with the portal. I updated the request with the full error.

0 Kudos
MicahBabinski
Occasional Contributor III

Ah ok, I see what you're saying. Are you sure you need to interact with the DataStore class?

I may be misunderstanding your intent, but it sounds like what you want to do is update or overwrite a feature layer that's already hosted or registered with your portal. If so, there's a sample notebook that talks about taking CSV files, reading them using the pandas library, publishing the CSV as a feature layer, and then overwriting an existing feature layer. Hope this helps and I'm not way off base with what you're trying to do!

Overwriting feature layers | ArcGIS for Developers 

0 Kudos
by Anonymous User
Not applicable

Thanks for following up on my reply. I have a little better handle on this now, but I am still unsure how to connect to an existing feature. I would assume that I would use the url on the feature layer page, but I am not able to find the function that would connect something like that. as far as the rest of the script that I have put together. I am using the overwrite() function

current_file = FeatureLayerCollection.fromitem.fromitem('https://metroas08.metrostlouis.org/arcserver/rest/services/MetroBusStopsByLine_191021/MapServer/0')

current_file.manager.overwrite(current_file.manager.overwrite('AutomationExports.gdb/MetroBusStopsByLine_191021'))

and I am getting the following error

Traceback (most recent call last):
File "W:/Research&Development/Data-Share/layers/trapeze/MetroBusStops/AutomationExports/py/CSV_2_FeatureClass_2_DataStore.py", line 69, in <module>
current_file = FeatureLayerCollection.fromitem('https://url/arcserver/rest/services/MetroBusStopsByLine_191021/MapServer/0')
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\__init__.py", line 9509, in fromitem
if not item.type.lower().endswith('service'):
AttributeError: 'str' object has no attribute 'type'

0 Kudos