其他分享
首页 > 其他分享> > geoserver wfs 服务访问

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

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

Format Syntax Notes
GML2 outputFormat=GML2 Default option for WFS 1.0.0
GML3 outputFormat=GML3 Default option for WFS 1.1.0 and 2.0.0
Shapefile outputFormat=shape-zip ZIP archive will be generated containing the shapefile (see Shapefile output below).
JSON outputFormat=application/json Returns a GeoJSON or a JSON output. Note outputFormat=json is only supported for getFeature (for backward compatibility).
JSONP outputFormat=text/javascript Returns 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).
CSV outputFormat=csv Returns a CSV (comma-separated values) file

待研究:如何将编辑后的数据通过WFS塞回数据库

标签:outputFormat,const,text,geoserver,访问,json,WFS,wfs,官网
来源: https://blog.csdn.net/geol200709/article/details/94646941