|
POST
|
Thanks. I figure it's something simple but struggling to find an example that clearly breaks down the different components in a way I understand. Thought I was returning the value on the 2nd last line, but obviously not.
... View more
07-15-2021
06:22 PM
|
0
|
1
|
3978
|
|
POST
|
Thanks @DanPatterson I had seen that post. I suppose that wasn't quite what I was looking for in that it returns an existing value instead of passing (or "continuing") onto the next row - I couldn't confirm if it was still recalculating the field with the existing value or actually skipping the row.
... View more
07-15-2021
05:45 PM
|
0
|
0
|
3987
|
|
POST
|
Hi @JoeBorgione I think this is what I'm looking for. Trying to implement now and see how it performs, but struggling with my newness to arcade and getting my head around the structure. var row1 = $feature['featureclass.Work_Centre']
var row2 = $feature['jointable.csv.WorkCentre']
for(var r in row1) {
if (r==row2) continue;
if (r!=row2);
row2;
} Essentially in the code section of the Calculate Field tool I'm, trying to read 2 fields in a feature class joined to a table and compare the 2 fields. If values match, continue, if not, return value from the join table (row2). Any pointers on where I've gone wrong? It told me it was valid, but when I ran it, all values were calculated as Nulls instead of being left as they were or updated with new values.
... View more
07-15-2021
05:43 PM
|
0
|
0
|
3990
|
|
POST
|
So I know that in python you can write if-else statements and use "pass" to skip doing something if that is desired. I've trawled the web on Arcade and can't find an equivalent to the pass option in python. Does this exist? i.e. - I have a feature class and table joined together. I want to compare 2 fields to see if they match (if FieldA == FieldB). If they match, do nothing (pass), if not, return FieldB. I know I could simply return FieldA (as per this solution in this post) but I want to see if by skipping instead of returning FieldA, it might improve the speed of the calculation if it can skip values instead of returning the original value??? P.S. I couldn't actually get it to work in python - it didn't seem to like the joined field names (i.e. Table1.FieldA == Table2.csv.FieldA). I did get it to work on a an un-joined feature class (i.e. FieldA == FieldB). I'm guessing it was the "dots" between the table name and the field name that was confusing it.
... View more
07-14-2021
11:59 PM
|
0
|
7
|
4053
|
|
POST
|
So I'm sure this has to be possible, and I just haven't googled the correct terminology yet. We have a number of feature services for different field based tasks (served up through offline enabled webmaps in Field Maps) and many have a common feature which is to record the Field Officer name. We can't use the Creator or Editor fields as the data is created in the office by a planner, and is edited multiple times by different people. We want to record which Field Officer manages an operation over multiple operation types (thus multiple feature services). Unfortunately this means we have many lists of names that we have to update to add/remove people as they start/leave/move around the business. Is there a way to have a single list source that is replicated to/syncronsied with the Domains of specified fields and feature services?
... View more
07-14-2021
09:00 PM
|
0
|
0
|
798
|
|
IDEA
|
So with Pro 2.8, we got the much wanted improvements to the Append tool when appending features to a feature service in ArcOnline. This reduced upload times when appending hundreds or thousands of features from many, many mintutes/hours to mere seconds. It would be great if the same sort of improvement could be applied to the Delete Rows tool for when you're trying to do the opposite (still painfully slow).
... View more
07-14-2021
12:28 AM
|
10
|
22
|
9005
|
|
IDEA
|
I have been intending to log this very same request over the last few weeks and kept forgetting - looks like I was beaten to it by @MarcelSt-Germain. All the same, I have learnt that you can filter by broken links (Thanks @KoryKramer - this will be handy) but also support the idea for an indicator at the grouped layer level showing broken links of the sub-layers. You're not always expecting broken links and therefore won't look for them, and in our maps, almost always are buried in Group Layers too.
... View more
07-11-2021
07:02 PM
|
0
|
0
|
1602
|
|
POST
|
Tried that but got the following error immediately; ImportError: cannot import name 'strptime' from 'datetime' (C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\datetime.py) I assume that's because strptime is coming from within the datetime class and not the datetime module (something someone else pointed out to me in an unrelated post.
... View more
07-09-2021
01:31 AM
|
0
|
0
|
3075
|
|
POST
|
I just tried your solution and ran the problem script by itself and got the following error; Exception: module 'datetime' has no attribute 'strptime' So instead I added "import datetime" line at Line 23 and left the rest of the script as it was originally. It worked standalone, and also in the batch run as desired. Thanks for the pointer. One day I'll get my head around all of the in's and out's of this!
... View more
07-09-2021
12:57 AM
|
0
|
2
|
3098
|
|
POST
|
Hi All. I've just tried to implement a single python script that iterates through a list of other python files with the aim of not having dozens of independent Task Schedule items. I've got the below code working - with 1 flaw (so far); import glob,os
#https://stackoverflow.com/questions/64016426/how-to-run-multiple-python-scripts-using-single-python-py-script
os.chdir(r"\\my\server\folder") # locate ourselves in the directory containing the python files to run
for script in sorted(glob.glob("*.py")):
if not script.startswith (("1.", "2.")):
print ("Found: " + script)
with open(script) as f:
contents = f.read()
print ("Running " + script)
exec(contents)
print ("Script complete") The script successfully lists all the python files in the folder (and also to exclude 2 which are a template and the script being run above), and it successfully runs through the first script found. When it gets to the 2nd, 3rd, ... scripts though I get the below error; "Exception: type object 'datetime.datetime' has no attribute 'datetime'" Obviously, you need to see the script to understand context, so here it is. From what I can see, it is failing somewhere between Lines 50 and 58 (based on the print statements that come out before the error occurs). from datetime import datetime, timedelta, date
# *****Update the below 6 lines*****
name = "My Hosted Feature Service" #Name of dataset for use in error email notification
url_fl = "https://services3.arcgis.com/SERVICEID/arcgis/rest/services/SERVICENAME/FeatureServer/0" # Service URL for feature layer to download as feature class
destGDB = r"\\My\output\folder\and\GDB.gdb" #The GDB where the backup feature class will be created
destFC = "BackupID1" #The backup feature class name (no spaces - use _ 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
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://abcde.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 json
import requests
from time import strftime
def getSecrets():
# Secrets from file stored outside of revison control
with open(r"\\none\of\your\bees.json") as f:
secrets = json.load(f)
return secrets
secrets = getSecrets()
# Get login credentials # http://docs.python-requests.org/en/latest/user/advanced/
s = requests.Session()
url_gis="https://abcde.maps.arcgis.com"
s.user = (secrets["username"])
s.pw = (secrets["password"])
#SIGNING INTO ARCGIS ONLINE
print ("Signing into ArcGIS Online")
source = gis.GIS(url_gis, s.user, s.pw) #signing in
print ("Signed into ArcGIS Online")
# CREATING BACKUP OF FEATURE SERVICE # https://community.esri.com/t5/python-questions/using-arcpy-to-copy-a-portal-feature-service-to-a-fgdb-feature/m-p/4285#M394
fl = FeatureLayer(url_fl)
fs = fl.query()
print ("Exporting backup of feature service")
fs.save(destGDB, destFC + "_" + strftime("%Y%m%d_%H%M%S"))
time.sleep(10) #add 10 seconds delay to allow export to complete
print (name + " feature service exported to backup GDB: " + destGDB + "\\" + destFC + strftime("_%Y%m%d_%H%M%S"))
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...#does more stuff
... View more
07-08-2021
11:35 PM
|
0
|
4
|
3115
|
|
POST
|
Hi Brains Trust. I've got a "problem" that I haven't been able to figure out through the googs, but it's also not business critical and I can ignore it, but the desire to know more is spurring me on. The below script is part of a larger code which downloads a feature service from ArcOnline (Point, Polyline or Polygon) and saves a copy as a feature class in a GDB on our server. The "issue" I've found is that where it has (fs.save (destGDB, destFC...) on Line 40, if the feature service has 0 rows, it changes the feature class to a table with 0 rows. It would be nice if it preserved the Geometry type (i.e. still shows as a point/line/polygon) despite having no data. Any ideas how I could make this happen? I did try swapping the fs.save() for arcpy.conversion.FeatureClassToFeatureClass() but that returned an Object error (I assume because the input wasn't a feature class but was a feature layer [fs]). I did manage to figure out how to determine the Geometry type of the feature service using desc = arcpy.Describe(fs) and print (desc.shapeType) but not pass it to the export step. name = "Dataset Name" #Name of dataset for use in error email notification
url_fl = "https://services3.arcgis.com/###############/arcgis/rest/services/##################/FeatureServer/1" # Service URL for feature layer to download as feature class
destGDB = r"C:\temp\download.gdb" #The GDB where the backup feature class will be created
destFC = "DailyBackup" #The backup feature class name (no spaces - user _ or CamelCase)
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://#####.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 json
import requests
from time import strftime
def getSecrets():
# Secrets from file stored outside of revison control
with open(r".\secrets.json") as f:
secrets = json.load(f)
return secrets
secrets = getSecrets()
# Get login credentials # http://docs.python-requests.org/en/latest/user/advanced/
s = requests.Session()
url_gis="https://#####.maps.arcgis.com"
s.user = (secrets["username"])
s.pw = (secrets["password"])
#SIGNING INTO ARCGIS ONLINE
print ("Signing into ArcGIS Online")
source = gis.GIS(url_gis, s.user, s.pw) #signing in
print ("Signed into ArcGIS Online")
# CREATING BACKUP OF FEATURE SERVICE # https://community.esri.com/t5/python-questions/using-arcpy-to-copy-a-portal-feature-service-to-a-fgdb-feature/m-p/4285#M394
fl = FeatureLayer(url_fl)
fs = fl.query()
print ("Exporting backup of feature service")
fs.save(destGDB, destFC + "_" + strftime("%Y%m%d_%H%M%S"))
time.sleep(10) #add 10 seconds delay to allow export to complete
print (name + " feature service exported to backup GDB: " + destGDB + "\\" + destFC + strftime("_%Y%m%d_%H%M%S"))
break # Stops script here
except Exception as e:
#code here sends email if script fails
break # Stops script here
... View more
07-08-2021
11:25 PM
|
0
|
0
|
872
|
|
POST
|
Thanks for the pointers and suggestions. It would still be good to get an answer on why such basic stuff is being downgraded, but will still look into the links you've provided. At present, the Vector Tile Packages are mainly for use to enable efficient offline downloads in Field Maps and to mimic a service provided by another platform that many of our staff love but isn't compatible with Field Maps.
... View more
06-28-2021
05:04 PM
|
0
|
0
|
1607
|
|
POST
|
I have a Vector Tile Package created from ArcGIS Pro. The first time I created this package (Christmas 2020), the below labels came out as expected. When a ran an update 6 months later (June 2021), the labels for the 2 layers shown below have been getting downgraded/modified for no apparent reason. I have not changed the style of these labels at all, except for the purple labels which was to change the scale at which the labels would appear. Yet after trying multiple changes to the text styles, the continue to come out black instead of purple. They are simple formats (no complex symbology or halos, etc) so don't know what I'm missing (I've read the documentation on the limitations of Vector Tile Packages and label symbology/positioning). In ArcGIS Pro; In the Vector Tile Package; The purple features labelling symbology/positioning; The black cirlces label symbology/positions;
... View more
06-27-2021
11:19 PM
|
1
|
2
|
1670
|
|
POST
|
Thanks @DavidPike and @jcarlson for your answers. All 3 were helpful and will be of use in the future. I hadn't seen the AGO Assistant before and my python is probably just beyond entry level so can read and rearrange but not really any good at writing from scratch. Cheers! A couple of quick notes though - I've just test the ArcGIS Online Assistant to try the find/replace function and whilst the URL was indeed replaced, the layer information wasn't. When you look at it in the map, the name is the old name and the page opened when you click on the item properties is the old items page. It really is just a replacement of the underlying URL but nothing else. Also, I tried the find and print python script and whilst it sort of works, it only printed off about half a dozen maps and their layers - not the few dozen that I would expect to see. The maps printed were from an assortment of users in the org (including the admin account used to run the process) but defintely fell short of what I expected to see - and I can't see why. Haven't tried script 3 as I'm not confident (yet) that I want to try that option until I understand it a little better.
... View more
06-21-2021
05:26 PM
|
2
|
0
|
3576
|
|
POST
|
So I've googled and searched and thought I'd just ask. Is there any way to search through all the maps in an organisation to find which ones contain a particular layer? I ask as I want to replace a layer with a completely new one (not overwritten) and that means updating all the maps that contained the old one - but I have to open them all individually. Surely there's an easier way?
... View more
06-20-2021
07:08 PM
|
1
|
4
|
3680
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | Thursday | |
| 1 | 08-24-2025 06:11 PM | |
| 1 | 3 weeks ago | |
| 1 | 10-08-2024 09:01 PM | |
| 1 | 06-05-2025 12:17 AM |
| Online Status |
Offline
|
| Date Last Visited |
yesterday
|