【问题标题】:WFS layer in openlayers not showing up in the databaseopenlayers 中的 WFS 层未显示在数据库中
【发布时间】:2020-12-16 17:52:31
【问题描述】:

我正在设置一个 PostgreSQL/Geoserver/Openlayers 应用程序。我可以通过 Geoserver 从 postgreSQL 获取数据作为图层并将其显示在我的 Web 应用程序中的 openlayers 地图上方,但是 当我尝试在 openlayers 地图上创建多边形并将其存储在数据库中时,我无法这样做。多边形的创建工作正常,但在那之后什么也没有发生,我看不到它存储在任何地方,当我刷新页面时它就消失了。可能我的 Post 查询无法正常工作。这是我的 GET 和 POST 查询代码。 如何在数据库中存储多边形?

var formatWFS = new ol.format.WFS();
var formatGML = new ol.format.GML({
    featureNS: 'http://localhost:8080/geoserver/DBdata/wfs',
    featureType: 'wfs_geom',
    srsName: 'EPSG:3857'
});

var s = new XMLSerializer();

var sourceWFS = new ol.source.Vector({
    loader: function (extent) {
        $.ajax('http://localhost:8080/geoserver/DBdata/wfs', {
            type: 'GET',
            data: {
                service: 'WFS',
                version: '1.1.0',
                request: 'GetFeature',
                typename: 'DBdata:district',
                srsname: 'EPSG:3857',
                bbox: extent.join(',') + ',EPSG:3857'
            }
        }).done(function (response) {
            sourceWFS.addFeatures(formatWFS.readFeatures(response));
        });
    },
    strategy: ol.loadingstrategy.bbox,
    projection: 'EPSG:3857'
});

var layerWFS = new ol.layer.Vector({
    source: sourceWFS
});

var map = new ol.Map({
    target: 'map',
    layers: [
        new ol.layer.Tile({
          source: new ol.source.OSM()
         }),
        layerWFS
    ],
    view: new ol.View({
        center: ol.proj.fromLonLat([71,30]),
        zoom: 4
    })
});

var interaction = new ol.interaction.Draw({
    type: 'Polygon',
    source: layerWFS.getSource()
});

map.addInteraction(interaction);

interaction.on('drawend', function (e) {
    $.ajax('http://localhost:8080/geoserver/DBdata/wfs', {
        type: 'POST',
        dataType: 'xml',
        contentType: 'text/xml',
        data: s.serializeToString(formatWFS.writeTransaction([e.feature], null, null, formatGML))
    }).done();
});


function switchlayer(thelayer){
          var layer= {
             
              districtwfs:layerWFS,
              
          }
          [thelayer];
          layer.setVisible(!layer.getVisible());
          return layer;
      }

地理服务器日志


    Request: getFeature service = WFS version = 1.1.0 baseUrl = http://localhost:8080/geoserver/ query[0]: filter = [ bbox ReferencedEnvelope[3158473.130378682 : 1.2648894562266165E7, 1546761.9194038615 : 5460337.767604887] ] srsName = EPSG:3857 typeName[0] = {http://geoserver.org/DBdata}district outputFormat = text/xml; subtype=gml/3.1.1 resultType = results 2020-12-28 21:54:01,553 INFO [geoserver.wfs] - Request: getServiceInfo 2020-12-28 21:54:01,570 ERROR [geoserver.ows] - org.geoserver.wfs.WFSException: No such feature type http://localhost:8080/geoserver/DBdata/wfs:district at org.geoserver.wfs.WFSWorkspaceQualifier.ensureFeatureNamespaceUriMatches(WFSWorkspaceQualifier.java:215) at org.geoserver.wfs.WFSWorkspaceQualifier.qualifyRequest(WFSWorkspaceQualifier.java:192) at org.geoserver.ows.WorkspaceQualifyingCallback.operationDispatched(WorkspaceQualifyingCallback.java:49) at org.geoserver.ows.Dispatcher.fireOperationDispatchedCallback(Dispatcher.java:830)

回应


    <ows:ExceptionReport
     
    xmlns:xs
    ="
    http://www.w3.org/2001/XMLSchema
    "
     
    xmlns:ows
    ="
    http://www.opengis.net/ows
    "
     
    xmlns:xsi
    ="
    http://www.w3.org/2001/XMLSchema-instance
    "
     
    version
    ="
    1.0.0
    "
     
    xsi:schemaLocation
    ="
    http://www.opengis.net/ows http://localhost:8080/geoserver/schemas/ows/1.0.0/owsExceptionReport.xsd
    "
    >
    <ows:Exception
     
    exceptionCode
    ="
    NoApplicableCode
    "
    >
    <ows:ExceptionText
    >
    No such feature type http://localhost:8080/geoserver/DBdata/wfs:district
    </ows:ExceptionText
    >
    </ows:Exception>
    </ows:ExceptionReport>

【问题讨论】:

  • 请添加发送到geoserver的XML和返回的响应,geoserver日志文件中可能还有有用的信息
  • @IanTurton 我如何访问它?
  • 请求和响应将显示在调试器网络选项卡中,GeoServer 日志位于 data_dir/logs 文件夹中
  • @IanTurton 我已添加来自 Geoserver 和网络选项卡的响应
  • @IanTurton 我已经指定了featureNS。我的 WFS GET 请求工作正常,如果您查看有问题的代码,则 POST 查询不起作用。我已经提到了这两个问题

标签: database postgresql web-services post geoserver


【解决方案1】:

线索在响应和日志文件中:

No such feature type http://localhost:8080/geoserver/DBdata/wfs:district

您请求的功能不存在。

我怀疑您不希望名称中包含 wfs:,或者您错误指定了 featureType 的 NameSpace URL。

当我查看OpenLayers WFS example page 时,我得到:

// 生成 GetFeature 请求

var featureRequest = new WFS().writeGetFeature({
  srsName: 'EPSG:3857',
  featureNS: 'http://openstreemap.org',
  featurePrefix: 'osm',
  featureTypes: ['water_areas'],
  outputFormat: 'application/json',
  filter: andFilter(
    likeFilter('name', 'Mississippi*'),
    equalToFilter('waterway', 'riverbank')
  ),
});

而您没有指定 featureNSfeaturePrefix,这可能是他们在请求中填写错误的原因。

【讨论】:

    猜你喜欢
    • 2015-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-06
    • 1970-01-01
    相关资源
    最近更新 更多