Python scripts using Requests module and ArcGIS REST services.
- employing tokens
- to be fleshed-out later
Python dict consisting of key/value pairs which are submitted to the API as the HTTP query string. Most can use empty strings as their value, but some are required to have explicit values in order to return any results from the API. The get()
method of the requests
module takes this dict, along with the url string, to submit a GET request and store the response
object.
See ESRI Feature Service Documentation
- Must be a SQL
where
clause that evaluates to True - formatted as a Python string
- no URL encoding is required
- supported operators
( '<=' | '>=' | '<' | '>' | '=' | '!=' | '<>' | LIKE )
(AND | OR)
(IS | IS_NOT)
(IN | NOT_IN) ( expr )
COLUMN_NAME BETWEEN LITERAL_VALUE AND LITERAL_VALUE
- examples:
"where": "1=1",
'where': 'OBJECTID > 0',
"where": "year = 1998",
"where": """year_of_const LIKE '%1985%' OR year_of_const LIKE '%1986%'""",
"where": "CITY_NAME = 'Barrington'",
- note: string literals must be single-quoted
- see more examples in the REST API where documentation
- List of fields to be returned from the API query
- formatted as a Python string, with a comma-delimited (no space) list of fieldnames
- use an asterisk (quoted) to return all fields
- examples:
'outFields': '*',
"outFields": "Match_addr,Addr_type",
- when set to
true
the GeoJSON representation of the feature geometry is included in the response - when set to
false
the geometry is not included- use this option when you need to get attribute field values and have no need for the geometry, which can be very large
- spatial reference of the returned geometry features
- can be an empty string, in which case, according to ESRI documentation, the SRID returned is "the same as the map"
- typically
SRID: 3857 - WGS 84 Web (pseudo) Mercator
- or
SRID: 4326 WGS 84
- typically
- can be specified as a WKID number (in a string format)
'outSR': '4326', # 4326 = WGS 84 lat/lon decimal degrees
'outSR': '32612', # 32612 = WGS 84 UTM zone 12
"outSR": "3395", # 3395 = WGS 84 compliant World Mercator, units: meters
- when
true
the number of features that match thewhere
clause is returned - no additional attributes or features are returned
- useful when you need to know the total number features you need to request
- divide this value by the
maxRecordCount
attribute of the feature service to determine the number of API requests required to obtain all of the features in a feature service
- specifies the number of records to return in the API request and the starting point
- use both to obtain records in batches when the Max Record Count property exceeds the total number of records that are needed from the feature service
- example scenario:
- the
maxRecordCount
attribute limits requests to 1000 records per API call - the
returnCountOnly
request indicates that there are 14,523 total records available in the feature service - to obtain all records, 15 individual API calls will be required
- 1st request:
'resultOffset': 0
and'resultRecordCount': 1000
- 2nd request:
'resultOffset': 1000
and'resultRecordCount': 1000
- 3rd request:
'resultOffset': 2000
and'resultRecordCount': 1000
... - 15th request:
'resultOffset': 14000
and'resultRecordCount': 1000
- allows for specifying the number of decimal places in coordinates in the feature geometry returned from feature service
- doesn't seem to work when tested on the ArcGIS Online geocoding service, but that service might not be returning a Geometry GeoJSON object
- specifies the format of the response
- valid options are:
html
,pjson
, andjson
- default response type is
html
- use
json
for spatial data- output can be imported directly into GIS software
pjson
is prettifiedjson
for debugging- more human-readable, but results in larger data sizes and longer processing times
- Spatial Filter: Envelope
'geometry': '-112,40.5,-111.0,41.5', #xmin, ymin, xmax, ymax 'geometryType': 'esriGeometryEnvelope', 'spatialRel': 'esriSpatialRelIntersects', 'distance': '', 'units': 'esriSRUnit_Meter', 'inSR': '4326',
- Spatial Filter: Point, (50,000 meter distance from)
'geometry': '426500,4500000', 'geometryType': 'esriGeometryPoint', 'spatialRel': 'esriSpatialRelIntersects', 'distance': '50000', 'units': 'esriSRUnit_Meter', 'inSR': '32612', # WGS 84 UTM zone 12
- Alternate geometry format for point
'geometry': '{"x" : 423500, "y" : 4500000}', 'geometry': "{'x' : 423500, 'y' : 4500000}",
- Spatial Filter: Polygon (State of Utah boundary, approximate)
'geometry': "{'rings': [[[-114.2,42.2],[-110.8,42.2],[-110.8,41.2],[-108.8,41.2],[-108.8,36.8],[-114.2,36.8],[-114.2,42.2]]]}", 'geometryType': 'esriGeometryPolygon ', 'spatialRel': 'esriSpatialRelIntersects', 'distance': '', 'units': 'esriSRUnit_Meter', 'inSR': '4326',
- see documentation: ArcGIS REST API Services Reference Query
- Sample Layer: National Inventory of Dams
- Dynamic Layers
- change the symbol representation of a Feature Layer
[{ "source": { "type": "mapLayer", "mapLayerId": 0 }, "definitionExpression": "HAZARD='H'", "drawingInfo": { "renderer": { "type": "simple", "symbol": { "color": [255,0,0,255], "size": 20, "type": "esriSMS", "style": "esriSMSCross" } } } }]