kotlin中mainactivity无法直接调用xml中的控件_使用52North 客户端接口调用OGC WPS服务...

这篇博客介绍了如何使用52°North的WPS客户端连接到GeoServer并执行WPS服务,特别是调用缓冲区服务。作者展示了创建连接、获取过程描述、构建执行请求并解析响应的过程,最后展示了从响应中提取结果的代码示例。
摘要由CSDN通过智能技术生成

       52°North是一个来自研究机构、工业界和公共行政管理界的研究者组成的开放国际合作组织,他们通过协作研发流程促进地理信息学创新。具体来说他们开发新的地理信息概念和技术,例如用于管理时空测量数据,以及通过网络共享地理处理技术。他们评估新的GIS发展趋势,如物联网、语义 Web 或链接开放数据,并在实践中尝试研究和应用这些趋势。在 52°North 研发过程中开发的所有软件均以开源许可证发布。

        该组织之所以叫这个名字,是因为该组织的所在地——德国明斯特市位于北纬51°57 ' 38.394" ,东经7°37 ' 34.086" 的位置。        本节使用52°North的wps客户端来连接执行WPS服务。对于GeoTools的wps工具,试了几次都有问题,就不再浪费时间研究了。        下 面新建一个项目,当然直接在上一篇调用wfs的项目上新建一个类也是一样的。        下面接是该调用wps服务的类的代码,实现了调用geoserver的buffer服务,并返回缓冲区结果。
package edu.sdau.wpsstudy;import java.io.IOException;import javax.xml.transform.TransformerException;import org.apache.xpath.XPathAPI;import org.apache.xpath.objects.XObject;import org.n52.wps.client.ExecuteRequestBuilder;import org.n52.wps.client.WPSClientException;import org.n52.wps.client.WPSClientSession;import net.opengis.wps.x100.ExecuteDocument;import net.opengis.wps.x100.ExecuteResponseDocument;import net.opengis.wps.x100.ProcessDescriptionType;import net.opengis.wps.x100.ProcessDescriptionType.DataInputs;public class ReadWps {  public static void main(String[] args) throws IOException, WPSClientException, TransformerException {        String url = "http://localhost:8080/geoserver/ows";    String processID = "JTS:buffer";    //创建连接客户端    WPSClientSession wpsClient = WPSClientSession.getInstance();    boolean connected = wpsClient.connect(url);    if (!connected) {      System.out.println("无法连接到WPS.");      return;    }    //获取所有的process名称或ID    String[] pnames = wpsClient.getProcessNames(url);    for (int i = 0; i < pnames.length; i++) {      System.out.println(pnames[i]);    }    //创建某个process的描述信息    ProcessDescriptionType processDescription = wpsClient.getProcessDescription(url, processID);    //查看某个process的数据输入信息,可以通过dt访问许多关于输入数据的信息    DataInputs dt = processDescription.getDataInputs();    //查看完整的process的xml信息。    System.out.println("该process的描述:\n" + processDescription.xmlText() + "\n");    //创建请求    ExecuteRequestBuilder executeBuilder = new ExecuteRequestBuilder(processDescription);        //增加复杂数据数据,即创建几何输入    String paramGeo = "geom";    executeBuilder.addComplexData(paramGeo, "POINT(100 100)", null, null, "application/wkt");//      String schema = "http://schemas.opengis.net/gml/3.1.1/base/gml.xsd";//      String encoding  = "base64";    //创建缓冲区距离,literaData    String input = String.valueOf(20);    String parameterIn = "distance";    executeBuilder.addLiteralData(parameterIn, input);    //创建输出参数    String parameterOut = "result";    executeBuilder.setResponseDocument(parameterOut, null, null, null);    if (!executeBuilder.isExecuteValid())      System.out.println("创建执行请求失败!");    // 执行wps处理    ExecuteDocument executeRequest = executeBuilder.getExecute();    System.out.println("发送的执行请求是:\n" + executeRequest.xmlText() + "\n");    Object response = wpsClient.execute(url, executeRequest);    System.out.println("获取的响应结果是:\n" + response.toString() + "\n");    //输出结果    if (response instanceof ExecuteResponseDocument) {      ExecuteResponseDocument responseDoc = (ExecuteResponseDocument) response;      XObject data = XPathAPI.eval(responseDoc.getDomNode(), "//wps:ComplexData");      String output = data.toString();      System.out.println(output);    }  }}

下面是pom.xml的内容。

<project xmlns="http://maven.apache.org/POM/4.0.0"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">  <modelVersion>4.0.0modelVersion>  <groupId> edu.sdaugroupId>  <artifactId>wpsstudyartifactId>  <version>0.0.1-SNAPSHOTversion>  <packaging>jarpackaging>  <name>wpsstudyname>  <url>http://maven.apache.orgurl>  <properties>    <project.build.sourceEncoding>UTF-8project.build.sourceEncoding>  properties>  <dependencies>    <dependency>      <groupId>junitgroupId>      <artifactId>junitartifactId>      <version>4.11version>      <scope>testscope>    dependency>    <dependency>      <groupId>org.n52.wpsgroupId>      <artifactId>52n-wps-client-libartifactId>      <version>3.3.1version>    dependency>    <dependency>      <groupId>org.slf4jgroupId>      <artifactId>slf4j-simpleartifactId>      <version>1.7.30version>      <scope>compilescope>    dependency>      dependencies>  <repositories>    <repository>      <id>n52-releasesid>      <name>52n Releasesname>      <url>http://52north.org/maven/repo/releasesurl>      <releases>        <enabled>trueenabled>      releases>      <snapshots>        <enabled>trueenabled>      snapshots>    repository>  repositories>project>

点右键运行,可以看到输出结果。

3c2f303447706e11b00085987e694926.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值