【发布时间】: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