日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

geoserver的api接口_geoserver REST使用

發布時間:2024/2/28 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 geoserver的api接口_geoserver REST使用 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1.部署一個簡單的測試環境

測試geoserver REST接口,我們可使用python來測試,很方便。需要下載包:

python,http://python.org/。我下載的是Python27版本。

cURL,幾個簡單的命令行工具,很容易使用命令交互, 地址為http://curl.haxx.se/download.html,下載curl-7.53.1-win64-mingw版本。

三個包現在后,配置python的環境變量。打開Requests下載后的目錄。在該目錄下執行以下命令:

python setup.py install~$ python>>> import requests

2.使用curl獲取工作區列表

解壓curl下載包,進入目錄“curl-7.53.1-win64-mingw\bin”,執行cmd命令。輸入以下命令:

curl -u admin:geoserver -v -XGET -H 'Accept: text/xml' http://localhost:8082/geoserver/rest/workspaces -o E:\workspaces.xml

參數說明: -u表示驗證的用戶名和密碼,-v表示輸入版本, -X表示請求的方式,-H表示輸入的請求頭信息,-o打印輸出文件。但實際不知道-o文件輸出到哪里去了,沒找到。 輸出結果如下:

3.使用python獲取工作區

打開用于輸出的一個目錄,在該目錄下執行cmd指令。分別一步一步執行以下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()

打開workspaces_py.xml文件查看輸出結果。額curl輸出結果一樣。

4.查看工作區下的數據存儲

指令和3相似,myUrl有點區別:myUrl = 'http://localhost:8082/geoserver/rest/workspaces/tiger'。查詢結果:

tiger

5.查詢命名空間

6.創建命名空間

使用curl創建,指令如下:

curl -u admin:geoserver -XPOST -H 'Content-type: text/xml' -d 'newWorkspacehttp://geoserver.org' http://localhost:8082/geoserver/rest/namespaces

使用python創建,指令如下:

>>> 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內容:

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內容:

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.獲取數據存儲列表

使用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內容如下:

50m-rivers-lake-centerlines

ne_10m_railroads

10.獲取某個存儲的具體數據

使用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()

輸出結果如下:

/p>

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

GeoServer Configuration
  • ne_50m_populated_places

總結

以上是生活随笔為你收集整理的geoserver的api接口_geoserver REST使用的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。