【WebGIS例】 (5) POSTリクエストによるWFS条件付きクエリ

すべての OGC 準拠マップ サーバーで動作します。

<wfs:GetFeature xmlns:wfs="http://www.opengis.net/wfs"
  service="WFS"
  version="1.0.0"
  outputFormat="application/json"
  maxFeatures="10"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.opengis.net/wfs
  http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd">
  <wfs:Query typeName="webgis:guangdong" userecent="true">
    <ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
      <ogc:PropertyIsLike wildCard="*" singleChar="." escape="!">
        <ogc:PropertyName>city</ogc:PropertyName>
        <ogc:Literal>guangzhou</ogc:Literal>
      </ogc:PropertyIsLike>
    </ogc:Filter>
  </wfs:Query>
</wfs:GetFeature>

説明:

  • クエリレイヤー:webgis:guangdong
  • クエリのプロパティ:city
  • クエリ値:guangzhou
  • 出力フォーマットoutputFormat:"application/json"
  • 特徴の数 maxFeature を出力します。"10"

使用例: axios 経由

// 按属性查询
const dataType = 'application/json'; // 输出的格式,不同服务器可能不同
const layerName = 'webgis:guangdong'; // 查询的图层
const propertyName = 'city'; // 查询的属性
const attr = 'guangzhou'; // 查询的值

function postWFSAttribute() {
    
    
  const data = ''
  + `<wfs:GetFeature xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.0.0" outputFormat="${
      
      dataType}" maxFeatures="100" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd">`
  + ` <wfs:Query typeName="${
      
      layerName}" userecent="true">`
  + '  <ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">'
  + '  <ogc:PropertyIsLike wildCard="*" singleChar="." escape="!">'
  + `    <ogc:PropertyName>${
      
      propertyName}</ogc:PropertyName>`
  + `    <ogc:Literal>${
      
      attr}</ogc:Literal>`
  + '  </ogc:PropertyIsLike>'
  + '</ogc:Filter>'
  + '</wfs:Query>'
  + '</wfs:GetFeature>';

  return axios({
    
    
    headers: {
    
    
      'Content-Type': 'application/xml',
    },
    method: 'POST',
    url: 'http://localhost/geoserver/webgis/ows',
    data,
    timeout: 10000, // 设置10秒超时
  });
}

参照と拡張

  1. OGC フィルター: https://www.ogc.org/standards/filter
  2. GeoServer での条件付きクエリのための WFS の使用

おすすめ

転載: blog.csdn.net/ReBeX/article/details/128368588