geoserver的api接口_geoserver REST使用
1.部署一個(gè)簡(jiǎn)單的測(cè)試環(huán)境
測(cè)試geoserver REST接口,我們可使用python來(lái)測(cè)試,很方便。需要下載包:
python,http://python.org/。我下載的是Python27版本。
cURL,幾個(gè)簡(jiǎn)單的命令行工具,很容易使用命令交互, 地址為http://curl.haxx.se/download.html,下載curl-7.53.1-win64-mingw版本。
三個(gè)包現(xiàn)在后,配置python的環(huán)境變量。打開(kāi)Requests下載后的目錄。在該目錄下執(zhí)行以下命令:
python setup.py install~$ python>>> import requests
2.使用curl獲取工作區(qū)列表
解壓curl下載包,進(jìn)入目錄“curl-7.53.1-win64-mingw\bin”,執(zhí)行cmd命令。輸入以下命令:
curl -u admin:geoserver -v -XGET -H 'Accept: text/xml' http://localhost:8082/geoserver/rest/workspaces -o E:\workspaces.xml
參數(shù)說(shuō)明: -u表示驗(yàn)證的用戶名和密碼,-v表示輸入版本, -X表示請(qǐng)求的方式,-H表示輸入的請(qǐng)求頭信息,-o打印輸出文件。但實(shí)際不知道-o文件輸出到哪里去了,沒(méi)找到。 輸出結(jié)果如下:
3.使用python獲取工作區(qū)
打開(kāi)用于輸出的一個(gè)目錄,在該目錄下執(zhí)行cmd指令。分別一步一步執(zhí)行以下python指令:
python
import requests
myUrl= 'http://localhost:8082/geoserver/rest/workspaces'headers= {'Accept': 'text/xml'}
resp= requests.get(myUrl,auth=('admin','geoserver'),headers=headers)
resp.status_code
file= open('workspaces_py.xml','w')
file.write(resp.text)
file.close()
打開(kāi)workspaces_py.xml文件查看輸出結(jié)果。額curl輸出結(jié)果一樣。
4.查看工作區(qū)下的數(shù)據(jù)存儲(chǔ)
指令和3相似,myUrl有點(diǎn)區(qū)別:myUrl = 'http://localhost:8082/geoserver/rest/workspaces/tiger'。查詢結(jié)果:
tiger
5.查詢命名空間
6.創(chuàng)建命名空間
使用curl創(chuàng)建,指令如下:
curl -u admin:geoserver -XPOST -H 'Content-type: text/xml' -d 'newWorkspacehttp://geoserver.org' http://localhost:8082/geoserver/rest/namespaces
使用python創(chuàng)建,指令如下:
>>> myUrl = 'http://localhost:8082/geoserver/rest/namespaces'
>>> file = open('requestBody.xml','r')>>> payload =file.read()>>> headers = {'Content-type': 'text/xml'}>>> resp = requests.post(myUrl, auth=('admin','geoserver'),data=payload, headers=headers)>>> resp.status_code
requestBody.xml內(nèi)容:
newWorkspacehttp://geoserver.org
7.修改命名空間
使用python指令如下:
>>> myUrl = 'http://localhost:8082/geoserver/rest/namespaces/newWorkspace'
>>> file = open('requestBody.xml','r')>>> payload =file.read()>>> headers = {'Content-type': 'text/xml'}>>> resp = requests.put(myUrl,auth=('admin','geoserver'),data=payload, headers=headers)
requestBody.xml內(nèi)容:
newWorkspacehttp://localhost:8082/geoserver
8.刪除命名空間
使用python指令如下:
>>> myUrl = 'http://localhost:8082/geoserver/rest/workspaces/newWorkspace'
>>> headers = {'Accept': 'text/xml'}>>> resp = requests.delete(myUrl, auth=('admin','geoserver'),headers=headers)>>> resp.status_code
9.獲取數(shù)據(jù)存儲(chǔ)列表
使用python指令如下:
>>> myUrl = 'http://localhost:8082/geoserver/rest/workspaces/tiger/datastores'
>>> headers = {'Accept': 'text/xml'}>>> resp = requests.get(myUrl,auth=('admin','geoserver'),headers=headers)>>> file = open('tiger_datastores.xml','w')>>>file.write(resp.text)>>> file.close()
輸出的tiger_datastores.xml內(nèi)容如下:
50m-rivers-lake-centerlines
ne_10m_railroads
10.獲取某個(gè)存儲(chǔ)的具體數(shù)據(jù)
使用python指令如下:
>>> myUrl = 'http://localhost:8082/geoserver/rest/workspaces/tiger/datastores/ne_50m_populated_places'
>>> headers = {'Accept': 'text/html'}>>> resp = requests.get(myUrl,auth=('admin','geoserver'),headers=headers)>>> file = open('tiger_ne_50m_populated_places_datastores.xml','w')>>>file.write(resp.text)>>> file.close()
輸出結(jié)果如下:
/p>
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
GeoServer Configuration- ne_50m_populated_places
總結(jié)
以上是生活随笔為你收集整理的geoserver的api接口_geoserver REST使用的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 老电脑内存容量查找大揭秘!三招教你轻松搞
- 下一篇: ios 获取沙盒文件名_获取IOS各种沙