我正在设置PostgreSQL/Geoserver/Open层应用程序。我可以从postgreSQL thorugh作为一个层获取数据,并在我的web应用程序中将其显示在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;
}Geoserver日志
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>发布于 2020-12-28 18:08:28
线索在响应和日志文件中:
No such feature type http://localhost:8080/geoserver/DBdata/wfs:district您正在请求一个不存在的特性。
我怀疑您不希望wfs:在名称中,或者您错误地指定了featureType的NameSpace URL。
当我看到OpenLayers WFS示例页时,我得到:
//生成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')
),
});然而,您没有指定featureNS或featurePrefix,这可能是它们在请求中填写错误的原因。
https://stackoverflow.com/questions/65328552
复制相似问题