python wms_webGIS实践:4_2_python django整合geoserver wms服务

转发geoserver的WMS服务需要三个方法,一个是get瓦片参数,返回png图片;一个是get矢量要素参数,返回json;一个是post gml到后台。

一、get png

在geoserver.py中添加一个方法。

import requests

# 获取wmts服务

def wmts(request):

url='http://localhost:8080/geoserver/wms?SERVICE=WMS&VERSION=1.1.0&'+\

'REQUEST=GetMap&FORMAT=image%2Fpng&TRANSPARENT=true&tiled=true&'+\

'LAYERS='+request.GET['LAYERS']+'&exceptions=application%2Fvnd.ogc.se_inimage&singleTile=true&SRS=EPSG%3A4326&STYLES=&WIDTH='+\

request.GET['WIDTH']+'&HEIGHT='+request.GET['HEIGHT']+'&BBOX='+request.GET['BBOX']

print(url)

image_data=requests.get(url=url,stream=True)

return HttpResponse(image_data,content_type='image/png')

在urls.py中添加一个访问连接。

url(r'^getwmts$', geoserver.wmts

访问:

127.0.0.1:5000/getwmts?LAYERS=gismap%3Av6_time_pref_pgn_utf_wgs84_geoserver&WIDTH=1263&HEIGHT=134&BBOX=111.09189783417972%2C39.53658281977804%2C123.49882337000003%2C40.85291537860616

效果:

二、get feature

在geoserver.py中添加一个方法。

# 获取要素服务

def getfeature(request):

url='http://localhost:8080/geoserver/wms?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetFeatureInfo&FORMAT=image%2Fpng&'+\

'TRANSPARENT=true&QUERY_LAYERS='+request.GET['QUERY_LAYERS']+'&LAYERS='+request.GET['LAYERS']+\

'&exceptions=application%2Fvnd.ogc.se_inimage&INFO_FORMAT=application/json&FEATURE_COUNT=50&X=50&Y=50'+\

'&SRS=EPSG%3A4326&STYLES=&WIDTH=101&HEIGHT=101&BBOX='+request.GET['BBOX']

json_data=requests.get(url=url)

return HttpResponse(json_data,content_type='application/json')

在urls.py中添加一个访问连接。

url(r'^getfeature$', geoserver.getfeature),

访问:

127.0.0.1:5000/getfeature?QUERY_LAYERS=gismap%3Av6_time_pref_pgn_utf_wgs84_geoserver&LAYERS=gismap%3Av6_time_pref_pgn_utf_wgs84_geoserver&BBOX=116.25889429644533%2C40.173365121277484%2C116.25909429644534%2C40.17356512127749

效果:

三、post GML

在geoserver.py中新建一个方法:

# 提交 gml到geoserver

def postgml(request):

ctx ={}

if request.POST:

head = {"Content-Type": "text/xml; charset=UTF-8", "Connection": "close"}

r = requests.post('http://localhost:8080/geoserver/wfs', data=request.POST['gml'], headers=head)

ctx['rlt'] = r.text

return render(request, "postgml.html", ctx)

在urls.py中增加一个链接:

url(r'^postgml$', geoserver.postgml),

在templates文件夹下,新建一个postgml.html的文件:

django post页面

{% csrf_token %}

{{ rlt }}

访问:

在文本框中贴如如下内容:

geometry82.143976 37.149243 85.473018 37.109135 85.312581 34.822926 83.307136 34.2614 82.143976 37.149243name_pyname_pyname_chtestnewname_ftx_coory_coorpres_loctype_pytype_chlev_rankbeg_yrbeg_ruleend_yrend_rulenote_idobj_typesys_idgeo_srccompilergecomplrcheckerent_datebeg_chg_tyend_chg_ty

点击提交,效果如下:

Python django转发完geoserver wms服务后,我们接下来要看怎么把前端的内容放到程序中。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值