我不能解决这个问题
我们开发了一个网络地图应用程序。
我们使用OpenLayers版本6和Geoserver 2.18,以及PostGis 3.0.2
在打开层上加载WFS层是没有问题的。
在Openlayers上,我尝试编辑(添加新向量)该层(Wfs),但保存失败。
在Qgis上编辑这一层(Wfs)进展顺利。
这里是代码块:
//variables
var its_typeName ='reception:fak_test';
var url_NS = 'http://localhost:8080/geoserver';
var url_wfs ='http://localhost:8080/geoserver/reception/ows?service=WFS&version=1.0.0';
var fak_draw;
var formatWFS = new ol.format.WFS();
var formatGML = new ol.format.GML3({
featureNS: url_NS,
featureType: its_typeName,
srsName: 'EPSG:4326'
//srsName: "EPSG:3857"
});
var transactWFS = function(p,f) {
f.unset('bbox', true);
switch(p) {
case 'insert':
node = formatWFS.writeTransaction([f],null,null,formatGML);
break;
case 'update':
node = formatWFS.writeTransaction(null,[f],null,formatGML);
break;
case 'delete':
node = formatWFS.writeTransaction(null,null,[f],formatGML);
break;
}
s = new XMLSerializer();
str = s.serializeToString(node);
console.log(str);
// send data
var request = new XMLHttpRequest();
request.onreadystatechange = function() {
if (request.readyState == 4 && request.status == 200) {
alert(request.responseText);
}
}
request.open("POST", url_wfs, true);
request.send(str);
}
// parameter of layer
var PolygonStyle = [
new ol.style.Style({
stroke: new ol.style.Stroke({ color: '#EC1B0C', width: 3,}),
fill: new ol.style.Fill({ color: 'rgba(0, 0, 255, 0.1)',}),
})
];
// to load wfs on OpenLayers
function test_wfs_t(){
var url = url_wfs
+ '&request=GetFeature'
+ '&typeName=' + its_typeName
+ '&outputFormat=application/json';
fetch(url)
.then((response) => response.text())
.then((data) => {
//console.log(data);
getItsAttributs_db(data);
});
}
function getItsAttributs_db(xData)
{
//get its infos to post in the new feature
var JSON_received = JSON.parse(xData);
var len_draw = JSON_received.features.length;
var xid = len_draw + 1;
var nom = "xxx";
var custom_lab = "next";
var descriptio = "bla bla";
var xcouleur= "#FF0000";
// convert to GeoJSON
const vectorSource = new ol.source.Vector({
features: new ol.format.GeoJSON().readFeatures(xData, {
dataProjection: 'EPSG:4326',
featureProjection: 'EPSG:3857'
}),
});
// init vector to load on map
var fak_Vector = new ol.layer.Vector({
source: vectorSource,
style: PolygonStyle
});
var its_source = fak_Vector.getSource();
// load on map
map.addLayer(fak_Vector);
//remove old draw
map.removeInteraction(fak_draw);
//add new draw
draw_boo_wfst = true;
fak_draw = new ol.interaction.Draw({
type: 'MultiPolygon',
source: its_source
});
map.addInteraction(fak_draw);
// on end of draw
fak_draw.on('drawend', function(e) {
//add its properties
var draw_wfst = e.feature;
draw_wfst.setProperties(create_gfc_Attributs_view(xid, nom, descriptio, custom_lab, xcouleur));
// try to send to database
transactWFS('insert', draw_wfst);
});
}
// to create attributs of the new feature
function create_gfc_Attributs_view(xid, nom, descriptio, custom_lab, xcouleur){
var xTable = {};
xTable.id = xid;
xTable.name = nom;
xTable.descriptio = descriptio;
xTable.custom_lab = custom_lab;
xTable.color = xcouleur;
// callback
return xTable;
}PostgreSQL语法:
-- Structure of postgis
CREATE TABLE public.fak_test
(
id integer NOT NULL DEFAULT nextval('track_store.fak_test_id_seq'::regclass),
geom geometry(MultiPolygon,4326),
name character varying(254) COLLATE pg_catalog."default",
descriptio character varying(254) COLLATE pg_catalog."default",
custom_lab character varying(254) COLLATE pg_catalog."default",
color character varying(254) COLLATE pg_catalog."default",
CONSTRAINT fak_test_pkey PRIMARY KEY (id)
)
GRANT ALL ON TABLE public.fak_test TO myuser;
CREATE INDEX sidx_fak_test_geom
ON public.fak_test USING gist
(geom)
TABLESPACE pg_default;GML的输出
<Transaction xmlns="http://www.opengis.net/wfs" service="WFS" version="1.1.0"
xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Insert>
<reception:fak_test xmlns:reception="http://localhost:8080/geoserver">
<reception:geometry>
<MultiPolygon xmlns="http://www.opengis.net/gml" srsName="EPSG:4326">
<polygonMember>
<Polygon srsName="EPSG:4326">
<exterior>
<LinearRing srsName="EPSG:4326">
<posList srsDimension="2">
-2144007.8418341065 5288167.744512376 -2144040.7892421824 5289040.850826394 -2145259.8433409994 5288645.48192948 -2144007.8418341065 5288167.744512376
</posList>
</LinearRing>
</exterior>
</Polygon>
</polygonMember>
</MultiPolygon>
</reception:geometry>
<reception:id>5</reception:id>
<reception:name>xxx</reception:name>
<reception:descriptio>bla blax</reception:descriptio>
<reception:custom_lab>suite</reception:custom_lab>
<reception:color>#FF0000</reception:color>
</reception:fak_test>
</Insert>
</Transaction>来自服务器的响应:
<?xml version="1.0" encoding="UTF-8"?>
<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="InvalidParameterValue">
<ows:ExceptionText>org.geotools.referencing.operation.projection.PointOutsideEnvelopeException: -2144007.8418341065 outside of (-180.0,180.0)
Parsing failed for LinearRing: org.geoserver.wfs.WFSException: org.geotools.referencing.operation.projection.PointOutsideEnvelopeException: -2144007.8418341065 outside of (-180.0,180.0)
org.geotools.referencing.operation.projection.PointOutsideEnvelopeException: -2144007.8418341065 outside of (-180.0,180.0)
-2144007.8418341065 outside of (-180.0,180.0)</ows:ExceptionText>
</ows:Exception>
</ows:ExceptionReport>问题出在哪里?谢谢
发布于 2022-02-10 08:28:21
你对GeoServer撒谎,它不喜欢这样。您发送的坐标不是lat/lon中的,而是声称它们是的。
<Polygon srsName="EPSG:4326">
<exterior>
<LinearRing srsName="EPSG:4326">
<posList srsDimension="2">
-2144007.8418341065 5288167.744512376 -2144040.7892421824 5289040.850826394 -2145259.8433409994 5288645.48192948 -2144007.8418341065 5288167.744512376
</posList>
</LinearRing>
</exterior>
</Polygon>我不知道你的地图在什么投影中,但我猜它是what (EPSG:3857),所以你要么在你发送的数据中设置它,要么在发送之前将多边形重新投影到ESPG:4326。
https://stackoverflow.com/questions/71060685
复制相似问题