1.利用Python 当使用动态数据,Python语言非常适用于REST查询层,并找到所需的信息。下面的例子将查询所有信息层,并在控制台屏幕显示其所有属性:启动它,创建一个test.py文件包括下面的代码,然后从控制台窗口调用“python test.py”。
|
import simplejson, urllib, sys, string baseUrl = "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/3 /query?text=all&geometry=&geometryType=esriGeometryEnvelope&inSR=&spatialRel=esriSpatialRelIntersects &where=&returnGeometry=true&outSR=&outFields=&f=json" def loadJSON(url): request = simplejson.load(urllib.urlopen(url)) return request results = loadJSON(baseUrl)['results'] for result in results: print result['id'], result['name'] for attribute in result['attributes']: print attribute, result['attributes'][attribute] print result['geometry']['x'], result['geometry']['y'] print |
你还可以使用以下代码在HTML中找回信息来获得图像:
|
import urllib, sys, string baseUrl = "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/ MapServer/export?bbox=-185.337909357176%2C15.2049923316373%2C-59.5254874993028%2C74.082485035617 6&bboxSR=&layers=&layerdefs=&size=&imageSR=&format=png&transparent=false&dpi=&f=html" request = urllib.urlopen(baseUrl).read() print request |
接下来,从ArcGIS Online下载扩展到HTML页面,包括影像和扩展属性。你就可以剪切和粘贴以下代码,执行代码将返回下列HTML文件:
|
import urllib, sys, string baseUrl = "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/ export?bbox=-185.337909357176%2C15.2049923316373%2C-59.5254874993028%2C74.0824850356176&bboxSR= &layers=&layerdefs=&size=&imageSR=&format=png&transparent=false&dpi=&f=html" request = urllib.urlopen(baseUrl).read() print request |
返回如下HTML文件:
|
<html> <head> <title>Export Map Image: Layers</title> <link href='/ArcGIS/rest/ESRI.ArcGIS.Rest.css' rel='stylesheet' type='text/css'> </head> <body> <table width="100%" id="userTable"> <tr> <td id="titlecell">ArcGIS Services Directory</td> </tr> </table> <table id="navTable" width="100%"> <tbody> <tr valign="top"> <td id="breadcrumbs"> <a href="/ArcGIS/rest/services">Home</a> > <ahref="/ArcGIS/rest/services/Demographics">Demographics</a> > <ahref="/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer">ESRI_Census_USA (MapServer)</ |

首页
资讯
博客
论坛
视频
专题
搜索