geoserver wfs 服务访问

WFS 服务是OGC服务之一,可以通过 WFS 获取要素信息,ArcGIS Server 跟 GeoServer 都支持。下面且看如何请求WFS。


const crossIds = ['8316','8318'];
const ACC_ROAD_WFS_NAME = 'test:road';
const wfsUrl = `${GEOSERVER_URL}/wfs?service=wfs&version=1.0.0&request=getfeature&typename=${ACC_ROAD_WFS_NAME}&PROPERTYNAME=name,fid,geom&CQL_FILTER=fid in (${crossIds.join(',')})&outputformat=application/json`;

fetch(wfsUrl,{
  method: 'GET',
  headers: {
  'Content-Type': 'application/x-www-form-urlencoded',
  },
}).then(response => response.text())
.then((text) => {
  if (typeof text === 'string' && text !== '') {
    try {
      return JSON.parse(text);
    } catch (e) { return null; }
  }
  return null;
}).then((json) => {
  console.log('object data', json);
});

不追究代码写得怎么样,重点在于如何组织 WFS URL

  • request: 这里为 getfeature,其他请求类型,点击官网文档
  • typename: 发布的图层名
  • PROPERTYNAME: 需要返回的属性,如果不加则默认全部属性返回,多个属性英文逗号隔开,另外,需要geometry,则需加上geom (因为数据连的是postgreSQL,默认几何属性为geom)
  • CQL_FILTER: 查询条件,可参考官网文档
  • outputformat: 输出格式,支持shp,json,csv等,详情点击官网文档

支持格式(资料来自官网)

FormatSyntaxNotes
GML2outputFormat=GML2Default option for WFS 1.0.0
GML3outputFormat=GML3Default option for WFS 1.1.0 and 2.0.0
ShapefileoutputFormat=shape-zipZIP archive will be generated containing the shapefile (see Shapefile output below).
JSONoutputFormat=application/jsonReturns a GeoJSON or a JSON output. Note outputFormat=json is only supported for getFeature (for backward compatibility).
JSONPoutputFormat=text/javascriptReturns a JSONP in the form: parseResponse(…json…). See WMS vendor parameters to change the callback name. Note that this format is disabled by default (See Global variables affecting WMS).
CSVoutputFormat=csvReturns a CSV (comma-separated values) file

注意:如果请求失败,会返回 XML 的错误说明信息,所以如果要求json,则需要判断结果是否为json。
待研究:如何将编辑后的数据通过WFS塞回数据库

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值