WPS挂钩¶
在GeoScript JS中 geoscript/process 模块提供 Process 构造器。流程对象用标题、描述和有关输入和输出的附加元数据包装函数。使用GeoServer脚本扩展,当脚本导出进程时,它将通过WPS接口在GeoServer中公开。
为了更好地理解如何构建一个描述良好的流程,我们将检查前面提供的 buffer.js 脚本:
var Process = require("geoscript/process").Process;
exports.process = new Process({
title: "JavaScript Buffer Process",
description: "Process that buffers a geometry.",
inputs: {
geom: {
type: "Geometry",
title: "Input Geometry",
description: "The target geometry."
},
distance: {
type: "Double",
title: "Buffer Distance",
description: "The distance by which to buffer the geometry."
}
},
outputs: {
result: {
type: "Geometry",
title: "Result",
description: "The buffered geometry."
}
},
run: function(inputs) {
return {result: inputs.geom.buffer(inputs.distance)};
}
});
当此脚本保存在 $GEOSERVER_DATA_DIR/scripts/wps 目录,它将对具有标识符的WPS客户机可用 js:buffer . 通常,进程标识符是以语言扩展名为前缀的脚本的名称。
首先, require 函数用于拉入 Process 来自的构造函数 geoscript/process 模块:
var Process = require("geoscript/process").Process;
接下来,构造一个流程并将其分配给 process 性质 exports 反对。这使得其他JavaScript模块可以使用 require 除了向GeoServer的WPS公开进程之外,还可以使用函数。标题和描述为WPS客户机提供了有关进程的可读信息。
exports.process = new Process({
title: "JavaScript Buffer Process",
description: "Process that buffers a geometry.",
流程的所有工作都由 run 方法。在客户机可以执行一个流程之前,他们需要知道一些关于作为输入提供什么和作为输出期望什么的细节。一般来说,进程接受多个输入,并可能返回多个输出。这些由过程描述' inputs 和 outputs 性质。
inputs: {
geom: {
type: "Geometry",
title: "Input Geometry",
description: "The target geometry."
},
distance: {
type: "Double",
title: "Buffer Distance",
description: "The distance by which to buffer the geometry."
}
},
缓冲区进程需要两个输入,名为 geom 和 distance . 与进程本身一样,每个输入都有一个可读的标题和描述,将提供给WPS客户机。这个 type 属性是标识输入数据类型的速记字符串。见 Process API docs 有关支持的输入和输出类型的详细信息。
outputs: {
result: {
type: "Geometry",
title: "Result",
description: "The buffered geometry."
}
},
缓冲进程提供一个标识为 result . 与每个输入一样,此输出用 type , title 和 description 性质。
要查看此流程元数据对于WPS客户端的外观,请调用WPS DescribeProcess 方法:
http://localhost:8080/geoserver/wps
?service=WPS
&version=1.0.0
&request=DescribeProcess
&identifier=js:buffer
最后, run 提供了方法。
run: function(inputs) {
return {result: inputs.geom.buffer(inputs.distance)};
}
});
这个 run method takes a single inputs argument. This object will have named properties corresponding the the client provided inputs. In this case, the geom property is a Geometry object from the geoscript/geom module. This geometry has a buffer method that is called with the provided distance. See the Geometry API docs 有关可用几何图形特性和方法的详细信息。
这个 run 方法返回一个具有与上述输出对应的属性的对象-在本例中,仅返回一个 result 财产。
要查看此进程的实际结果,请调用WPS Execute 方法:
http://localhost:8080/geoserver/wps
?service=WPS
&version=1.0.0
&request=Execute
&identifier=js:buffer
&datainputs=geom=POINT(0 0)@mimetype=application/wkt;distance=10