when i try to insert a feature into an existing WFS Layer on my GeoServer i get the error "Error performing insert: Dbf has extra record" in the log of the GeoServer. I used the following code to insert a feature and get the WFS layer after that.
var GeoServerAddr = 'http://localhost:8080/geoserver/';
var wmsLayerName = 'Stairways';
var wmsWorkgroupName = 'HTW_Erd';
var stroke = new ol.style.Stroke({color: 'black', width: 2});
var fill = new ol.style.Fill({color: 'red'});
var styles = {
'star': new ol.style.Style({
image: new ol.style.RegularShape({
fill: fill,
stroke: stroke,
points: 5,
radius: 10,
radius2: 4,
angle: 0
})
})};
//OSM Layer einbinden
var osmlayer = new ol.layer.Tile({source: new ol.source.OSM()});
//Layer für das Grid zum Speichern der Wände
var GridSource = new ol.source.Vector({
projection: 'EPSG:3857',
format: new ol.format.GeoJSON()
});
var GridLayer = new ol.layer.Vector({
source: GridSource
});
var featureSource = new ol.source.Vector({
format: new ol.format.GeoJSON(),
url: function(extent) {
return gs.wfs + '?service=WFS&' +
'version=1.1.0&request=GetFeature&typename=' + wmsWorkgroupName + ':' + wmsLayerName +
'&outputFormat=application/json&srsname=EPSG:3857&' +
'bbox=' + extent.join(',') + ',EPSG:3857';
},
strategy: ol.loadingstrategy.bbox
});
var featureLayer = new ol.layer.Vector({
source: featureSource,
style: new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'rgba(0, 0, 255, 1.0)',
width: 2
})
})
});
var scaleLineControl = new ol.control.ScaleLine();
//Layer Z-Index festlegen
osmlayer.setZIndex(0);
//GridLayer.setZIndex(5);
var layers = [osmlayer]; //, GridLayer
//Sicht auf HTW Zentrieren
var view = new ol.View({
center: [1529088.5676403488, 6627805.4185389215],
zoom: 18,
rotation: 6
});
var map = new ol.Map({
controls: ol.control.defaults({
attributionOptions: /** @type {olx.control.AttributionOptions} */ ({
collapsible: false
})
}).extend([
scaleLineControl
]),
layers: layers,
target: 'map',
view: view
});
var gs = {
wfs: GeoServerAddr + wmsWorkgroupName + '/wfs',
ows: GeoServerAddr + wmsWorkgroupName + '/ows'
};
function init() { //Wird beim laden der Seite aufgerufen
drawGrid([1528915.8154546698,6627851.731194374], [1529106.647853138,6628043.728236666], 5, null);
//getWfsFeaturesLayer();
}
map.on('singleclick', function(evt) {
console.log("TestAttr: " + getVectorFeatureInfo(featureLayer, evt.pixel, "TestAttr"));
});
var drawGrid = function(TlCoord, BrCoord, Size, apPositions) {
var GridSize = Size * 1.5;
var NewSquare = drawSquare(TlCoord, GridSize);
NewSquare.getGeometry().rotate(map.getView().getRotation(), TlCoord);
GridSource.addFeature(NewSquare);
var attr = {};
var key = "TestAttr";
attr[key] = "This is a Test";
NewSquare.attributes = attr;
transactWFS('insert', NewSquare);
}
var drawSquare = function(StartCoord, size) {
var polyCoords = [[StartCoord, [StartCoord[0], StartCoord[1] + size], [StartCoord[0] + size, StartCoord[1] + size], [StartCoord[0] + size, StartCoord[1]], StartCoord]];
var polygonFeature = new ol.Feature({
geometry: new ol.geom.Polygon(polyCoords),
name: 'geometry'
});
return polygonFeature;
}
var formatWFS = new ol.format.WFS();
var formatGML = new ol.format.GML({
featureNS: 'https://localhost:8080/geoserver/htw_erd',
featurePrefix: wmsWorkgroupName,
featureType: wmsLayerName,
srsName: 'EPSG:3857',
geometryName: "the_geom"
});
var xs = new XMLSerializer();
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 payload = xs.serializeToString(node);
$.ajax(gs.ows, {
service: 'WFS',
type: 'POST',
dataType: 'xml',
processData: false,
contentType: 'text/xml',
data: payload,
error: function(e) {
var errorMsg = e? (e.status + ' ' + e.statusText) : "";
alert('Error saving this feature to GeoServer. \n\n'
+ errorMsg);
}
}).done();
};
var getVectorFeatureInfo = function(featureLayer, pixel, infoKey) {
var features = [];
map.forEachFeatureAtPixel(pixel, function(feature, layer) {
features.push(feature);
}, null, function(layer) {
return layer === featureLayer;
});
console.log("Features Found: " + features.length);
if (features.length > 0) {
for(var i = 0; i < features.length; i++)
{
if (typeof features[i].attributes[infoKey] !== 'undefined')
{
console.log("Found Attribute: " + infoKey + ": " + features[i].attributes[infoKey]);
return features[i].attributes[infoKey];
}
}
} else {
console.log("No Info Aviable");
return "None"
}
}
var getWfsFeaturesLayer = function() {
featureSource = new ol.source.Vector({
format: new ol.format.GeoJSON(),
url: function(extent) {
return gs.wfs + '?service=WFS&' +
'version=1.1.0&request=GetFeature&typename=' + wmsWorkgroupName + ':' + wmsLayerName +
'&outputFormat=application/json&srsname=EPSG:3857&' +
'bbox=' + extent.join(',') + ',EPSG:3857';
},
strategy: ol.loadingstrategy.bbox
});
featureLayer = new ol.layer.Vector({
source: featureSource,
style: new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'rgba(0, 0, 255, 1.0)',
width: 2
})
})
});
//Add Marker to Layer so it is visible that it was loaded correct
var feature;
feature = new ol.Feature(new ol.geom.Point([1528915.8154546698, 6627851.731194374]));
feature.setStyle(styles['star']);
featureSource.addFeature(feature);
map.addLayer(featureLayer);
featureLayer.setZIndex(5);
}
</script>
The describefeature Request shows the following:
<?xml version="1.0"?>
<xsd:schema xmlns:HTW_Erd="https://localhost:8080/geoserver/htw_erd" xmlns:gml="http://www.opengis.net/gml" xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="https://localhost:8080/geoserver/htw_erd">
<xsd:import namespace="http://www.opengis.net/gml" schemaLocation="http://localhost:8080/geoserver/schemas/gml/3.1.1/base/gml.xsd"/>
<xsd:complexType name="StairwaysType">
<xsd:complexContent>
<xsd:extension base="gml:AbstractFeatureType">
<xsd:sequence>
<xsd:element maxOccurs="1" minOccurs="0" name="the_geom" nillable="true" type="gml:MultiSurfacePropertyType"/>
<xsd:element maxOccurs="1" minOccurs="0" name="id" nillable="true" type="xsd:long"/>
<xsd:element maxOccurs="1" minOccurs="0" name="indoor_are" nillable="true" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="indoor_lev" nillable="true" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="indoor_l_1" nillable="true" type="xsd:string"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:element name="Stairways" substitutionGroup="gml:_Feature" type="HTW_Erd:StairwaysType"/>
</xsd:schema>
This seems to be normal. I already discussed a problem that lead to this problem in this question
I hope someone can help me solve this problem too.
Edit:
This is the Post XML
<?xml version="1.0"?>
<Transaction xmlns="http://www.opengis.net/wfs" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" service="WFS" version="1.1.0" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd">
<Insert>
<Stairways xmlns="https://localhost:8080/geoserver/htw_erd">
<geometry>
<Polygon xmlns="http://www.opengis.net/gml" srsName="EPSG:3857">
<exterior>
<LinearRing srsName="EPSG:3857">
<posList>1528915.8154546698 6627851.731194374
1528917.9110709063 6627858.932471524 1528925.1123480562 6627856.836855288
1528923.0167318196 6627849.635578138 1528915.8154546698
6627851.731194374</posList>
</LinearRing>
</exterior>
</Polygon>
</geometry>
<name>geometry</name>
</Stairways>
</Insert>
</Transaction>
This is the Response of the Get:
<ows:exception exceptioncode="NoApplicableCode">
<ows:exceptiontext>
java.lang.RuntimeException: java.io.IOException: Dbf has extra record
java.io.IOException: Dbf has extra record
Dbf has extra record
</ows:exceptiontext>
</ows:exception>
Edit 2:
So i changed the polygon attributes to the attributes from the schema from this link http://localhost:8080/geoserver/wfs?service=wfs&version=1.1.0&request=DescribeFeatureType&typeName=HTW_Erd:Stairways
to this
var polygonFeature = new ol.Feature({
'the_geom': new ol.geom.Polygon(polyCoords),
'id': 100,
'indoor_are': 'whatever value you need',
'indoor_lev': '0',
'indoor_l_1': 'Erdgeschoss',
});
But the error is still the same
Edit:
I updated my GeoServer to the Version 2.11.2 just to be sure i am not using an old version and tried to fix the XML but i always generate this XML file:
<Transaction
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">
<Insert>
<Stairways xmlns="https://localhost:8080/geoserver/htw_erd">
<the_geom>
<Polygon xmlns="http://www.opengis.net/gml" srsName="EPSG:3857"
<exterior>
<LinearRing srsName="EPSG:3857">
<posList>1528915.8154546698 6627851.731194374 1528915.8154546698 6627859.231194374 1528923.3154546698 6627859.231194374 1528923.3154546698 6627851.731194374 1528915.8154546698 6627851.731194374</posList>
</LinearRing>
</exterior>
</Polygon>
</the_geom>
<id>100</id>
<indoor_are>whatever value you need</indoor_are>
<indoor_lev>0</indoor_lev>
<indoor_l_1>Erdgeschoss</indoor_l_1>
</Stairways>
</Insert>
</Transaction>
The describefeature request generates this:
<xsd:schema xmlns:HTW_Erd="https://localhost:8080/geoserver/htw_erd" xmlns:gml="http://www.opengis.net/gml" xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="https://localhost:8080/geoserver/htw_erd" debug="true">
<script id="FirebugLite" firebugIgnore="true" extension="Chrome"/>
<xsd:import namespace="http://www.opengis.net/gml" schemaLocation="http://localhost:8080/geoserver/schemas/gml/3.1.1/base/gml.xsd"/>
<xsd:complexType name="StairwaysType">
<xsd:complexContent>
<xsd:extension base="gml:AbstractFeatureType">
<xsd:sequence>
<xsd:element maxOccurs="1" minOccurs="0" name="the_geom" nillable="true" type="gml:MultiSurfacePropertyType"/>
<xsd:element maxOccurs="1" minOccurs="0" name="id" nillable="true" type="xsd:long"/>
<xsd:element maxOccurs="1" minOccurs="0" name="indoor_are" nillable="true" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="indoor_lev" nillable="true" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="indoor_l_1" nillable="true" type="xsd:string"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:element name="Stairways" substitutionGroup="gml:_Feature" type="HTW_Erd:StairwaysType"/>
</xsd:schema>
So it should fit togehter but i still get the same error.