I am trying to insert feature like point, line, etc on "india_ds" wfs layer map using wfs-t but not able to make successful POST request using openlayers3. I have post my script and error. I have linked my "india_ds" layer with PostGIS. Also, do I have to make any changes from my geoserver account and postGIS? I am new to openlayers and geoserver. Please help.
<script>
var formatWFS = new ol.format.WFS();
var formatGML = new ol.format.GML({
featureNS: 'http://localhost:8080/geoserver/cite',
featureType: 'india_ds1',
srsName: 'EPSG:3857'
});
var vectorSource = new ol.source.Vector({
format: new ol.format.GeoJSON(),
url: function(extent) {
return 'http://localhost:8080/geoserver/cite/ows?service=WFS&' +
'version=1.0.0&request=GetFeature&typeName=cite:india_ds1&' +
'outputFormat=application/json&srsname=EPSG:3857&' +
'bbox=' + extent.join(',') + ',EPSG:3857';
},
strategy: ol.loadingstrategy.bbox
});
var vector = new ol.layer.Vector({
source: vectorSource
});
var interaction;
var interactionSelectPointerMove = new ol.interaction.Select({
condition: ol.events.condition.pointerMove
});
var interactionSelect = new ol.interaction.Select({
style: new ol.style.Style({
stroke: new ol.style.Stroke({
color: '#FF2828'
})
})
});
var interactionSnap = new ol.interaction.Snap({
source: vector.getSource()
});
var view = new ol.View({
center: [0, 0],
zoom: 2
});
var map = new ol.Map({
target: 'map',
interactions: [
interactionSelectPointerMove,
new ol.interaction.MouseWheelZoom(),
new ol.interaction.DragPan()
],
layers: [vector],
view: view
});
var dirty = {};
var transactWFS = function (mode, f) {
var node;
switch (mode) {
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;
}
var xs = new XMLSerializer();
var payload = xs.serializeToString(node);
var geo = f.getGeometry();
var geometry = geo.getCoordinates();
var postData = '<wfs:Transaction service="WFS" version="1.0.0"\
xmlns:wfs="http://www.opengis.net/wfs"\
xmlns:cite="http://www.openplans.org/cite"\
xmlns:gml="http://www.opengis.net/gml"\
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\
xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd http://www.openplans.org/cite http://localhost:8080/geoserver/wfs/DescribeFeatureType?typename=cite:india_ds1">\
<wfs:Insert>\
<cite:india_ds1>\
<cite:geom>\
<gml:MultiLineString srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">\
<gml:lineStringMember>\
<gml:LineString>\
<gml:LineString srsName="EPSG:3857">\
<gml:coordinates decimal="." cs="," ts=" ">\
'+geometry+'\
</gml:coordinates>\
</gml:LineString>\
</gml:LineString>\
</gml:lineStringMember>\
</gml:MultiLineString>\
</cite:geom>\
<cite:TYPE>alley</cite:TYPE>\
</cite:india_ds1>\
</wfs:Insert>\
</wfs:Transaction>';
$.ajax({
type: 'POST',
url:'http://localhost:8080/geoserver/cite/ows',
dataType: 'xml',
processData: false,
contentType: 'text/xml',
data: postData,
success: function(response){
console.log(" point features were posted to server");
console.log(response);
}
}).done();
};
$('button').click(function () {
$(this).siblings().removeClass('btn-active');
$(this).addClass('btn-active');
map.removeInteraction(interaction);
interactionSelect.getFeatures().clear();
map.removeInteraction(interactionSelect);
switch ($(this).attr('id')) {
case 'btnEdit':
map.addInteraction(interactionSelect);
interaction = new ol.interaction.Modify({
features: interactionSelect.getFeatures()
});
map.addInteraction(interaction);
map.addInteraction(interactionSnap);
dirty = {};
interactionSelect.getFeatures().on('add', function (e) {
e.element.on('change', function (e) {
dirty[e.target.getId()] = true;
});
});
interactionSelect.getFeatures().on('remove', function (e) {
var f = e.element;
if (dirty[f.getId()]) {
delete dirty[f.getId()];
var featureProperties = f.getProperties();
delete featureProperties.boundedBy;
var clone = new ol.Feature(featureProperties);
clone.setId(f.getId());
transactWFS('update', clone);
}
});
break;
case 'btnPoint':
interaction = new ol.interaction.Draw({
type: 'Point',
source: vector.getSource(),
geometryName:'geom'
});
map.addInteraction(interaction);
interaction.on('drawend', function (e) {
var feature = e.feature;
feature.set('geom', feature.getGeometry());
transactWFS('insert', e.feature);
});
break;
case 'btnLine':
interaction = new ol.interaction.Draw({
type: 'LineString',
source: vector.getSource(),
geometryName:'geom'
});
map.addInteraction(interaction);
interaction.on('drawend', function (e) {
var feature = e.feature;
feature.set('geom', feature.getGeometry());
transactWFS('insert', e.feature);
});
break;
case 'btnArea':
interaction = new ol.interaction.Draw({
type: 'MultiPolygon',
source: vector.getSource(),
geometryName:'geom'
});
interaction.on('drawend', function (e) {
var feature = e.feature;
feature.set('geom', feature.getGeometry());
transactWFS('insert', e.feature);
});
map.addInteraction(interaction);
break;
case 'btnDelete':
interaction = new ol.interaction.Select();
interaction.getFeatures().on('add', function (e) {
transactWFS('delete', e.target.item(0));
interactionSelectPointerMove.getFeatures().clear();
interaction.getFeatures().clear();
});
map.addInteraction(interaction);
break;
default:
break;
}
});
</script>
error :-
<ServiceException>
java.lang.RuntimeException: Parsing failed for coordinates: java.lang.IllegalStateException: Unable to usecom.vividsolutions.jts.geom.impl.CoordinateArraySequenceFactory@2cb1c829 to produce CoordinateSequence with dimension 6
Parsing failed for coordinates: java.lang.IllegalStateException: Unable to usecom.vividsolutions.jts.geom.impl.CoordinateArraySequenceFactory@2cb1c829 to produce CoordinateSequence with dimension 6
Unable to usecom.vividsolutions.jts.geom.impl.CoordinateArraySequenceFactory@2cb1c829 to produce CoordinateSequence with dimension 6
</ServiceException>