3

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:

<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>
        <opengeo:Point xmlns:opengeo="http://opengeo.org">
            <geometry xmlns="http://opengeo.org">
                <Point xmlns="http://www.opengis.net/gml">
                    <pos>39.8274942 21.4226638</pos>
                </Point>
            </geometry>
            <NAME xmlns="http://opengeo.org">Ya Ali Madad</NAME>
        </opengeo:Point>
    </Insert>
</Transaction>

Request in Network: enter image description here

And geoserver response this request as follow.
GeoServer response:

<?xml version="1.0" encoding="UTF-8"?>
<wfs:TransactionResponse 
    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">

    <wfs:TransactionSummary>
        <wfs:totalInserted>1</wfs:totalInserted>
        <wfs:totalUpdated>0</wfs:totalUpdated>
        <wfs:totalDeleted>0</wfs:totalDeleted>
    </wfs:TransactionSummary>
    <wfs:TransactionResults/>

    <wfs:InsertResults>
        <wfs:Feature>
            <ogc:FeatureId fid="new0"/>
        </wfs:Feature>
    </wfs:InsertResults>
</wfs:TransactionResponse>

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?

  • What is the output of DescribeFeatureType on your typename? Is your geometry even called geometry in the feature model? – bartvde Aug 4 '15 at 6:34
  • sorry I don't undrstand you – Morteza Malvandi Aug 4 '15 at 6:36
  • 1
    This is a DescribeFeatureType request: demo.opengeo.org/geoserver/… It shows you the schema. In this case the geometry column is named as "the_geom". Check your own feature type. – user30184 Aug 4 '15 at 6:54
  • 1
    This part or insert request defines that the geometry column is named as "geometry" but it should be "the_geom" <geometry xmlns="http://opengeo.org"> Perhaps you should edit this part of your javascript feature = new ol.Feature({ geometry: point }); I am not sure, though, but you must make the name of the geometry column to match. – user30184 Aug 4 '15 at 7:59
4

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).

<xsd:schema xmlns:gml="http://www.opengis.net/gml" xmlns:opengeo="http://opengeo.org" xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://opengeo.org">
<xsd:import namespace="http://www.opengis.net/gml" schemaLocation="http://localhost:8080/geoserver/schemas/gml/3.1.1/base/gml.xsd"/>
<xsd:complexType name="PointType">
    <xsd:complexContent>
        <xsd:extension base="gml:AbstractFeatureType">
            <xsd:sequence>
                <xsd:element maxOccurs="1" minOccurs="0" name="the_geom" nillable="true" type="gml:PointPropertyType"/>
                <xsd:element maxOccurs="1" minOccurs="0" name="AREA" nillable="true" type="xsd:double"/>
                <xsd:element maxOccurs="1" minOccurs="0" name="PERIMETER" nillable="true" type="xsd:double"/>
                <xsd:element maxOccurs="1" minOccurs="0" name="IR_CEN_" nillable="true" type="xsd:long"/>
                <xsd:element maxOccurs="1" minOccurs="0" name="IR_CEN_ID" nillable="true" type="xsd:long"/>
                <xsd:element maxOccurs="1" minOccurs="0" name="X_COORD" nillable="true" type="xsd:double"/>
                <xsd:element maxOccurs="1" minOccurs="0" name="Y_COORD" nillable="true" type="xsd:double"/>
                <xsd:element maxOccurs="1" minOccurs="0" name="NAME" nillable="true" type="xsd:string"/>
            </xsd:sequence>
        </xsd:extension>
    </xsd:complexContent>
</xsd:complexType>
<xsd:element name="Point" substitutionGroup="gml:_Feature" type="opengeo:PointType"/>

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.

<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>
    <opengeo:Point xmlns:opengeo="http://opengeo.org">
        <the_geom xmlns="http://opengeo.org">
            <Point xmlns="http://www.opengis.net/gml">
                <pos>39.8274942 21.4226638</pos>
            </Point>
        </the_geom>
        <NAME xmlns="http://opengeo.org">Ya Ali Madad</NAME>
    </opengeo:Point>
</Insert>
</Transaction>

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');
  • Yes I do it correctly. But how do I do in my code?feature.setGeometryName('the_geom'); It don't work correctly. – Morteza Malvandi Aug 4 '15 at 8:40
  • Where you say geometry point try the_geom point – Ian Turton Aug 4 '15 at 9:21
  • I brought All of code that I used for defining layer, **adding feature and sending insert request to server. – Morteza Malvandi Aug 4 '15 at 9:52
  • here: feature = new ol.Feature({ geometry: point }); should be: feature = new ol.Feature({ the_geom: point }); – Ian Turton Aug 4 '15 at 9:59
  • change to feature = new ol.Feature({ the_geom: point });? Does not work properly. – Morteza Malvandi Aug 4 '15 at 10:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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