进程
GeoTools流程系统是打包有用功能以便在应用程序中使用(或通过“web处理服务”(如GeoServer或52N)发布)的好方法。
当与流程引擎一起使用时,这些单独的流程可以链接在一起,形成有趣和有用的脚本。
这个过程数据结构比我们添加到GeoTools过滤器系统的功能更强大,能够根据需要处理大量数据。其基本思想与此类似,您可以编写一些简单的java代码并将其打包以供GeoTools库使用。
我们有很多选择:
- Annotations
- DataStructure
参考:
过程详解
这是创建流程的最快方法;这很好(只要您的过程产生一个结果)。
- 添加一个依赖gt-process到您的项目:
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-process</artifactId>
<version>${geotools.version}</version>
</dependency>
- 首先,我们需要创建一个扩展StaticMethodsProcessFactory的类:
/*
* GeoTools - The Open Source Java GIS Toolkit
* http://geotools.org
*
* (C) 2019, Open Source Geospatial Foundation (OSGeo)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
*/
package org.geotools.tutorial.process;
import org.geotools.process.factory.DescribeParameter;
import org.geotools.process.factory.DescribeProcess;
import org.geotools.process.factory.DescribeResult;
import org.geotools.process.factory.StaticMethodsProcessFactory;
import org.geotools.text.Text;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.OctagonalEnvelope;
public class ProcessTutorial extends StaticMethodsProcessFactory<ProcessTutorial> {
- 我们需要做一点工作来填充构造函数
public ProcessTutorial() {
super(Text.text("Tutorial"), "tutorial", ProcessTutorial.class);
}
- 我们现在可以实现我们的功能:
static public Geometry octagonalEnvelope( Geometry geom) {
return new OctagonalEnvelope(geom).toGeometry(geom.getFactory());
}
- 然后我们可以填写注释来描述我们的过程、结果和参数。
- @DescribeProcess
- @DescribeParameter
- @DescribeResult
@DescribeProcess(
title = "Octagonal Envelope",
description = "Get the octagonal envelope of this Geometry."
)
@DescribeResult(description = "octagonal of geom")
public static Geometry octagonalEnvelope(@DescribeParameter(name = "geom") Geometry geom) {
return new OctagonalEnvelope(geom).toGeometry(geom.getFactory());
}
- 然后将其连接到工厂SPI(正如在函数教程中所做的那样)。
创建文件:
- META-INF/services/org.geotools.process.ProcessFactory
- 填写以下内容(每行一个实现类):
org.geotools.tutorial.process.ProcessTutorial
- 就是这样,八角形信封现在出版了。
扩展尝试
- 尝试使用Processors实用程序类调用您的进程
WKTReader wktReader = new WKTReader(new GeometryFactory());
Geometry geom = wktReader.read("MULTIPOINT (1 1, 5 4, 7 9, 5 5, 2 2)");
Name name = new NameImpl("tutorial", "octagonalEnvelope");
Process process = Processors.createProcess(name);
ProcessExecutor engine = Processors.newProcessExecutor(2);
// quick map of inputs
Map<String, Object> input = new KVP("geom", geom);
Progress working = engine.submit(process, input);
// you could do other stuff whle working is doing its thing
if (working.isCancelled()) {
return;
}
Map<String, Object> result = working.get(); // get is BLOCKING
Geometry octo = (Geometry) result.get("result");
System.out.println(octo);
它是这样的:

- 处理程序类还可以列出Map<String,参数>,允许您显示数据输入向导(就像连接到数据存储时一样)。
Name name = new NameImpl("tutorial", "octagonalEnvelope");
Map<String, Parameter<?>> paramInfo = Processors.getParameterInfo(name);
网友评论