Openlayers4 中 Geoserver WPS 的显示栅格结果
Posted
技术标签:
【中文标题】Openlayers4 中 Geoserver WPS 的显示栅格结果【英文标题】:Displayer raster result from Geoserver WPS in Openlayers4 【发布时间】:2018-05-17 09:15:08 【问题描述】:对于交互式网络应用程序,我使用 Openlayers 4.6.5 和 Geoserver 2.13.0。
希望通过使用 Geoserver WPS 启用用户选择的输入数据点的动态处理。我使用 SourceForge 的统计数据包扩展了 WPS 功能,并希望对选定点的集合运行 KernelDensity 分析。 KernelDensity 处理的结果将在我的地图中显示为栅格图层。
我正在使用 javascript 的 fetch 功能向 WPS 发送 XML 请求。:
<wps:Execute version="1.0.0" service="WPS" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:wfs="http://www.opengis.net/wfs" xmlns:wps="http://www.opengis.net/wps/1.0.0" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xlink="http://www.w3.org/1999/xlink" xsi:schemaLocation="http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsAll.xsd"><ows:Identifier>statistics:KernelDensity</ows:Identifier><wps:DataInputs><wps:Input><ows:Identifier>inputFeatures</ows:Identifier><wps:Data><wps:ComplexData mimeType="application/json"><![CDATA["type":"FeatureCollection","totalFeatures":2,"features":["type":"Feature","id":"alllocations.fid-57f369ef_1636c6c3947_-5ddb","geometry":"type":"Point","coordinates":[100.330936,5.41626549],"geometry_name":"geom","properties":"idstorylocation":344,"idstory":27,"story":"HOUN","idlocation":203,"location_role":"reference","actions":"The walking stick left behind by young Dr Mortimer is of the sort which is called \"Penang Lawyer\".","name":"Penang ","country_today":"Malaysia","reference_to":"city","reality":"real","certainty":"good","accuracy":"high","county":"","state_country":"","city":"Penang","idcountry":298,"idpoints":99,"idperson":40,"initial":null,"lastname":"Mortimer","firstname":"James","nationality":null,"type":"Feature","id":"alllocations.fid-57f369ef_1636c6c3947_-5dda","geometry":"type":"Point","coordinates":[100.330936,5.41626549],"geometry_name":"geom","properties":"idstorylocation":1519,"idstory":15,"story":"SILV","idlocation":203,"location_role":"reference","actions":"The stick of Fitzroy Simpson, which was a Penang-lawyer weighted with lead, was was just such a weapon as might, by repeated blows, have inflicted the terrible injuries to which the trainer had succumbed. ","name":"Penang ","country_today":"Malaysia","reference_to":"city","reality":"real","certainty":"good","accuracy":"high","county":"","state_country":"","city":"Penang","idcountry":298,"idpoints":99,"idperson":0,"initial":null,"lastname":null,"firstname":null,"nationality":null],"crs":"type":"name","properties":"name":"urn:ogc:def:crs:EPSG::4326"]]></wps:ComplexData></wps:Data></wps:Input><wps:Input><ows:Identifier>kernelType</ows:Identifier><wps:Data><LiteralData>Quadratic</LiteralData></wps:Data></wps:Input><wps:Input><ows:Identifier>populationField</ows:Identifier><wps:Data><wps:LiteralData>icount</wps:LiteralData></wps:Data></wps:Input><wps:Input><ows:Identifier>searchRadius</ows:Identifier><wps:Data><wps:LiteralData>5</wps:LiteralData></wps:Data></wps:Input><wps:Input><ows:Identifier>cellSize</ows:Identifier><wps:Data><wps:LiteralData>20</wps:LiteralData></wps:Data></wps:Input><wps:Input><ows:Identifier>extent</ows:Identifier><wps:Data><wps:BoundingBoxData crs="EPSG:4326" dimension="2"><ows:LowerCorner>-180.0 -90.0</ows:LowerCorner><ows:UpperCorner>180.0 90.0</ows:UpperCorner></wps:BoundingBoxData></wps:Data></wps:Input></wps:DataInputs><wps:ResponseForm><wps:RawDataOutput mimeType="image/tiff"><ows:Identifier>result</ows:Identifier></wps:RawDataOutput></wps:ResponseForm></wps:Execute>
输入jsonstring是从选定点数据中收集的事件,输出应该是image/tiff。
但是,我不知道如何从响应中获取 a) 栅格和 b) 栅格作为图层到我的地图中。
function calculateKernelDensity(jsonstring)
xml = createKernelDensityRequest(jsonstring);
fetch('http://localhost:8080/geoserver/Sherlock/wps',
method: 'POST',
body: xml
)
// tried my luck with blob to use it later on as image layer
.then(function(response)
var blob = response.blob();
return blob;
)
.then(function(blob)
console.log(blob.size + " " + blob.type);
);
// something here to put it as layer into the map...
;
我对基于矢量的请求(collectEvents、convexHull)做了非常相似的事情,并将 response.json 作为矢量特征添加到地图中,效果很好:
function collectEvents(jsonstring)
xml = createCollectEventsRequest(jsonstring);
fetch('http://localhost:8080/geoserver/Sherlock/wps',
method: 'POST',
body: xml
)
.then(function(response)
jsonresults = response.json();
return jsonresults;
)
.then(function(jsonresults)
jsonstring = JSON.stringify(jsonresults);
results = new ol.format.GeoJSON(geometryName:'geom').readFeatures(jsonresults,
dataProjection: 'EPSG:4326',
featureProjection: 'EPSG:3857'
);
vectorSource.clear(results);
vectorSource.addFeatures(results);
);
;
我找不到任何关于 OpenLayers 4 以及如何将其与 Geoserver WPS 一起使用的好的文档。关于使用光栅和图像源的 API 文档也没有任何帮助。我确实知道 ol.source.ImageWMS,但是当我尝试动态生成和显示栅格而不是从 WMS 检索栅格时,这里没有选择。
有没有办法从 WPS 中获取生成的光栅图像并将其显示在 OpenLayers 地图中?
【问题讨论】:
【参考方案1】:从this question 的回答来看,无法在 OpenLayers 中直接显示 GeoTiff,因为它使用浏览器的原生显示功能进行显示。
可能对您有用的一个选项是将 WPS 输出保存到 GeoServer,然后使用 WMS 请求获取结果。 GeoSolution's WPS training 中有一个如何执行此操作的示例。此answer 还为此目的提到了StoreCoverage
进程,但我找不到任何其他参考。
【讨论】:
以上是关于Openlayers4 中 Geoserver WPS 的显示栅格结果的主要内容,如果未能解决你的问题,请参考以下文章
openlayers4 入门开发系列之前端动态渲染克里金插值 kriging 篇(附源码下载)
openlayers6结合geoserver实现地图空间查询(附源码下载)