# Import python modules import arcpy # For Http calls import httplib, urllib, json #Globals refURL = 'ArcGIS' AGOL_org_User_Name = " " AGOL_passWord = " " def getToken(username, password, serverName, serverPort): # A function to generate a token given username, password and the adminURL. # Token URL is typically http://server[:port]/arcgis/admin/generateToken tokenURL = "/sharing/generateToken" params = urllib.urlencode({'username': username, 'password': password, 'client': 'referer','referer': refURL, 'expiration':'60','f': 'json'}) headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain",'referer': refURL} # Connect to URL and post parameters if serverPort == "": httpConn = httplib.HTTPSConnection(serverName) else: httpConn = httplib.HTTPConnection(serverName, serverPort) httpConn.request("POST", tokenURL, params, headers) # Read response response = httpConn.getresponse() if (response.status != 200): httpConn.close() FailType = 'Failed getting token; check connection and credentials' print "Error while fetching tokens from admin URL. Please check the URL and try again." return else: data = response.read() httpConn.close() # Check that data returned is not an error object if not assertJsonSuccess(data): return # Extract the token from it token = json.loads(data) return token['token'] def assertJsonSuccess(data): # A function that checks that the input JSON object # is not an error object. obj = json.loads(data) if 'status' in obj and obj['status'] == "error": print "Error: JSON object returns an error. " + str(obj) return False else: return True def main(): # ###### Access for Premium Demographic Content ###### # Get a Token demogServerName = "demographics1.arcgis.com" tokenServerName = "www.arcgis.com" serverPort = "" tokenString = (getToken(AGOL_org_User_Name,AGOL_passWord,tokenServerName,serverPort)).encode('ascii','ignore') # Get the Spatial Reference object from the demographic service from Esri demogServerName = "demographics1.arcgis.com" headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain",'referer': refURL} srSvcURL = "/arcgis/rest/services/USA_Demographics_and_Boundaries/MapServer" params2 = urllib.urlencode({'token': tokenString, 'f': 'JSON'}) httpConn = httplib.HTTPSConnection(demogServerName) httpConn.request("POST", srSvcURL, params2, headers) response = httpConn.getresponse() httpReturnCode = response.status if (httpReturnCode != 200): httpConn.close() print "Could not read service information. Code " + str(httpReturnCode) #403 = Forbidden, #498 = Bad Token FailType = "Could not get supply Spatial Reference" return else: data = response.read() httpConn.close() if not assertJsonSuccess(data): return dataObj2 = json.loads(data) srvJSONSR2 = dataObj2["spatialReference"] demandSR = arcpy.SpatialReference(int(srvJSONSR2.get('wkid'))) if __name__ == '__main__': main()
{u'capabilities': u'Data,Map,Query', u'copyrightText': u'Esri, US Census Bureau, Navteq', u'currentVersion': 10.2, u'description': u'This thematic map contains over 2000 demographic variables from Esri Updated Demographics for 2013, including projections for 2018, and the United States 2010 Census, ready to be symbolized in ten different levels of geography. Two views are available. The default view depicts States at greater than 15m scale, Counties at 1.5m to 15m scale, Zip Codes at 500k to 1.5m scale, Census Tracts at 150k to 500k scale, and Census Block Groups at less than 150k scale. The second view allows the ten separate geography levels to be turned on or off individually, each including the full set of variables. The ten levels of geography represented are State, County, Tract, Block Group, Zip Code, Place, County Subdivision, Congressional District, CBSA and DMA.\n\nFor more information on this map, including our terms of use, visit us online at http://goto.arcgisonline.com/demographics/USA_Demographics_and_Boundaries', u'documentInfo': {u'AntialiasingMode': u'Fastest', u'Author': u'Esri', u'Category': u'', u'Comments': u'This thematic map contains over 2000 demographic variables from Esri Updated Demographics for 2013, including projections for 2018, and the United States 2010 Census, ready to be symbolized in ten different levels of geography. Two views are available. The default view depicts States at greater than 15m scale, Counties at 1.5m to 15m scale, Zip Codes at 500k to 1.5m scale, Census Tracts at 150k to 500k scale, and Census Block Groups at less than 150k scale. The second view allows the ten separate geography levels to be turned on or off individually, each including the full set of variables. The ten levels of geography represented are State, County, Tract, Block Group, Zip Code, Place, County Subdivision, Congressional District, CBSA and DMA.\n\nFor more information on this map, including our terms of use, visit us online at http://goto.arcgisonline.com/demographics/USA_Demographics_and_Boundaries', u'Keywords': u'polygon, demographics, census, state, county, tract, block group, Zip Code, postal, CBSA, DMA, place, county subdivision, congressional district, population, income, household, age, race, male, female', u'Subject': u'USA Demographics and Boundaries includes over 2000 demographic variables from the 2010 Census ready to symbolize in ten different geographies.', u'TextAntialiasingMode': u'Force', u'Title': u'USA Demographics and Boundaries'}, u'exportTilesAllowed': False, u'fullExtent': {u'spatialReference': {u'latestWkid': 3857, u'wkid': 102100}, u'xmax': -7452828.103399999, u'xmin': -19942589.5526, u'ymax': 11537127.463399999, u'ymin': 2144435.340399999}, u'initialExtent': {u'spatialReference': {u'latestWkid': 3857, u'wkid': 102100}, u'xmax': -6427885.287170573, u'xmin': -20967532.368829425, u'ymax': 12006762.069549998, u'ymin': 8371850.2991352845}, u'layers': [{u'defaultVisibility': True, u'id': 0, u'maxScale': 0, u'minScale': 0, u'name': u'Demographics and Boundaries', u'parentLayerId': -1, u'subLayerIds': [1, 9, 10, 11, 12, 16]}, {u'defaultVisibility': True, u'id': 1, u'maxScale': 0, u'minScale': 0, u'name': u'State and County Boundaries', u'parentLayerId': 0, u'subLayerIds': [2, 3]}, {u'defaultVisibility': True, u'id': 2, u'maxScale': 0, u'minScale': 1500000, u'name': u'County Boundaries', u'parentLayerId': 1, u'subLayerIds': None}, {u'defaultVisibility': True, ## Shortened layers element to fit in post u'mapName': u'Layers', u'maxImageHeight': 4096, u'maxImageWidth': 4096, u'maxRecordCount': 3500, u'maxScale': 0, u'minScale': 0, u'serviceDescription': u'', u'singleFusedMapCache': False, u'spatialReference': {u'latestWkid': 3857, u'wkid': 102100}, u'supportedExtensions': u'KmlServer', u'supportedImageFormatTypes': u'PNG32,PNG24,PNG,JPG,DIB,TIFF,EMF,PS,PDF,GIF,SVG,SVGZ,BMP', u'supportedQueryFormats': u'JSON, AMF', u'supportsDynamicLayers': True, u'tables': [], u'units': u'esriMeters'}
サインインしたメンバーは投稿、更新のフォローなどができます。初めてですか?無料アカウントを登録してください。
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.