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

前言

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

一、官方API地址

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

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

二、请求示例

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

TypeScript 复制代码
/**
 * 图层wfs查询
 * @param {WfsQueryParams} obj 查询条件
 * @returns 图层wfs结果
 */
export function wfsQuery(obj: WfsQueryParams) {
  const { layername, cql, fid, startIndex, maxFeatures } = obj
  const 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 = fid
  if (cql) featureRequest.CQL_FILTER = cql
  if (startIndex != null && startIndex !== undefined) featureRequest.startIndex = startIndex
  if (maxFeatures != null && maxFeatures !== undefined) featureRequest.maxFeatures = maxFeatures
  const 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、安装依赖

TypeScript 复制代码
# 安装依赖
npm i geoserver-helper

2、引用依赖

TypeScript 复制代码
// 整体引入依赖
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.使用

TypeScript 复制代码
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 => {
  debugger
  console.log(res)
})
//查询单个图层详情
restHelperInstance.getLayerInfoApi("test:xzqh_shi").then(res => {
  debugger
  res.layer
  console.log(res)
})
//查询单个工作空间详情
restHelperInstance.getWorkspaceInfoApi("qhd").then(res => {
  debugger
  console.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 => {
  debugger
  console.log(res)
})
//要素查询
wfsHelperInstance.GetFeature({
  propertyname: "name,gb",
  typename: "qhd:xzqh_xian",

}).then(res => {
  debugger
  console.log(res)
})
//获取图层字段描述信息
wfsHelperInstance.DescribeFeatureType({
  typeName: "topp:states",
}).then(res => {
  debugger
  console.log(res)
})
//获取wfs能力集合
wfsHelperInstance.GetCapabilities({
  version: "1.0.0",
}).then(res => {
  debugger
  console.log(res)
})
//获取单属性属性表
wfsHelperInstance.GetPropertyValue({
  typeNames: "topp:states",
  valueReference: "STATE_NAME"
}).then(res => {
  debugger
  console.log(res)
})
//获取wms能量集合
wmsHelperInstance.GetCapabilities({
  version: "1.0.0"
}).then(res => {
  debugger
  console.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 => {
  debugger
  console.log(res)
})
//获取图例
wmsHelperInstance.GetLegendGraphic({
  layer: "ellip_visual:1000510942192095232",
}).then(res => {
  debugger
  console.log(res)
})
//获取wps能力集
wpsHelper.GetCapabilities().then(res => {
  debugger
  console.log(res)
})
//获取某个算子的详情信息
wpsHelper.DescribeProcess({
  identifier: "JTS:buffer"
}).then(res => {
  debugger
  console.log(res)
})
相关推荐
孤水寒月1 小时前
给自己网站增加一个免费的AI助手,纯HTML
前端·人工智能·html
CoderLiu1 小时前
用这个MCP,只给大模型一个figma链接就能直接导出图片,还能自动压缩上传?
前端·llm·mcp
伍哥的传说1 小时前
鸿蒙系统(HarmonyOS)应用开发之实现电子签名效果
开发语言·前端·华为·harmonyos·鸿蒙·鸿蒙系统
海的诗篇_2 小时前
前端开发面试题总结-原生小程序部分
前端·javascript·面试·小程序·vue·html
uncleTom6662 小时前
前端地图可视化的新宠儿:Cesium 地图封装实践
前端
lemonzoey2 小时前
无缝集成 gemini-cli 的 vscode 插件:shenma
前端·人工智能
老家的回忆2 小时前
jsPDF和html2canvas生成pdf,组件用的elementplus,亲测30多页,20s实现
前端·vue.js·pdf·html2canvas·jspdf
半点寒12W2 小时前
uniapp全局状态管理实现方案
前端
Vertira2 小时前
pdf 合并 python实现(已解决)
前端·python·pdf
PeterJXL3 小时前
Chrome 下载文件时总是提示“已阻止不安全的下载”的解决方案
前端·chrome·安全