|
IDEA
|
An alternative solution for you to consider. 1. Create polygons that cover your project sites with the project number 2. If you don't want to see them, give them no symbol (no fill or outline) 3. Hide the layer from the legend 4. Create an expression that searches the above layer for intersecting features and returns the project number. We have recently implemented this to return plantation details from an invisible, underlying layer and seems to be working pretty good. Arcade expression below for reference (utilizes a search buffer distance for features that don't intersect directly) #feature being created
var BufferedFeature = Buffer($feature, 100, 'meters')
#intersects the above feature with the layer containing the desired attribute
var intersectLayer = Intersects(FeatureSetByName($map, 'Plantations Layer'),BufferedFeature);
#returns the value from the "Plantation" field
for (var f in intersectLayer){
return f.Plantation
}
... View more
06-02-2022
06:39 PM
|
0
|
0
|
1891
|
|
POST
|
Hi @Anonymous User. I've managed to isolate the cause of my issue - but need some guidance on a solution! I took the approach of commenting out all the lines, scheduling the code to run and one-by-one, uncommenting a line and rescheduling until I found which one was causing the problem. The below code shows that line 3 is causing the issues! import arcpy
from arcpy import env
#from arcgis.gis import GIS ###### This line is causing the Exception
import os
import time
from time import strftime
import datetime
import zipfile
from zipfile import ZipFile
# Access the stored password with keyring and sign into the GIS # https://community.esri.com/t5/arcgis-online-blog/connect-to-the-gis-in-python-scripts-without/ba-p/889867
import keyring
pw = keyring.get_password("ArcGISOnline", "Username") # Note: Username is Case Sensitive
gis = GIS("https://org.maps.arcgis.com", "Username", pw) # Note: Username is Case Sensitive
print("Connected to the GIS") Obviously this line is needed (first referenced in line 12 and strangely it works fine when running the script through IDLE or Task Scheduler when logged in - it only fails and throws the Exception: LOCALAPPDATA issue when scheduled through Task Scheduler and logged out. Tested that it worked by only commenting out Line 3 and got the following - "Exception: name 'GIS' is not defined".
... View more
06-01-2022
11:25 PM
|
0
|
1
|
3415
|
|
IDEA
|
@DerekBannon22 the issue was that only fields with domains were having their values wiped when a feature was split. Fields without domains (i.e. free text) retained their values as there was no split policy applied at all. Therefore, the above fix only applies to fields with domains as they have been given the split policy after initially being published without it (a few versions ago) and the default policy applied was to wipe the values - not duplicate.
... View more
06-01-2022
05:31 PM
|
0
|
0
|
4012
|
|
POST
|
UPDATE: After the most recent updates to ArcGIS Online (June 2022) it seems the below solution doesn't work. I've tried a few variations but none of them result in the split policy either being inserted or changed. Back to not having an option but to use ArcMap to republish the service as suggested here: FAQ: Is it possible to add or edit domains after a feature service is published in ArcGIS Online? (esri.com) Posted an Idea here to give us something that works! Update "Alter Domain (Data Management)" tool to up... - Esri Community We've finally got a solution to this issue (with assistance from ESRI Support). The JSON at the service URL for the hosted feature layer needs to be updated to either include or modify the split policy so that it reflects the desired behaviour ("Duplicate"). My workflow below: 1. Go to item page > click on sub-layer > open Service URL 2. Modify the URL to see the Admin settings 3. Scroll to the bottom of the page and select the "Update Definition" option 4. Clear the lastEditDate value (replace the value with "") 5. Scroll down to the fields list 6. Update any field domains where domain is NOT null with the below line of text: "splitPolicy" : "esriSPTDuplicate", Updated JSON below: 7. Click the "Update Layer Definition" button and whalla! Your features should now duplicate attributes in fields with coded domain values when split in ArcGIS Pro 2.9+
... View more
05-27-2022
12:13 AM
|
3
|
0
|
4843
|
|
IDEA
|
This sounds like this topic: Splitting tool wipes values from AGOL feature serv... - Esri Community for which we've just sorted a solution with assistance from ESRI Support. In summary, on layers published prior to 2.9, the split policy was set to "default" and ArcGIS Pro ignored it and duplicated the attributes. After 2.9, ArcGIS Pro honoured the policy, meaning we started losing attributes. The solution to this is to edit the JSON at the service admin URL and insert/modify the split policy to "Duplicate". More details in above post.
... View more
05-26-2022
11:50 PM
|
0
|
0
|
4049
|
|
POST
|
I've modified the tool to create a new table based on the feature service and then append the data instead. It loses the GlobalID info which is a bit annoying but not overly important (couldn't figure out how to preserve it) but overall, it works for what I need. # CREATING BACKUP OF FEATURE SERVICE TABLE / RELATED TABLE
print ("Exporting backup of feature service")
Outputfs = destFC + "_" + strftime("%Y%m%d_%H%M%S")
arcpy.management.CreateTable(destGDB, Outputfs, url_fl)
arcpy.management.Append(url_fl, destGDB + "\\" + Outputfs, "NO_TEST")
time.sleep(timeout) #add time delay to allow export to complete
print (name + " feature service exported to backup GDB: " + destGDB + "\\" + Outputfs)
... View more
05-26-2022
09:37 PM
|
0
|
0
|
867
|
|
POST
|
I've just tried running the tool directly through Pro on both machines...and it works fine - but with the below warning: This has me even more confused now as both machines are running on a Basic License, yet the data was exported as expected. I suspect this might have something to do with the python error, but I still don't understand why one will complain when the other doesn't and both are supposedly accessing the same Basic license.
... View more
05-26-2022
07:47 PM
|
0
|
1
|
871
|
|
POST
|
Hi. Wouldn't doing this require storing the password in clear text in the script? We shifted away from doing this to remove that vulnerability from our scripts and instead storing them in a password protected environment.
... View more
05-26-2022
07:23 PM
|
0
|
0
|
873
|
|
IDEA
|
This is a great idea. Would have been very useful in the rollout process of some new maps we've just undertaken.
... View more
05-25-2022
06:33 PM
|
0
|
0
|
757
|
|
IDEA
|
Yes - it would be good to be able to format and validate a field so that it records and displays a valid and recognisable phone number or email address. We have come across this use case too.
... View more
05-17-2022
05:51 PM
|
0
|
0
|
1102
|
|
POST
|
I tried removing the credentials and resaving them (using the below code) but it made no difference. ### Set password and optionally verify storage
import keyring
from arcgis.gis import GIS
username = input("Enter username: ")
password = input("Enter password: ")
keyring.set_password("ArcGISOnline", username, password)
#Optionally verify password storage
print("Verifying credentials: attempting to login")
try:
pw = keyring.get_password("ArcGISOnline", username)
gis = GIS("https://org.maps.arcgis.com", username, pw)
print("Connected to the GIS - credentials verified and stored.\n\n")
except:
print("Login failed - invalid credentials stored. Re-run to update credentials.\n\n")
... View more
05-17-2022
05:47 PM
|
0
|
0
|
3027
|
|
POST
|
Hi. Interesting. I did use a code sample to use keyring to store the credentials in the first place - is this what you are referring to? I might try updating the details again anyway and see if I get a different outcome.
... View more
05-17-2022
05:25 PM
|
0
|
0
|
3027
|
|
POST
|
I've included the sample code above now. The output GDB is on a network folder (directly mapped - not using a drive letter).
... View more
05-17-2022
05:22 PM
|
0
|
0
|
3027
|
|
POST
|
Code sample below from datetime import datetime, timedelta, date
# *****Update the below 7 lines*****
name = "ArcOnline Related Table" #Name of dataset for use in error email notification
url_fl = "https://services3.arcgis.com/1GMgEwg21aGmaBQf/arcgis/rest/services/ArcOnlineRelatedTable/FeatureServer/1" # Service URL for feature layer (TABLE/RELATED TABLE ONLY) to download as feature class
destGDB = r"\\a\folder\on\our\server\Data.gdb" #The GDB where the backup feature class will be created
destFC = "ArcOnlineRelatedTable" #The backup feature class name (no spaces - user _ or CamelCase)
monthlimit = datetime.today() - timedelta(days=30) # number of days to keep daily backups
yearlimit = datetime.today() - timedelta(days=365) # number of days to keep monthly backups (1st day of month only) - everything older will be deleted
timeout = 60 # number of seconds delay to allow the export to complete
while True: #If something fails in the main script under "try", the "except" section emails a notification to the GIS Inbox
try:
import arcpy
from arcpy import env
from arcgis import gis #Instead of signing in as follows (gis = GIS("https://org.maps.arcgis.com", "Username", "Password") this breaks it up so that you are able to call the sign in details independently
from arcgis.gis import GIS
from arcgis.features import FeatureLayer
import getpass
import requests
from time import strftime
import datetime
### Access the stored password with keyring and sign into the GIS # https://community.esri.com/t5/arcgis-online-blog/connect-to-the-gis-in-python-scripts-without/ba-p/889867
import keyring
pw = keyring.get_password("ArcGISOnline", "my_username")
gis = GIS("https://org.maps.arcgis.com", "my_username", pw)
print("Connected to the GIS")
# CREATING BACKUP OF FEATURE SERVICE TABLE / RELATED TABLE
print ("Exporting backup of feature service")
Outputfs = destFC + "_" + strftime("%Y%m%d_%H%M%S")
arcpy.conversion.TableToTable(url_fl, destGDB, Outputfs)
time.sleep(timeout) #add time delay to allow export to complete
print (name + " feature service exported to backup GDB: " + destGDB + "\\" + Outputfs)
print ("Filtering past backups")
arcpy.env.workspace = destGDB
FClist = arcpy.ListFeatureClasses(destFC + "*")
for fc in FClist:
datestamp = datetime.datetime.strptime(('{}'.format(fc))[-15:], "%Y%m%d_%H%M%S")
day = (datestamp.day)
print (fc + "..........Backup date:" + str(datestamp))
if datestamp < yearlimit: #data more than 365 days old
print (" Older than 12 months: delete backup")
arcpy.management.Delete(fc)
print ("Deleted")
elif datestamp < monthlimit: #fc more than 90 days old
if day == 1:
print (" 1st of month & 4-12 months old: retain as monthly backup") #fc from 1st of Month and more than 90 days old
else:
print (" Older than 3 months and not the 1st of the month: delete backup")
arcpy.management.Delete(fc) #fc NOT from 1st of Month and more than 90 days old
print ("Deleted")
else:
print (" Less than 3 months old: retain backup")
print ("Script finished")
break # Stops script here
except Exception as e:
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import smtplib
fromaddr = "me@org.wa.com.au"
toaddr = "me@org.wa.com.au"
msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = name + " backup process failed"
# Enter email body text below
body = "There has been an error backing up the feature service. Please check the script to troubleshoot any problems. Exception: " + str(e)
msg.attach(MIMEText(body, 'plain'))
server = smtplib.SMTP('smtp.org.com.au')
#No login required so this section is commented out
#server.login("youremailusername", "password")
server.sendmail(fromaddr, toaddr, str(msg))
print ("Script failed - email notification sent to me@org.com.au")
print ("Exception: " + str(e))
break # Stops script here
... View more
05-17-2022
05:18 PM
|
0
|
2
|
3027
|
|
POST
|
Sorry for the dodgy code sample - I normally do include a proper code sample instead of just screenshots. I suppose I was just trying to demonstrate that both were the same but showed different outcomes. Will make sure I include the code sample as well next time! I've also included a code sample above.
... View more
05-17-2022
05:11 PM
|
0
|
0
|
3031
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | Sunday | |
| 1 | 2 weeks ago | |
| 1 | 08-24-2025 06:11 PM | |
| 1 | a month ago | |
| 1 | 10-08-2024 09:01 PM |
| Online Status |
Offline
|
| Date Last Visited |
Monday
|