|
POST
|
@heatherdaw this is the full script I'm using to create a backup fgdb of a hosted feature layer in my content. It overwrites the existing backup each time. Hope that helps. from arcgis.gis import GIS
from time import strftime
gis = GIS("home")
username = gis.properties.user.username
home_dir = os.path.abspath(os.path.join(os.sep, 'arcgis', 'home'))
# Variables
itemid = "000abc000abc000abc000abc000abc00" # AGO layer to backup
itemtype = "File Geodatabase" # export format
itemtags = "backup, fgdb" # item tags
itemdesc = strftime("This backup was generated on %m/%d/%Y.") # item description
folderlocation = "/" # export folder, / is root folder
# Check to see if a backup file geodatabase already exists
dataitem = gis.content.get(itemid) #fetch the item to be backed-up
backupname = f"{dataitem.title} Backup" #acquire backup name using the source hosted feature layer
searchquery = f"title:{backupname} AND owner:{username}" # search query using item title and owner
searchresult = gis.content.search(query=searchquery, item_type=itemtype, sort_field='uploaded', sort_order='desc') #search for existing backups
print(f'Found {len(searchresult)} existing backups')
# Update existing backup item, if it exists
if len(searchresult) >= 1:
print('Updating existing backup file...')
dataitem = gis.content.get(itemid) #fetch the item to be backed-up
backupname = f'{dataitem.title} Backup' #create a name for the backup using the existing item name
dataitem.export(backupname, itemtype, parameters=None, wait=True, tags=itemtags, snippet = itemdesc, overwrite=True) #export the data to a file geodatabase within the user's content
searchquery = f"title:{backupname} AND owner:{username}" # search query using item title and owner
searchresult = gis.content.search(query=searchquery, item_type=itemtype, sort_field='uploaded', sort_order='desc') #find the new temporary backup item that was just created
backupitem = gis.content.get(searchresult[0].itemid)
dwnldname = backupname.replace(" ","_")
backupitem.download(save_path=home_dir, file_name=dwnldname + '.zip')
searchquery = f"title:{backupname} AND owner:{username}" # search query using item title and owner
searchresult = gis.content.search(query=searchquery, item_type=itemtype, sort_field='uploaded', sort_order='asc') #search for the previous backup
oldbackup = gis.content.get(searchresult[0].itemid)
itemprops = {"snippet":f"{itemdesc}","description":f"{itemdesc}"}
oldbackup.update(item_properties=itemprops, data = os.path.join(home_dir, dwnldname, '.zip'))
backupitem.delete(dry_run=False) #Can change dry_run to True for testing, won't remove duplicate backups
#Create a new backup if no previous backup exists
else:
print('Creating new backup...')
dataitem = gis.content.get(itemid) #fetch the item to be backed-up
backupname = f'{dataitem.title} Backup' #create a name for the backup using the existing item name
dataitem.export(backupname, itemtype, parameters=None, wait=True, tags=itemtags, snippet = itemdesc) #export the data to a file geodatabase within the user's content
## Move the backup to designated folder, if not root
searchquery = f"title:{backupname} AND owner:{username}" # search query using item title and owner
searchresult = gis.content.search(backupname, item_type=itemtype) #find the backup that was just created
backupitem = gis.content.get(searchresult[0].itemid) #get the itemid of that new item
if folderlocation != "/":
print('Moving backup to designated folder...')
backupitem.move(folder=folderlocation) #move the item to the correct user folder, if user chose somewhere other than the default root
... View more
05-12-2022
07:48 AM
|
2
|
2
|
4930
|
|
IDEA
|
Hello @Anonymous User, I saw that the ArcGIS API for Python 2.0.0 documentation has an argument for service_name included with to_featurelayer. This isn't available in previous versions of the API however, and ArcGIS Online Notebooks 6.0 is still using ArcGIS API for Python 1.9.1. Any idea when Notebooks 7.0 for ArcGIS Online is expected, and if it will use version 2.0.0?
... View more
05-04-2022
01:31 PM
|
0
|
0
|
5746
|
|
POST
|
I'm running into a similar issue but with the service_name parameter. Haven't figured it out yet. Following the documentation here: https://developers.arcgis.com/python/api-reference/arcgis.features.toc.html?highlight=to_featurelayer#arcgis.features.GeoAccessor.to_featurelayer sdf.spatial.to_featurelayer(title='My Feature Layer Title', tags=['my','tags'], service_name='My_Feature_Layer_Title') TypeError: to_featurelayer() got an unexpected keyword argument 'service_name' It works if I remove the service_name argument, but then the name of my service is a randomly generated string. Not sure how else to define it. Maybe because I'm using a Spatially Enabled Dataframe instead of the deprecated Spatial Dataframe?
... View more
04-14-2022
02:04 PM
|
1
|
0
|
2390
|
|
IDEA
|
Agreed, categories are a great step in the right direction but could definitely use some of these additional features, especially Anthony's second point, as well as being able to read/edit members categories via the ArcGIS API for Python: https://community.esri.com/t5/arcgis-online-ideas/add-new-member-categories-as-a-property-to-arcgis/idi-p/1156929
... View more
04-13-2022
09:13 AM
|
0
|
0
|
2619
|
|
IDEA
|
Adding additional endpoints/layers to a hosted feature service in ArcGIS Online would be very useful and help save time and cut down on clutter by combining data. Feature services often need to change as projects evolve.
... View more
04-13-2022
09:09 AM
|
0
|
0
|
2752
|
|
POST
|
Thank you both @fklotz and @JoëlHempenius3 , works great and saved me some work as well. I will add that I was getting an error when it hit certain web maps that contained uploaded shapefiles (Classic Map Viewer; and which have no url). To get around it I just wrapped Joëls whole bit into a try/except clause. I'm sure there's a more elegant way to handle that issue but this works and I can then investigate the map manually at that point if I suspect the layer I'm searching for is in there. try:
for lyr in lyrs:
if 'url' in lyr and not found_it:
found_it = lyr_to_find.lower() in lyr.url.lower()
elif 'layerType' in lyr and lyr.layerType =="GroupLayer":
for sublyr in lyr.layers:
if 'url' in sublyr and not found_it:
found_it = lyr_to_find.lower() in sublyr.url.lower()
except Exception as error:
print(f'{item.title} led to an error')
print(error)
display(item)
continue
... View more
03-31-2022
01:20 PM
|
2
|
0
|
13057
|
|
IDEA
|
@KaraUtterI have not, but would be very interested to know if anyone has as well
... View more
03-24-2022
01:13 PM
|
0
|
0
|
4278
|
|
IDEA
|
This would be nice for admins, maybe even give them a threshold limit that can be set. For example if the admin wanted to know any time a user uploads a hosted feature layer larger than 5GB. Could probably be done with the ArcGIS API for Python, but a built in solution would be great.
... View more
03-23-2022
11:52 AM
|
0
|
0
|
1192
|
|
IDEA
|
The March 2022 update brought Member Categories to ArcGIS Online. It would be great if this property was accessible via the ArcGIS API for Python, in the user class of the gis module. We have a decent-sized organization with many decentralized divisions within when it comes to GIS, so updates like Member Categories are much appreciated. By exposing this info via the API, we can build Dashboards updated via Notebooks to help track our user base. Also would love to get to something like what was previously suggested in another Idea post, for tying custom role permissions to something like member categories.
... View more
03-23-2022
11:50 AM
|
21
|
12
|
5302
|
|
POST
|
Hi Rahul, did you ever find a solution to this? Also struggling to get overviews into Azure blob storage.
... View more
03-17-2022
11:23 AM
|
0
|
0
|
2375
|
|
POST
|
Hello! Does anyone know if it is possible to set the conditional visibility of a field (or perform a field calculation in the upcoming March release) based on whether or not a barcode was scanned during feature collection? For example, if you are collecting features which may or may not have a readable barcode associated with them, you may want to have some additional fields appear or disappear for the user, to add additional info manually. Or in the future, once Field Calculations are added, you might want to have a Yes/No field for 'Was a Barcode Used?' for QAQC purposes, that calculates automatically. Thanks in advance!
... View more
03-08-2022
02:24 PM
|
0
|
0
|
717
|
|
POST
|
When creating custom project templates in ArcGIS Pro, is it possible to have the template create a particular folder structure within its project folder? For example, if I wanted all my new projects to come with an empty Windows folder for Images, Exports, Data etc... in addition to the default file geodatabase and toolbox that it generates? If so, how would one do this? I'm not seeing a lot of in-depth guidance on what can and can't be set with custom project templates in ArcGIS Pro.
... View more
03-01-2022
03:29 PM
|
1
|
3
|
2082
|
|
IDEA
|
A built-in highlight option would be neat for quick stuff -- but as a workaround in the meantime (or for advanced highlighting!), you can achieve this effect by putting two copies of the same layer/dataset into your web map, and then changing the symbology for one of them to be your 'highlight' look. Then, when you are setting up the map action, toggle off the visibility for your default copy and turn on the highlight copy. That should pull off the same effect, albeit with a little more work.
... View more
02-22-2022
07:05 AM
|
0
|
0
|
3787
|
|
POST
|
I got the result I was looking for by following the process in the first half of this video -- adding a Red, Green, and Blue short integer field and calculating the colors for each class. I'm not sure if this is the best method or the only method, but it is a method and for now it will work. If you had a ton of classes, manually inputting the RGB values would be a pain. Hope this helps someone else if they come across this post.
... View more
02-17-2022
09:50 AM
|
0
|
0
|
6588
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 3 weeks ago | |
| 1 | 04-24-2026 09:14 AM | |
| 1 | 09-19-2023 08:22 PM | |
| 1 | 06-24-2022 09:52 AM | |
| 1 | 03-26-2026 12:44 PM |
| Online Status |
Offline
|
| Date Last Visited |
yesterday
|