GeoServer获取图层选点的数值
Posted xbw12138
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了GeoServer获取图层选点的数值相关的知识,希望对你有一定的参考价值。
需求
需要把遥感影像分析的结果展示在地图上,该遥感影像是通过算法反演的结果,进行了着色,需要通过经纬度获取相应的数值。Geoserver上发布的图层已经具有地图选点获取灰度值的功能,采用Openlayers实现,我们这里需要把该功能封装成api接口。下图是Geoserver的Openlayers展示界面。
代码
# -*- coding: utf-8 -*-
import warnings
from pyproj import Proj, transform
import requests
import json
from config import GeoServer
warnings.filterwarnings("ignore")
def to_bbox(lon, lat):
c = 50
x, y = transform(Proj(init='EPSG:4326'), Proj(init="EPSG:32650"), lon, lat)
return ",,,".format(x - c, y - c, x + c, y + c)
def get_value(lon, lat, workspace, belong, indicator, time):
print(lon, lat, workspace, belong, indicator, time)
try:
layers = ":__".format(workspace, belong, indicator, time)
bbox = to_bbox(lon, lat)
url = "/wms?" \\
"SERVICE=WMS" \\
"&VERSION=1.1.1" \\
"&REQUEST=GetFeatureInfo" \\
"&FORMAT=image/jpeg" \\
"&TRANSPARENT=true" \\
"&QUERY_LAYERS=" \\
"&LAYERS=" \\
"&exceptions=application/vnd.ogc.se_inimage" \\
"&INFO_FORMAT=application/json" \\
"&FEATURE_COUNT=50" \\
"&X=50" \\
"&Y=50" \\
"&SRS=EPSG:32650" \\
"&STYLES=" \\
"&WIDTH=101" \\
"&HEIGHT=101" \\
"&BBOX=".format(GeoServer, layers, layers, bbox)
print(url)
response = requests.get(url, timeout=5)
temp = json.loads(response.text)['features'][0]['properties']['GRAY_INDEX']
if temp < -2:
return 0
else:
return round(temp, 3)
except:
return 0
if __name__ == '__main__':
lon = 116.17356
lat = 34.7716
workspace = "inversion"
belong = "武汉"
indicator = "疫情"
time = "2020-02"
print(get_value(lon, lat, workspace, belong, indicator, time))
最终实现输入相应经纬度获取图层的对应的灰度值。
以上是关于GeoServer获取图层选点的数值的主要内容,如果未能解决你的问题,请参考以下文章
简析Geoserver中获取图层列表以及各图层描述信息的三种方法
在点击时从多个Geoserver图层获取要素属性 - 打开图层3