|
DOC
|
@DevinBoyle_PCMCdo you know what line of the script it's failing at? A 403 would indicate an unauthorized access to the feature service, but this should not matter if you're using a File Geodatabase or Enterprise Geodatabase feature class.
... View more
11-17-2020
03:07 PM
|
0
|
0
|
68633
|
|
DOC
|
Jeffrey Steele try the following code below. Here are the steps: 1. Update the username, password, fromEmail, toEmail, smtpServer in the # Variables section: import requests, json, datetime, time, smtplib, math
from datetime import timedelta
from email.mime.text import MIMEText
# Disable warnings
requests.packages.urllib3.disable_warnings()
# Variables
username = 'jskinner_CountySandbox' # AGOL Username
password = '********' # AGOL Password
URL = 'https://services5.arcgis.com/JyUjaMA8RG5613cC/ArcGIS/rest/services/CitizenProblems_d15c40efcecc4c478fe252136f92aa03/FeatureServer/0/query' # Feature Service URL
uniqueID = 'OBJECTID' # i.e. OBJECTID
dateField = 'CreationDate' # Date field to query
hoursValue = 1 # Number of hours to check when a feature was added
fromEmail = '[email protected]' # Email sender
toEmail = ['[email protected]', '[email protected]'] # Email receiver(s)
smtpServer = 'smtp.gis.com' # SMPT Server Name
portNumber = 25 # SMTP Server port
# Create empty list for uniqueIDs
oidList = []
# Generate AGOL token
try:
print('Generating Token')
tokenURL = 'https://www.arcgis.com/sharing/rest/generateToken'
params = {'f': 'pjson', 'username': username, 'password': password, 'referer': 'http://www.arcgis.com'}
r = requests.post(tokenURL, data=params, verify=False)
response = json.loads(r.content)
token = response['token']
except:
token = ''
# Return largest ObjectID
whereClause = '1=1'
params = {'where': whereClause, 'returnIdsOnly': 'true', 'token': token, 'f': 'json'}
r = requests.post(URL, data = params, verify = False)
response = json.loads(r.content)
try:
response['objectIds'].sort()
except Exception as e:
print("Error: {0}".format(e))
OIDs = response['objectIds']
count = len(response['objectIds'])
iteration = int(response['objectIds'][-1])
minOID = int(response['objectIds'][0]) - 1
OID = response['objectIdFieldName']
# Query service and check if created_date time is within the last hour
if count < 1000:
params = {'f': 'pjson', 'where': "1=1", 'outFields' : '{0}, {1}'.format(uniqueID, dateField), 'returnGeometry' : 'false', 'token' : token}
r = requests.post(URL, data=params, verify=False)
response = json.loads(r.content)
for feat in response['features']:
createDate = feat['attributes'][dateField]
createDate = int(str(createDate)[0:-3])
t = datetime.datetime.now() - timedelta(hours=hoursValue)
t = time.mktime(t.timetuple())
if createDate > t:
oidList.append(feat['attributes'][uniqueID])
else:
y = minOID
x = minOID + 1000
ids = response['objectIds']
newIteration = (math.ceil(iteration/1000.0) * 1000)
while y < newIteration:
if x > int(newIteration):
x = newIteration
where = OID + '>' + str(y) + ' AND ' + OID + '<=' + str(x)
print('Querying features with ObjectIDs from ' + str(y) + ' to ' + str(x))
params = {'f': 'pjson', 'where': where, 'outFields' : '{0}, {1}'.format(uniqueID, dateField), 'returnGeometry' : 'false', 'token' : token}
r = requests.post(URL, data=params, verify=False)
response = json.loads(r.content)
for feat in response['features']:
createDate = feat['attributes'][dateField]
createDate = int(str(createDate)[0:-3])
t = datetime.datetime.now() - timedelta(hours=hoursValue)
t = time.mktime(t.timetuple())
if createDate > t:
oidList.append(feat['attributes'][uniqueID])
x += 1000
y += 1000
print(oidList)
# Email Info
SUBJECT = 'New Features Added'
TEXT = "Features with {0}s {1} were added.".format(uniqueID, oidList)
# If new features exist, send email
if len(oidList) > 0:
smtpObj = smtplib.SMTP(host=smtpServer, port=portNumber)
msg = MIMEText(TEXT)
msg['Subject'] = SUBJECT
msg['From'] = fromEmail
msg['To'] = ", ".join(toEmail)
smtpObj.sendmail(fromEmail, toEmail, msg.as_string())
print("Successfully sent email")
smtpObj.quit() 2. Add a new point to the Citizens Problem feature service 3. Execute the script
... View more
11-10-2020
05:43 AM
|
0
|
0
|
19833
|
|
DOC
|
Jeffrey Steele can you invite my AGOL account to a Group in AGOL that you have the service shared to? My AGOL account is jskinner_CountySandbox. I can take a look at the service and see how to modify the script.
... View more
11-06-2020
02:02 PM
|
0
|
0
|
19833
|
|
DOC
|
Devin Boyle I went ahead and updated the code above. It should no longer try to zip the lock files in the File Geodatabase. Try the updated version.
... View more
11-02-2020
05:31 PM
|
0
|
0
|
68695
|
|
DOC
|
Gary Christensen, yes you will need these GeoEvent Definitions to be created. What I do is add an output to the GeoEvent service. You don't even have to attach the output to an input/processor, just add it in so you can successfully publish the GeoEvent service. Turn on the input so event(s) are pushed to the GeoEvent service, which should create the GeoEvent Definitions. Once these are created, you can add the Field Mapper processor.
... View more
10-26-2020
08:03 AM
|
1
|
0
|
5624
|
|
POST
|
Scott Foster you can use ArcGIS Pro's Feature Class to Feature Class tool to write the AGOL Survey123 feature service to a geodatabase feature class.
... View more
10-23-2020
07:59 AM
|
0
|
0
|
10530
|
|
POST
|
Hi Sushil, You will need 3 separate MXDs referencing the correct Oracle instance, and then create the SD file. I worked with a customer where we did something similar. We had a script that would copy the MXD to the desired environment, remap the MXDs layers to the other Oracle instance, then publish the service.
... View more
10-22-2020
08:17 AM
|
0
|
1
|
1188
|
|
POST
|
Are you working with ArcGIS Online or Portal hosted feature services?
... View more
10-22-2020
04:16 AM
|
0
|
2
|
7185
|
|
POST
|
Hi Matthew, You could truncate the service and then add the features if editing is enabled on the feature service: import pandas as pd
from arcgis.gis import GIS
# Variables
portal = 'https://portal.esri.com/portal'
username = 'jskinner@ESRI'
password = '*******'
# Create connection to AGOL/Portal
gis = GIS(portal, username, password, verify_cert=False)
# Publish feature services from DF
df1 = pd.DataFrame([["foo", -90.0, 30.0], ["bar", -91.0, 31.0]], columns = ["ID", "Longitude", "Latitude"])
df1SEDF = df1.spatial.from_xy(df1, "Longitude", "Latitude")
dataFrameLayer = df1SEDF.spatial.to_featurelayer("DataFrame to a layer", gis)
# Get Item ID of previous published data frame
searchResults = gis.content.search('title:DataFrame to a layer AND owner:{0}'.format(username), item_type='Feature Layer')
sourceId = searchResults[0]['id']
# Reference layer in feature service
fLayer = gis.content.get(sourceId)
editTable = fLayer.layers[0]
# Truncate feature service
editTable.manager.truncate()
# List of edits as dictionaries
addFeatures1 = {
"attributes" : {
"id" : "foo",
"longitude" : -90.0,
"latitude" : 30.0
},
"geometry":
{"x": -90.0, "y": 30.0}
}
addFeatures2 = {
"attributes" : {
"id" : "fighter",
"longitude" : -91.0,
"latitude" : 31.0
},
"geometry":
{"x": -91.0, "y": 31.0}
}
# Add features
editTable.edit_features(adds=[addFeatures1, addFeatures2])
... View more
10-21-2020
11:51 AM
|
3
|
4
|
7185
|
|
POST
|
Here is an example on how to create a token using Python: import requests, json
# Disable warnings
requests.packages.urllib3.disable_warnings()
portal = 'portal.esri.com'
username = "jskinner@ESRI"
password = "**********"
tokenURL = 'https://{0}:7443/arcgis/sharing/rest/generateToken/'.format(portal)
params = {'f': 'pjson', 'username': username, 'password': password, 'client': 'requestip'}
r = requests.post(tokenURL, data = params, verify=False)
response = json.loads(r.content)
token = response['token']
print(token)
... View more
10-21-2020
10:40 AM
|
0
|
0
|
1876
|
|
POST
|
Hi Curt, I had a customer recently run into the same issue, and then I found the following bug: BUG-000089545 : GeoFences are not synchronized when a feature is deleted from a feature service. It looks like this bug is still relevant at 10.8.1. I did some testing and found that the only way to remove Geofences through the GeoFence Synchronization Rules is to designate a date field for the Time Extent End parameter.
... View more
10-21-2020
08:42 AM
|
0
|
0
|
1935
|
|
DOC
|
Jamie Leitch instead of using this tool, you can simply use ArcGIS Pro's Feature Class to Feature Class tool.
... View more
10-16-2020
09:58 AM
|
0
|
0
|
17062
|
|
DOC
|
Does the code work when you run it in a Python IDE (such as IDLE)? Can you post the code your trying to execute? This document will provide you the steps to properly post your code: https://community.esri.com/docs/DOC-8691-posting-code-with-syntax-highlighting-on-geonet
... View more
10-16-2020
08:59 AM
|
0
|
0
|
19833
|
|
POST
|
Kaitlyn Abrahamson you can use the following code to export the images: import os, arcpy
# Variables
tbl = r"C:\Temp\Python\Test.gdb\Graffiti__ATTACH" # Path to attachment table
fldBLOB = 'DATA' # Field name of Blob data type field in attachment table
fldAttName = 'ATT_NAME' # Field name in attachment table that contains attachment name
outFolder = r"C:\Temp\Python\Attachments" # Output folder to export attachments to
with arcpy.da.SearchCursor(tbl,[fldBLOB,fldAttName]) as cursor:
for row in cursor:
binaryRep = row[0]
fileName = row[1]
# save to disk
open(outFolder + os.sep + fileName, 'wb').write(binaryRep.tobytes())
print('Finished')
... View more
10-16-2020
07:58 AM
|
8
|
2
|
20073
|
|
DOC
|
Hammad Khalid you will run the code on any machine that has python installed, for example, on a machine that has ArcGIS Pro or ArcGIS Desktop installed. See the following document on how you can use Windows Task Scheduler to execute the python script.
... View more
10-16-2020
03:18 AM
|
0
|
0
|
19833
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 07-08-2026 12:27 PM | |
| 4 | 05-07-2020 05:14 PM | |
| 1 | 03-25-2026 04:16 AM | |
| 1 | 03-16-2026 01:00 PM | |
| 1 | 12-22-2025 10:39 AM |
| Online Status |
Offline
|
| Date Last Visited |
yesterday
|