Sunday, 10 June 2018

Why don't set Geometry column in OpenLayers wfs-t request to geoserver?


I want to edit a vector layer(its a point layer) using OpenLayers 3.6 and then save it with wfs protocol. I'm using Goserver 2.8 in server side. I define my layer as follow:


var u="http://localhost:8080/geoserver/wfs?&service=wfs&version=1.1.0&request=GetFeature&typeNames=opengeo:Point";
format = new ol.format.WFS({});
wfs = new ol.layer.Vector({
title: 'Point',

source: new ol.source.Vector({
url: 'proxy.cgi?url=' + encodeURIComponent(u),
format: format
})
});

I get all features correctly. Now I add a point to layer as follow:


point = new ol.geom.Point([39.8274942, 21.4226638]);
feature = new ol.Feature({
geometry: point

});
feature.set('NAME', 'Ya Ali Madad');
source.addFeature(feature);

Now saving feature is as bellow:


node = format.writeTransaction([feature],null,null,{
featureNS: 'http://opengeo.org',
featureType: 'opengeo:Point',
srsName: 'EPSG:4326'
});


s = new XMLSerializer();

var url = "http://localhost:8080/geoserver/wfs";

Ext.Ajax.request({
url: 'proxy.cgi?url='+ encodeURIComponent(url),
method: 'POST',
xmlData: s.serializeToString(node),
headers: {

'Content-Type': 'text/xml'
},
success: function(response){
console.log("All thing is right.");
}
});

I use Extjs-6 for creating ajax request. it create a request as follow:


Request Payload:



xmlns="http://www.opengis.net/wfs"
service="WFS" version="1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.opengis.net/wfs
http://schemas.opengis.net/wfs/1.1.0/wfs.xsd">





39.8274942 21.4226638


Ya Ali Madad




Request in Network: enter image description here


And geoserver response this request as follow.

GeoServer response:



xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:ogc="http://www.opengis.net/ogc"
xmlns:wfs="http://www.opengis.net/wfs"
xmlns:ows="http://www.opengis.net/ows"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:gml="http://www.opengis.net/gml"
xmlns:opengeo="http://opengeo.org"

xmlns:usa="http://census.gov"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="1.1.0"
xsi:schemaLocation="
http://www.opengis.net/wfs
http://localhost:8080/geoserver/schemas/wfs/1.1.0/wfs.xsd">


1
0

0











Geoserver add this point in database, but don't set geometry field. it only set properties column and Not geometry column.


Where is the problem? How can I do to fix it?



Answer



Your Insert request contains an feature that doesn't match your Schema which is expecting the Point attribute to be called the_geom. You don't get an error because you have marked that feature as Nillable (or optional).
























If you change your request to the following it should work - the best way to test this is using the demo requests page in GeoServer.


xmlns="http://www.opengis.net/wfs" 
service="WFS" version="1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="
http://www.opengis.net/wfs
http://schemas.opengis.net/wfs/1.1.0/wfs.xsd">




39.8274942 21.4226638



Ya Ali Madad




Now you must define the feature as follow:


feature = new ol.Feature({
the_geom: point
});


And then set geometryName features config:


feature.setGeometryName('the_geom');

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...