Geoserver的 rest、wfs、wms、wps接口请求指南

ops/2024/10/11 5:30:03/

前言

时光如白驹过隙,不知不觉间已经干了7年的GIS开发了,一路走来跌跌撞撞的,跟随着时代的洪流行尸走肉般的生存着(此处省略n个字,全是感慨)

一、官方API地址

geoserver官方的api地址还是比较全的,我整理了下放到了下面

  1. 文档地址:传送门
  2. rest接口地址:传送门
  3. wfs服务接口地址:传送门
  4. wms服务接口地址:传送门
  5. wps服务接口地址:传送门

二、请求示例

以wfs查询为例做一个查询的示例

/*** 图层wfs查询* @param {WfsQueryParams} obj 查询条件* @returns 图层wfs结果*/
export function wfsQuery(obj: WfsQueryParams) {const { layername, cql, fid, startIndex, maxFeatures } = objconst featureRequest: { [key: string]: string | number } = {service: "WFS",version: "1.0.0",request: "GetFeature",srsName: "EPSG:4326",typename: layername,outputFormat: "application/json"}if (fid) featureRequest.featureId = fidif (cql) featureRequest.CQL_FILTER = cqlif (startIndex != null && startIndex !== undefined) featureRequest.startIndex = startIndexif (maxFeatures != null && maxFeatures !== undefined) featureRequest.maxFeatures = maxFeaturesconst params = new URLSearchParams()for (const attr in featureRequest) {params.append(attr, featureRequest[attr] as any)}return http.independentGet<WfsQueryResult>(`${MAPSERVER}/ows?${params.toString()}`)
}

在上述代码中封装了一个wfs查询的方法,最下面的请求的http用的是axios

三、geoserver-helper示例

geoserver-helper是专门封装的用于请求geoserver的wfs,mws、wps以及rest接口的帮助类

使用方法如下

1、安装依赖

# 安装依赖
npm i geoserver-helper

2、引用依赖

// 整体引入依赖
import geoserverHelper from 'geoserver-helper'// 按需引入依赖
import utils from 'geoserver-helper/utils'
import wfsHelper from 'geoserver-helper/wfs'
import wpsHelper from 'geoserver-helper/wps'
import wmsHelper from 'geoserver-helper/wms'
import restHelper from 'geoserver-helper/rest'

3.使用

const restHelperInstance = new restHelper({url: "http://localhost:8080/geoserver"
})
const wpsHelper = new geoserverRest.wpsHelper("/geoserver/ows",);
const wfsHelperInstance = new wfsHelper({url: "/geoserver/wfs",workspace: "test",
});
const wmsHelperInstance = new wmsHelper({url: "/geoserver/wms",workspace: "test",
});//查询所有的图层列表
const res = await restHelperInstance.getLayerListApi()
console.log(res.layers)
//查询所有的工作空间列表
const res = await restHelperInstance.getWorkspaceListApi()
console.log(res.workspaces)
//查询所有的样式列表
restHelperInstance.getStylesListApi().then(res => {debuggerconsole.log(res)
})
//查询单个图层详情
restHelperInstance.getLayerInfoApi("test:xzqh_shi").then(res => {debuggerres.layerconsole.log(res)
})
//查询单个工作空间详情
restHelperInstance.getWorkspaceInfoApi("qhd").then(res => {debuggerconsole.log(res)
})const currentLayerModifyInfo: ILayer.LayerModifyInfo = {defaultStyle: {name: "test:xzqh_shi",// name: "polygon",},
}
//修改图层信息
restHelperInstance.modifyLayerApi("xzqh_shi",currentLayerModifyInfo,"test",
).then(res => {debugger
}).catch(e => {debugger
})
//用post请求要素
wfsHelperInstance.GetFeatureByPost({// "workspace": "test", // "workspaceUri": "http://test", "typename": "test:基本农田","startIndex": 0,"maxFeatures": 10,"cql": "type = '种植非粮食作' AND INTERSECTS (the_geom, MULTIPOLYGON(((119.149559 40.60191,119.1549 40.597565,119.176018 40.609817,119.220772 40.604893。。。))))"
}).then(res => {debuggerconsole.log(res)
})
//要素查询
wfsHelperInstance.GetFeature({propertyname: "name,gb",typename: "qhd:xzqh_xian",}).then(res => {debuggerconsole.log(res)
})
//获取图层字段描述信息
wfsHelperInstance.DescribeFeatureType({typeName: "topp:states",
}).then(res => {debuggerconsole.log(res)
})
//获取wfs能力集合
wfsHelperInstance.GetCapabilities({version: "1.0.0",
}).then(res => {debuggerconsole.log(res)
})
//获取单属性属性表
wfsHelperInstance.GetPropertyValue({typeNames: "topp:states",valueReference: "STATE_NAME"
}).then(res => {debuggerconsole.log(res)
})
//获取wms能量集合
wmsHelperInstance.GetCapabilities({version: "1.0.0"
}).then(res => {debuggerconsole.log(res)
})
//获取要素(多用于点选查询)
wmsHelperInstance.GetFeatureInfo({layers: "ellip_visual:1000510942192095232",version: "1.1.1",bbox: "118.85559,39.47113,119.17419,39.776",srs: "EPSG:4326"
}).then(res => {debuggerconsole.log(res)
})
//获取图例
wmsHelperInstance.GetLegendGraphic({layer: "ellip_visual:1000510942192095232",
}).then(res => {debuggerconsole.log(res)
})
//获取wps能力集
wpsHelper.GetCapabilities().then(res => {debuggerconsole.log(res)
})
//获取某个算子的详情信息
wpsHelper.DescribeProcess({identifier: "JTS:buffer"
}).then(res => {debuggerconsole.log(res)
})

http://www.ppmy.cn/ops/104754.html

相关文章

【C++】stack、queue、priority_queue的模拟实现

目录 一、stack &#x1f31f;stack的简单介绍 &#x1f31f;stack的基本使用 &#x1f31f;stack的模拟实现 &#x1f31f;stack模拟实现的完整代码 &#x1f31f;容器适配器 二、queue &#x1f31f;queue的简单介绍 &#x1f31f;queue的基本使用 &#x1f31f;q…

【微信小程序】全局数据共享 - MobX

1. 什么是全局数据共享 2. 小程序中的全局数据共享方案 3.Mobx的使用 1.npm init -y(根据实际情况选择) 在小程序项目中&#xff0c;可以通过 npm 的方式引入 MobX 。 如果你还没有在小程序中使用过 npm &#xff0c;那先在小程序目录中执行命令&#xff1a; npm init -y2. …

Your code has been rated at 6.24/10 (previous run: 5.83/10, +0.41)

收到代码评分为6.24/10&#xff0c;并且相比之前的评分5.83/10有所提升&#xff08;0.41&#xff09;&#xff0c;说明你的代码质量有所改善&#xff0c;但仍有一定的提升空间。为了进一步优化代码&#xff0c;特别是针对日志记录中使用懒惰格式化的问题&#xff0c;我们可以继…

Java面试自我介绍

持续更新中 模块序号目录链接前言介绍1前言地址2介绍地址基础知识3计算机网络地址4操作系统地址5Java基础地址6Java并发地址7Java虚拟机地址中间件8Mysql地址9Redis地址10Elasticsearch地址11RabbitMQ地址12RocketMQ地址框架13分布式系统地址14MyBatis地址15Dubbo地址16Spring地…

K8S ReplicaSet

在 Kubernetes&#xff08;通常拼写为 Kubernetes&#xff0c;而不是 kubernate&#xff09;中&#xff0c;ReplicaSet&#xff08;副本集&#xff09;是一种 Kubernetes 控制器&#xff0c;它确保由它管理的 Pod&#xff08;容器组&#xff09;的数量与预期的副本数量相匹配。…

Mac 去除自动生成.DS_Store文件的方法

最近在编译部署项目&#xff0c;Mac经常会产生.DS_Store的隐藏文件&#xff0c;虽然在Mac上看不到&#xff0c;但是有时用了人家的U盘或把U盘拿到Windows系统上用&#xff0c;就会看到&#xff0c;不但麻烦而且会泄露隐私&#xff0c;文件名都会历历在目。 .DS_Store是Mac OS保…

HaloE 移动云前端组件库的研究与分析

原文链接&#xff1a;HaloE 移动云前端组件库的研究与分析-科技语者 (chgskj.cn) 博主提示&#xff1a;该文章使用AI进行生成&#xff0c;并非博主创作&#xff01; 摘要&#xff1a;本论文旨在深入研究 HaloE 移动云前端组件库&#xff0c;探讨其设计价值观、功能特点、开发…

swift自定义数据集微调Qwen-7B大模型,转换模型后使用ollama跑起来

前文&#xff1a;swift微调Qwen-7B大模型-CSDN博客 我详细介绍了swift如何进行微调&#xff0c;但数据集均来自魔搭社区&#xff0c;如何想训练自定义数据集&#xff0c;实际上也很简单。 一、自定义数据集微调 export MKL_THREADING_LAYERGNU \ CUDA_VISIBLE_DEVICES0,1,2…