|
POST
|
A sample script using the REST API: import urllib, urllib2, json, sys, time, arcpy
# Credentials and feature service information
username = <username>
password = <password>
# addList (geometry and fields) : [ X_LON, Y_LAT, Name, C_long, F_date ]
addList = [
[ -8572606.3109, 4705898.3536000028, 'US Capitol', 20180822, '2018-08-22 12:00:00' ]
]
URL = "https://<server info>/arcgis/rest/services/example/FeatureServer/0/addFeatures"
# 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) # exit if no token
for item in addList :
f_date = int(time.mktime(time.strptime(item[4], "%Y-%m-%d %H:%M:%S")))*1000 # UTC in miliseconds
feature_data = [{
"attributes": { "Name": item[2], "C_long": item[3], "F_date": f_date },
"geometry": { "x": item[0], "y": item[1] }}]
# print feature_data
submitData = {
"features": json.dumps(feature_data),
"f": "json",
"token": token['token']
}
# print submitData
jsonResponse = urllib.urlopen(URL, urllib.urlencode(submitData))
jsonOutput = json.loads(jsonResponse.read())
print json.dumps(jsonOutput, indent=4, sort_keys=False)
# parse jsonOutput for results
... View more
08-22-2018
11:12 PM
|
2
|
1
|
3320
|
|
POST
|
You can also use the Rest API. See: Add Features and Update Features . There are forms to add and update features using the REST API. Sign in to your account. In the content section select the feature layer you want, then (on next page) select the specific layer. This will take you into the services directory and show you basic info about your layer. At the bottom of this page, under supported operations, there is a link to the Add Features and Update Features forms. I would suggest learning with a practice/backup feature until you are comfortable with the process.
... View more
08-22-2018
03:04 PM
|
2
|
2
|
3320
|
|
POST
|
Your whereClause as shown is missing a + sign and space before " IS NULL". When joining strings, I like to use .format as I find the code is a bit clearer. You might try something like: mayDevice = "{}_DEVICE_ID".format(mayFeature)
whereClause = "{} IS NULL".format(mayDevice)
... View more
08-21-2018
10:28 AM
|
1
|
0
|
3115
|
|
POST
|
I hit a timeout on my data request, so there are a lot of records; the json indicated: "exceededTransferLimit": true with perhaps 1,000 records returned. You may need to do something to limit your query results. I also noticed that you are not requesting the geometry ( 'returnGeometry': 'false' ) which would cause JSONToFeatures to fail. You should see something like this in your json: "geometry": {
"rings": [
[
[
-9165686.7350331135,
3936948.9098836873
],
[
-9165681.1218573805,
3936946.988356465
],
[
-9165681.5995294657,
3936947.138881634
],
[
-9165686.7350331135,
3936948.9098836873
]
]
]
}
... View more
08-20-2018
02:13 PM
|
1
|
0
|
9436
|
|
POST
|
And when you print(cslfJson), does it appear to be correctly formatted json and a feature?
... View more
08-20-2018
12:55 PM
|
1
|
2
|
9435
|
|
POST
|
Should you need unique items sorted: for k in d.keys():
print "{}: ".format(k),
for i in sorted(set(d[k])):
print i,
print
# results
# 1974: 2775 2983 2985 3004 3005 3006 3008 3021 27027
# 1970: 2183
... View more
08-17-2018
09:42 AM
|
1
|
0
|
1042
|
|
POST
|
Using set on a list will give unique elements: d = {'1974': [3005, 3008, 3008, 3008, 3008, 3005, 3005, 3005, 3005, 3008, 3008,
3006, 3006, 3004, 3004, 3004, 3004, 3004, 3004, 27027, 2775, 3021,
3021, 3005, 3005, 3008, 3008, 3008, 3008, 3008, 3005, 3005, 3008,
3008, 3008, 3006, 3006, 3004, 3004, 3004, 3021, 3021, 2775, 3005,
3008, 3005, 3005, 3004, 3004, 3004, 3005, 3005, 3005, 3005, 3005,
3008, 3008, 3008, 3005, 3005, 3005, 3005, 3005, 3005, 3008, 3008,
3008, 3008, 3008, 3006, 3004, 2985, 3021, 2775, 3005, 3005, 3005,
3008, 3008, 3008, 3008, 3008, 3005, 3005, 3005, 3005, 3005, 3006,
3004, 3004, 3004, 3004, 3005, 2983, 3021, 3021, 27027, 2775, 2775,
3005, 3005, 3005, 3004, 2983, 2983, 3005, 3005, 3008, 3008, 3008,
3008, 3008, 3008, 3005, 3005, 3005, 3005, 3005, 3005, 3005, 3005,
3008, 3006, 3006, 3004, 3004, 3004, 3004, 3004, 3004, 3008, 3005,
2985, 2985, 2983, 3021, 3021, 2775, 3005, 3005, 3008, 3008, 3005,
3008, 3008, 3008, 3008, 3004, 3004, 2983, 3005, 3005, 3005, 3005,
3008, 3008, 3008, 3008, 3008, 3005, 3005, 3006, 3006, 3006, 3006,
3004, 3004, 3004, 2985, 3005, 3005, 3005, 3005, 3005, 3008, 3008,
3008, 3008, 3008, 3008, 3008, 3008, 3005, 3005, 3005, 3005, 3005,
3005, 3008, 3006, 3006, 2985, 2985, 2985, 2985, 3021, 3021, 3021,
27027, 3021],
'1970': [2183, 2183, 2183, 2183, 2183, 2183, 2183, 2183]}
for k in d.keys():
print k, set(d )
# 1974 set([3008, 2983, 2985, 3021, 27027, 2775, 3004, 3005, 3006])
# 1970 set([2183])
... View more
08-17-2018
09:25 AM
|
1
|
1
|
1042
|
|
POST
|
Here's another of many ways: cursor = [ # rows in your geodatabase
[ '1960-01-01', 'A' ],
[ '1972-01-01', 'B' ],
[ '1980-01-01', 'C' ],
[ '1972-02-01', 'D' ],
[ '1980-02-01', 'E' ],
[ '1980-03-01', 'F' ],
[ '1960-02-01', 'G' ],
[ '1972-03-01', 'H' ],
[ '1972-04-01', 'I' ],
[ '1960-03-01', 'J' ]
]
d = {} # empty dictionary
# with arcpy.da.SearchCursor(in_fc,fields) as cursor:
# for row in cursor:
for row in cursor:
if row[0][:4] not in d:
d[row[0][:4]] = [row[1]]
else:
d[row[0][:4]].append(row[1])
print d
# {'1960': ['A', 'G', 'J'], '1972': ['B', 'D', 'H', 'I'], '1980': ['C', 'E', 'F']}
for k in d.keys(): # access years and films
print k
print d[k]
'''
1960
['A', 'G', 'J']
1972
['B', 'D', 'H', 'I']
1980
['C', 'E', 'F']
'''
... View more
08-16-2018
08:57 PM
|
1
|
3
|
4203
|
|
POST
|
Is Download ArcGIS Online Feature Service or ArcGIS Server Feature/Map Service the type of script you are seeking?
... View more
08-14-2018
12:44 PM
|
1
|
1
|
1191
|
|
POST
|
Working with a file geodatabase, I attempted to insert a large polygon feature and received an error: Spatial Index Grid Size is Invalid. Following the suggestion in this old thread and Common errors that may occur during editing, I deleted the spatial index, but did not rebuild it. What are the issues of not having a spatial index on a feature?
... View more
08-08-2018
04:03 PM
|
0
|
0
|
1920
|
|
POST
|
I haven't taken the approach that you have, but I would try something like the following. You will need to log in at some point to get a token, and it will time out eventually, but you can reuse it a number of times. If the layer is publicly shared, a token may not be required. <form ......>
<input type="hidden" id="token" name="token" value="your token goes here">
<input type="submit" value="Submit">
</form>
... View more
08-07-2018
12:55 PM
|
2
|
1
|
4250
|
|
POST
|
You may want to restructure your if/elif/else in your function so that it will always return something - perhaps a zero or 25 for any unknown value. if (fld == 'S1640'):
return 55
elif (fld == 'S1500'):
return 45
elif (fld == 'S1400'):
return 35
else: # for S1200 and any other value, just in case
return 25
... View more
08-03-2018
12:55 PM
|
2
|
0
|
9104
|
|
POST
|
Pass ROAD_MTFCC to your function, and in your function reference fld. Reclass(!ROAD_MTFCC!)
def Reclass(fld):
if(fld == 'S1200'):
return 25
# etc.....
... View more
08-03-2018
12:40 PM
|
2
|
0
|
9104
|
|
POST
|
I use something like this to get field information: arcpy.env.workspace = r"C:\Path\To\file.gdb"
fcList = arcpy.ListFeatureClasses()
for fc in fcList:
print "FC: {}".format(fc)
fields = arcpy.ListFields(fc)
for f in fields:
print "\t {}".format(f.name)
# other options:
# print f.baseName
# print f.aliasName
# print f.length
# print f.domain
# print f.type
# print f.editable
# print f.isNullable
# print f.required
# print f.scale
# print f.precision For describe to have a fieldInfo method, the feature class would need to be made into a feature layer: fcList = arcpy.ListFeatureClasses()
for fc in fcList:
print "FeatureClass: {}".format(fc)
fl = arcpy.MakeFeatureLayer_management(fc) # make it a layer
desc = arcpy.Describe(fl)
field_info = desc.fieldInfo
for index in range(0, field_info.count):
print "Field Name: {0}".format(field_info.getFieldName(index))
... View more
08-03-2018
09:40 AM
|
2
|
1
|
5317
|
| 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 |
02-12-2026
07:13 PM
|