ArcPy Check cache levels

1017
4
Jump to solution
08-19-2016 07:00 AM
BillChappell
Occasional Contributor II

I need to find a way to determine what the cache levels are for our services. We use a 4 tier method for app development, dev, eval, production, public. Some apps use up to 20 different services, Like the 4 different app development process, we do the same with ArcServer services. Problem is our cache levels for a service in each level seem to be different, Different creator or created at different time periods. This we get different responses in each app.

What I need is to write a python script to query the service to determine what cache levels it's using, and to use this info to create a new service. Can Arcpy do this or is there a work around?

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JakeSkinner
Esri Esteemed Contributor

Hi Bill,

You could use something like below to return the tileInfo of the service:

import urllib, urllib2, json, smtplib

username = "agolUser"
password = "******"

tokenURL = 'https://www.arcgis.com/sharing/rest/generateToken'
params = {'f': 'pjson', 'username': username, 'password': password, 'referer': 'http://www.arcgis.com'}
req = urllib2.Request(tokenURL, urllib.urlencode(params))
response = urllib2.urlopen(req)
data = json.load(response)
token = data['token']

mapServiceURL = 'https://tiles.arcgis.com/tiles/dlQtlWFB4qUk/arcgis/rest/services/Philadelphia2014/MapServer'
params = {'f': 'json', 'token': token}
req = urllib2.Request(mapServiceURL, urllib.urlencode(params))
response = urllib2.urlopen(req)
data = json.load(response)

print data['tileInfo']['lods']

View solution in original post

4 Replies
JoshuaBixby
MVP Esteemed Contributor

My first thought is ArcREST.  I will take a closer look later and see about posting a code sample.

0 Kudos
JakeSkinner
Esri Esteemed Contributor

Hi Bill,

You could use something like below to return the tileInfo of the service:

import urllib, urllib2, json, smtplib

username = "agolUser"
password = "******"

tokenURL = 'https://www.arcgis.com/sharing/rest/generateToken'
params = {'f': 'pjson', 'username': username, 'password': password, 'referer': 'http://www.arcgis.com'}
req = urllib2.Request(tokenURL, urllib.urlencode(params))
response = urllib2.urlopen(req)
data = json.load(response)
token = data['token']

mapServiceURL = 'https://tiles.arcgis.com/tiles/dlQtlWFB4qUk/arcgis/rest/services/Philadelphia2014/MapServer'
params = {'f': 'json', 'token': token}
req = urllib2.Request(mapServiceURL, urllib.urlencode(params))
response = urllib2.urlopen(req)
data = json.load(response)

print data['tileInfo']['lods']
BillChappell
Occasional Contributor II

That worked.   Thanks, you saved me hours of manually clicking through each service to see where my problems lie.

0 Kudos
RebeccaStrauch__GISP
MVP Esteemed Contributor

I'm also finding Jake Skinner‌ 's script helpful and I'm incorporating into the workflow I'm working on right now.  To make it a little easier to read (and reuse), basically same info from line 14+ in script above.  I'm just starting to use and see the power in the urllb and urllib2 modules (still a novice)

def listScaleLevels(mapServiceURL, token):
     params = { 'f': 'json', 'token': token}
     req = urllib2.Request(mapServiceURL, urllib.urlencode(params))
     response = urllib2.urlopen(req)
     data = json.load(response)        
     # print data['tileInfo']['lods']
     # return(data)   # would return all the info about the services
     return(data['tileInfo']['lods'])   # would return the cache info

serviceTiles = listScaleLevels(mapServiceURL, token)
for cachescale in serviceTiles:
     print(("{0}".format(cachescale)))

Would return a format similar to:

{u'scale': 16000000, u'resolution': 4233.341800016934, u'level': 0}
{u'scale': 8000000, u'resolution': 2116.670900008467, u'level': 1}
{u'scale': 4000000, u'resolution': 1058.3354500042335, u'level': 2}
{u'scale': 2000000, u'resolution': 529.1677250021168, u'level': 3}
{u'scale': 1000000, u'resolution': 264.5838625010584, u'level': 4}
{u'scale': 500000, u'resolution': 132.2919312505292, u'level': 5}
{u'scale': 250000, u'resolution': 66.1459656252646, u'level': 6}
{u'scale': 125000, u'resolution': 33.0729828126323, u'level': 7}
{u'scale': 63360, u'resolution': 16.764033528067056, u'level': 8}
{u'scale': 24000, u'resolution': 6.350012700025401, u'level': 9}