openlayers4+geoserver wfs realizes spatial analysis and attribute query

openlayers4, geoserver wfs realizes spatial analysis and attribute query

principle
write picture description here

  1. Workspaces enable WFS
    write picture description here
    write picture description here
  2. Publish layer under workspace
  3. code
var featureRequest = new ol.format.WFS().writeGetFeature({
            srsName: 'EPSG:4326',//坐标系统
            featureNS: 'zjk',//命名空间 URI
            featurePrefix: 'sf',//工作区名称
            featureTypes: '',//查询图层,可以同一个工作区下多个图层,逗号隔开
            outputFormat: 'application/json',
            filter: ol.format.filter.intersects(//查询过滤条件
                'the_geom',//
                geometry//
        });
        //http请求数据
fetch(geoserverUrl + 'wfs', {//geoserver wfs地址如localhost:8080/geoserver/wfs
            method: 'POST',
            body: new XMLSerializer().serializeToString(featureRequest)
        }).then(function (response) {
            return response.json();
        }).then(function (json) {
          //查询结果
        })
  1. Query filter conditions openlayers api
    selects the corresponding filter according to the spatial relationship of the query, and passes the corresponding parameters.
    write picture description here

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325891928&siteId=291194637