Hi
I'm trying to automate an update process for one of my hosted features in portal. So far I have:
1. Solved the automatic download and adjustment of the file in question. (using powershell/task scheduler)
2. exportet the python code that runs the "Geocode Addresses" tool on my file, saves it in a file gdb.
3. manually published the feature class with the "overwrite web layer" function.
My challange is to automate step 3, and connect it to step 2.
Please keep in mind that I'm completely new to scripting/python.
I'm currently using ArcGIS Pro 2.1.0, and have admin rights on the portal.
I have looked at thise sites, and think they describe partly how to solve my issue, I'm just not able to pick out the relevant parts and build a script that works for my particular problem..
community.esri.com "using python to overwrite a feature layer"
developers.arcgis.com python, overwriting feature layers
esri updating-your-hosted-feature-services-with-arcgis-pro-and-the-arcgis-api-for-python
Not sure if that was a type-o, but check your portal variable. You have an extra '.' before the com.
I removed the company name and forgot to take out the extra period
but now I am running into another error:
Traceback (most recent call last):
File "<string>", line 42, in <module>
IndexError: list index out of range
at line 42 is :
sdItem = gis.content.search("{} AND owner:{}".format(sd_fs_name, user), item_type="Service Definition")[0]
Is that due to there being spaces in the name of the Map being published?
I think that may be the issue. I believe the SD file will replace the spaces with underscores. Take a look at your portal and locate the SD file, what is the name? The error is indicating your search is not finding any results.
so i tried a few things. I published a new map layer with no spaces and the same error still persisted. I changed the portal address to make sure it was going directly to content :
portal = "https://sdc01acgicpw01s.corp/portal/home/content.html"
and still an error. So I believe the issue is how Enterprise searches for layers.
found the issue, but again have another error. The service I am uploading is a Map Image Layer., so I had to change the item_type from
"Service Definition"
to
item_type="Map Image Layer"
However, now I am getting an error:
Traceback (most recent call last):
File "<string>", line 48, in <module>
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\__init__.py", line 8655, in publish
raise ValueError("A file_type must be provide, data format not recognized")
ValueError: A file_type must be provide, data format not recognized
and here is my code as line 48 is:
fs = sdItem.publish(overwrite=True)
sdItem = gis.content.search("{} AND owner:{}".format(sd_fs_name, user), item_type="Map Image Layer")[0]
print("Found SD: {}, ID: {} n Uploading and overwriting…".format(sdItem.title, sdItem.id))
sdItem.update(data=sd)
print("Overwriting existing feature service…")
fs = sdItem.publish(overwrite=True)
is there something in item.publish() where I need to specify if it is a Map Image Layer?
Since you are publishing a map service, the above code will not work. That code was for a hosted feature service. Take a look at the following help on publishing a map service
MapImageSharingDraft—Sharing module | Documentation
There are some samples at the bottom of the page.
Thanks, this looks promising. Would I use the same methods in this example to search and overwrite the current map image layer?
You shouldn't need to search and delete the previous service as long as you're using the same service name. There is a property overwriteExistingService you can set.
Perfect, got this working as expected! but one final question. Is there a way to also set up the sharing of this, such such as with everyone? I did not see that in the documentation.