|
POST
|
There is a link to some code in this blog article that gets a token: Using Python to push updates to a hosted feature service from an external source | ArcGIS Blog. Here are the basic steps: import urllib
import urllib2
import json
# Credentials and feature service information
username = '<username>'
password = '<password>'
URL = "<the services url you want to connect to>"
# obtain a token
referer = "http://www.arcgis.com/"
query_dict = { 'username': username, 'password': password, 'referer': referer }
query_string = urllib.urlencode(query_dict)
url = "https://www.arcgis.com/sharing/rest/generateToken"
token = json.loads(urllib.urlopen(url + "?f=json", query_string).read())
if "token" not in token:
print(token['error'])
sys.exit(1)
query_dict = { "f": "json", "token": token['token'] }
# query your services url
jsonResponse = urllib.urlopen(URL, urllib.urlencode(query_dict))
... View more
06-25-2016
10:57 AM
|
0
|
2
|
3317
|
|
POST
|
I have had similar issues with AGO; I have no experience with Portal. I found the "Sort Coded Value Domain" tool (Data Management - Domains) to be helpful.
... View more
06-25-2016
09:55 AM
|
0
|
0
|
678
|
|
POST
|
Once you get your addresses into a domain, you may want to use the Sort Domain tool to better organize the domain. You can sort by codes or by descriptions.
... View more
06-09-2016
02:35 PM
|
0
|
0
|
1770
|
|
POST
|
Are you sure you want a dropdown with 400+ choices? That would probably be difficult to navigate. If the answer is still yes, you could import your address list into a table (using Excel to Table, for example), then use the Table to Domain tool to create a domain. The field would then be set to take its value from the domain list dropdown. You may want to split the address into parts for several smaller dropdowns: number part, street name, street type, etc.
... View more
06-09-2016
02:01 PM
|
3
|
2
|
1770
|
|
POST
|
I have been working on a python script to query a feature service hosted on ArcGIS Online. It may give you an idea of what is involved. It uses the REST API. Basically the steps are: 1. Log in to get a token; 2. Format a query to select recent updates; 3. Loop through the returned JSON data and copy to your database. Here is a code sample that will help take you through the process of getting the data. import arcpy, urllib, urllib2, json, sys, time, datetime, collections
from datetime import datetime, timedelta
# how far back do you want to go? Remember AGO uses GMT / UTC.
H = 220
date_H_hours_ago = datetime.now() - timedelta(hours=H)
# Credentials and feature service information
# URL, referrer and tokenurl may vary based on ArcGIS Online or your server setup
username = '<username>'
password = '<password>'
URL = "https://<server.arcgis.com/AbxQRxx3etc>/arcgis/rest/services/<feature service>/FeatureServer/<layer>/query"
referer = "http://www.arcgis.com/"
tokenurl = "https://www.arcgis.com/sharing/rest/generateToken"
# obtain a token
query_dict = { 'username': username, 'password': password, 'referer': referer }
query_string = urllib.urlencode(query_dict)
token = json.loads(urllib.urlopen(tokenurl + "?f=json", query_string).read())
if "token" not in token:
print(token['error'])
sys.exit(1)
query_dict = {
"where" : "EditDate >= DATE '"+date_H_hours_ago.strftime("%Y-%m-%d %H:%M:%S")+"'",
"outFields" : "OBJECTID, EditDate",
"returnGeometry" : "true",
"f": "json", "token": token['token'] }
# to select all fields use: "outFields" : "*",
# to select individual fields use comma delimited list: "outFields" : "OBJECTID, EditDate",
# a date certain: "where" : "EditDate >= DATE '2016-05-29 18:30:00'",
# this morning at 2 am: "where" : "EditDate >= DATE '"+(datetime.now()).strftime("%Y-%m-%d 02:00:00")+"'",
# some time ago: "where" : "EditDate > DATE '"+date_H_hours_ago.strftime("%Y-%m-%d %H:%M:%S")+"'",
# if you do not want geometry: "returnGeometry" : "false",
# results in json format using POST method
jsonResponse = urllib.urlopen(URL, urllib.urlencode(query_dict))
features = json.loads(jsonResponse.read(),
object_pairs_hook=collections.OrderedDict)[u'features']
# print json.dumps(features, indent=4, sort_keys=False) # formatted json
print 'ObjectID\tEditDate'
for feature in features:
# AGO uses GMT/UTC, you may wish to convert to local time
editTime = time.strftime('%c', time.localtime(feature['attributes']['EditDate']/1000))
print str(feature['attributes']['OBJECTID']) + '\t' + editTime
# if you wanted geometry; AGO returns web mercator, reproject if necessary
print "x: " + str(feature['geometry']['x'])+ "\ty: " + str(feature['geometry']['y'])
# WGS 1984 : (4326) Lat/Lon
# WGS 1984 Web Mercator (auxiliary sphere) : (102100) or (3857)
ptGeometry = arcpy.PointGeometry(arcpy.Point(feature['geometry']['x'],feature['geometry']['y']),
arcpy.SpatialReference(3857)).projectAs(arcpy.SpatialReference(4326))
print "lon: " + str(ptGeometry.firstPoint.X) +"\tlat: " + str(ptGeometry.firstPoint.Y)
# add code to insert into another geodatabase You will probably need to adjust the script to distinguish between new entries and updated entries by using the CreateDate and EditDate fields (edit tracking) when inserting the data in your db. To set up the script to run at specified times, see the blog: Scheduling a Python script or model to run at a prescribed time | ArcGIS Blog. You may also find useful code at GitHub - Esri/ArcREST, and consider asking your question in the REST API or Python sections. If Collector is used in off-line mode, the Create/EditDate field is set when the feature is collected and not when it is synced. Features collected off-line and not synced before the script's scheduled time could be missed if only edit/create times are used.
... View more
06-05-2016
06:32 PM
|
1
|
0
|
1925
|
|
POST
|
Thanks Joshua for the tips and the code example. It has been most helpful in learning about generators. I hope this has also helped Ana in her project. About the use of the modulus operator, I thought it would be easier to keep track of one number instead of two for seeding the generator for Ana's needs. If she started at 0 and did 100 records, then she would use 100 for the seed the next time. When she reaches 3380, the generator would need to be modified to produce a new sequence of codes, such as 'ZAA'.
... View more
05-10-2016
03:16 PM
|
0
|
1
|
1476
|
|
POST
|
I am also new to generators, but here's my code. You might need to trap errors if you go past the limit. (Thanks to Joshua and Dan for the introduction to generators.) def gen(x):
UC = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
cr_vals = [c + r for c in UC for r in UC]
while True:
yield str(x / 676 + 5) + cr_vals[x % 676]
x+=1
g = gen(0)
# print all combinations
for loop in range(0, 3380):
print next(g)
... View more
05-10-2016
12:01 PM
|
1
|
4
|
1476
|
|
POST
|
I like Dan's code: UC = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
cr_vals = [c + r for c in UC for r in UC]
for j in range(5,10) :
for i in range(0,676) :
print str(j) + cr_vals But can it be put in a generator?
... View more
05-10-2016
10:52 AM
|
0
|
1
|
1476
|
|
POST
|
This will produce the codes, but it should be in a generator. def base(decimal ,base) :
list = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
answer = ""
while decimal != 0 :
answer += list[decimal % base]
decimal /= base
return answer[::-1]
# prints 3379 codes - 5AA to 9ZZ
for j in range(5, 10) :
for i in range(0,676) :
x = base(int(i % 676),26)
if len(x) == 0 :
print str(j) +'AA'
elif len(x) == 1 :
print str(j) +'A' + str(x)
else : print str(j) + str(x)
... View more
05-10-2016
10:43 AM
|
1
|
2
|
1741
|
|
POST
|
If the script only needs to change the month text in a standardized file name, try using the datetime module. import datetime
month = int(datetime.datetime.now().strftime("%m"))
year = int(datetime.datetime.now().strftime("%y"))
month_lst = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jly',
'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
last_month = month -1
last_year = year
if last_month < 1 : last_month = 12; last_year = year -1
print month_lst[month-1], # array index starts at 0, subtract 1
print
print str(year) + month_lst[month-1] + 'Res.DBF'
print str(last_year) + month_lst[last_month-1] + 'Res.DBF'
print
print str(year*100 + month) + '_Res.DBF' Just insert the month name where you need it in the file name. Script would then adjust without user input. Edit: As an afterthought, I tend to use numbers for months in file names as it helps with the sort order.
... View more
05-04-2016
02:10 PM
|
3
|
1
|
925
|
|
POST
|
I don't believe a time-out can be set for collector. You can do one of two things: 1. Use the device's security to lock access to the device after a preset time (you may also be able to do this with an app lock). 2. Use Collector's "Switch Account" option and remove the account. This would require adding the account and signing back in for the next session.
... View more
03-22-2016
01:48 PM
|
0
|
0
|
682
|
|
POST
|
If you are comfortable with using the REST API to edit the json file ... In the types section of your feature service, each type has a template section. When you change the attribute that controls the symbology, it will use the this template to set default values. Using the example json below, when your feature's symbol attribute is set to "SymbolValue", the template will set Atribute1 to use "SomeValue" and Attribute2 will be inherited because its value is null. If you want Attribute1 to be inherited, replace "SomeValue" (in line 20) with the word null (it will then look similar to line 21). You do not want to change "SymbolValue" (line 19 in the example) as it sets your symbology. When working with the REST API, you should backup your feature service before making changes. Experiment with a test feature service to become familiar with the REST API. Use jsonlint.com to validate your json. I would also suggest that you only update the types section with the API. {
"types": [{
"id": "SymbolValue",
"name": "SymbolAttribute",
"domains": {
"Attribute1": {
"type": "inherited"
},
"Attribute2": {
"type": "inherited"
}
},
"templates": [{
"name": "SymbolAttribute",
"description": "",
"drawingTool": "esriFeatureEditToolPoint",
"prototype": {
"attributes": {
"Symbol": "SymbolValue",
"Attribute1": "SomeValue",
"Attribute2": null
}
}
}]
}]
}
... View more
03-14-2016
09:55 AM
|
1
|
0
|
2576
|
|
DOC
|
While I have only worked with AGO, it is my understanding that server would work much the same as AGO. You would be accessing the feature via the REST API. In the script that Jake attached, you would need to change username, password, baseURL, tokenURL, and referer in lines 4 through 6. For example, baseURL would point to your servers REST point. Instead of pointing to "http :// services.arcgis.com /dlFJXQQUk /arcgis/rest/services/DamagedBuildings/FeatureServer/0" , change the "services.arcgis.com/dlFJXQQUk" to point to your server. I would suggest looking at the REST API documentation for Server.
... View more
03-01-2016
05:17 PM
|
0
|
0
|
42453
|
|
POST
|
Have you tried it without the new line codes (\n\n) ? "MODDATE <> MODDATE_1"
... View more
03-01-2016
09:35 AM
|
1
|
0
|
1196
|
|
POST
|
Glad it worked. It was a group effort. Check out Some Python Snippets. It will help you with learning Python.
... View more
02-24-2016
02:00 PM
|
1
|
1
|
578
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 10-27-2016 02:23 PM | |
| 1 | 09-09-2017 08:27 PM | |
| 2 | 08-20-2020 06:15 PM | |
| 1 | 10-21-2021 09:15 PM | |
| 1 | 07-19-2018 12:33 PM |
| Online Status |
Offline
|
| Date Last Visited |
09-15-2025
02:54 PM
|