2

I want to create some squared features with OpenLayers 4, add attributes to each feature and want to save them on the GeoServer to load them later on to another map. I am able to create the features, add attributes to them, read the attributes again and load a layers as WFS again.

My only problem is to save the created features to the GeoServer. I figured out that saving and loading should be possible with WFS-t. I found some examples online but they don't seem to work properly.

When i send the feature to the GeoServer with the function transactWFS at line 133 I get the Error "org.geoserver.wfs.WFSTransactionException: Feature type 'Stairways' is not available" in the GeoServer log file. The Layer Stairways exists on the GeoServer. This is the XML file that is sent:

<?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="http://localhost:8080/geoserver/wfs">
      <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>
    </Stairways>
  </Insert>       
</Transaction>

This is my whole Code:

   GridSource.addFeature(NewSquare);

    var attr = {};
    var key = "TestAttr";
    attr[key] = "This is a Test";

    NewSquare.attributes = attr; 
    transactWFS('insert', NewSquare);        
  }



  var formatWFS = new ol.format.WFS();

  var formatGML = new ol.format.GML({
      featureNS: gs.wfs,
      featurePrefix: 'HTW_Erd',
      featureType: 'Stairways',
      srsName: 'EPSG:3857'
  });

  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();

  };

Edit:
I saw in the log file that i wasnt allowed to write on that layer so i set the permissions. I also changed the projection of the GridLayer to 3857 and the name of the feature to geometry. But that didn't help either. I now don't get any errors and the log looks like this:

2017-07-30 23:47:07,676 INFO [geoserver.wfs] - 
Request: getServiceInfo
2017-07-30 23:47:07,709 INFO [geoserver.wfs] - 
Request: getServiceInfo
2017-07-30 23:47:07,744 INFO [geoserver.gwc] - DataStoreChange: {https://localhost:8080/geoserver/htw_erd}Stairways PreInsert
2017-07-30 23:47:07,749 INFO [geoserver.gwc] - DataStoreChange: {https://localhost:8080/geoserver/htw_erd}Stairways PostInsert
2017-07-30 23:47:07,751 INFO [geoserver.wfs] - 
Request: getFeature
    service = WFS
    version = 1.1.0
    baseUrl = http://localhost:8080/geoserver/
    query[0]:
        filter = [  bbox POLYGON ((1528628.1984057308 6627469.038650171, 1528628.1984057308 6628141.798427672, 1529548.9368749668 6628141.798427672, 1529548.9368749668 6627469.038650171, 1528628.1984057308 6627469.038650171)) ]
        srsName = EPSG:3857
        typeName[0] = {https://localhost:8080/geoserver/htw_erd}Stairways
    outputFormat = application/json
    resultType = results
2017-07-30 23:47:07,754 INFO [wfs.json] - about to encode JSON
2017-07-30 23:47:07,801 INFO [geoserver.wfs] - 
Request: transaction
    service = WFS
    version = 1.1.0
    baseUrl = http://localhost:8080/geoserver/
    group[0] = wfs:insert=net.opengis.wfs.impl.InsertElementTypeImpl@e314ac (feature: [SimpleFeatureImpl:Stairways=[SimpleFeatureImpl.Attribute: the_geom<the_geom id=fid--2e9bc012_15d95498172_-7ffe>=null, SimpleFeatureImpl.Attribute: id<id id=fid--2e9bc012_15d95498172_-7ffe>=null, SimpleFeatureImpl.Attribute: indoor_are<indoor_are id=fid--2e9bc012_15d95498172_-7ffe>=null, SimpleFeatureImpl.Attribute: indoor_lev<indoor_lev id=fid--2e9bc012_15d95498172_-7ffe>=null, SimpleFeatureImpl.Attribute: indoor_l_1<indoor_l_1 id=fid--2e9bc012_15d95498172_-7ffe>=null]], handle: null, idgen: <unset>, inputFormat: <unset>, srsName: null)
    insert[0]:
        feature[0] = SimpleFeatureImpl:Stairways=[SimpleFeatureImpl.Attribute: the_geom<the_geom id=fid--2e9bc012_15d95498172_-7ffe>=null, SimpleFeatureImpl.Attribute: id<id id=fid--2e9bc012_15d95498172_-7ffe>=null, SimpleFeatureImpl.Attribute: indoor_are<indoor_are id=fid--2e9bc012_15d95498172_-7ffe>=null, SimpleFeatureImpl.Attribute: indoor_lev<indoor_lev id=fid--2e9bc012_15d95498172_-7ffe>=null, SimpleFeatureImpl.Attribute: indoor_l_1<indoor_l_1 id=fid--2e9bc012_15d95498172_-7ffe>=null]
        idgen = GenerateNew
        inputFormat = text/xml; subtype=gml/3.1.1
    releaseAction = ALL

All the features that are already in the Layer named 'the_geom', renaming the feature to the_geom doesn't help.

Edit 2: This is the Output

<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" locator="service">
<ows:ExceptionText>No service: ( wfs\ )</ows:ExceptionText>
</ows:Exception>
</ows:ExceptionReport>

I have to add that I dont have the default layers anymore, so i dont have the topp workgroup and the layer states anymore.

Edit 3: This is the Output for this link: http://localhost:8080/geoserver/wfs?service=wfs&version=1.1.0&request=DescribeFeatureType&typeName=HTW_Erd:Stairways

<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>
1
  • you need to run it for your layer not topp:states - I know what it's attributes are!
    – Ian Turton
    Commented Jul 31, 2017 at 15:48

1 Answer 1

1

You are telling GeoServer that the namespace for your feature is xmlns="http://localhost:8080/geoserver/wfs" (or gs.wfs) when it should be the URI associated with your workspace that contains the Stairways featuretype.

I would also check to be sure that the layer name really starts with a capital S as it is case sensitive.

EDIT

You will need to set the geometry field name using

 geometryName: "the_geom",

in your GML format.

20
  • Thanks for the help, i used the URI of my Workspace and now there is no error anymore. But the Problem is that when I import the Stairways layer after adding and uploading the feature, the newly added feature dosent appear on that layer and also no attributes. There only appear the already added features that i uploaded manualy.
    – Killerawft
    Commented Jul 30, 2017 at 17:31
  • Then you need to look in the log file to see if it says anything. Next check that the geometry of your layer is called geometry and that it is in 3857
    – Ian Turton
    Commented Jul 30, 2017 at 17:35
  • Edited the main post
    – Killerawft
    Commented Jul 30, 2017 at 21:56
  • Now i get the error "java.io.IOException: Dbf has extra record" in the log files and i cant find a solution online.
    – Killerawft
    Commented Jul 31, 2017 at 13:14
  • what does describeFeature on the layer you are trying to write to say
    – Ian Turton
    Commented Jul 31, 2017 at 13:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.