1

I'm using OpenLayers 3.8.2. I have wfs layer. I insert a feature. I save this feature as follow(I use geoserver 2.7-SNAPSHOT in server side):

var features = source.getFeatures();
var insertedArr = [];
var updateArr = [];
var deleteArr = [];

for (var i in features) {
    var state = features[i].getProperties().state;
    switch (state) {
        case "insert":
            console.log("------- INSERT -------")
            var feature = features[i];
            var properties = feature.getProperties();

            if (properties.boundedBy)
                delete properties.boundedBy;

            if (properties.the_geom)
                delete properties.the_geom;

            if (properties.geometry)
                delete properties.geometry;

            if (properties.controllerId)
                delete properties.controllerId;

            var geometry = feature.getGeometry().clone();
            geometry.transform("EPSG:3857", "EPSG:4326");

            newFeature = new ol.Feature({
                the_geom: geometry
            });
            newFeature.setGeometryName("the_geom");
            newFeature.setProperties(properties);
            newFeature.setId(feature.getId());

            insertedArr.push(newFeature);
            break;
        case "update":
            ...
            break
        case "delete":
            ...
            break;
    }
}

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

var node = wfs.writeTransaction(insertedArr, updateArr, deleteArr, {
    featureType: "mf",
    featurePrefix: 'Calk',
    featureNS: "http://itsme.calk.ir",
    version: '1.1.0',
    srsName: "EPSG:4326"
});

var 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_) {
        response = response_;
    }
});

It send a request to server as follow:

<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>
        <mf xmlns="http://itsme.calk.ir">
            <the_geom>
                <Polygon xmlns="http://www.opengis.net/gml">
                    <exterior>
                        <LinearRing>
                            <posList>48.05419921875 37.30901407427592 ... 48.05419921875 37.30901407427592</posList>
                        </LinearRing>
                    </exterior>
                </Polygon>
            </the_geom>
            <region>MyRegion</region>
            <shape_len>10</shape_len>
        </mf>
    </Insert>
</Transaction>

But the server response as follow:

<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://192.168.3.2:8082/geoserver/schemas/ows/1.0.0/owsExceptionReport.xsd">
    <ows:Exception exceptionCode="InvalidParameterValue">
        <ows:ExceptionText>Error performing insert: java.lang.String cannot be cast to com.vividsolutions.jts.geom.Geometry</ows:ExceptionText>
    </ows:Exception>
</ows:ExceptionReport>

The discribefeatureType of geoserver's layer is as follow:

<xsd:schema xmlns:Calk="http://itsme.calk.ir" xmlns:gml="http://www.opengis.net/gml" 
            xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" 
            targetNamespace="http://itsme.calk.ir">

    <xsd:import namespace="http://www.opengis.net/gml" 
                schemaLocation="http://192.168.3.2:8082/geoserver/schemas/gml/3.1.1/base/gml.xsd"/>

    <xsd:complexType name="mfType">
        <xsd:complexContent>
            <xsd:extension base="gml:AbstractFeatureType">
                <xsd:sequence>
                    <xsd:element maxOccurs="1" minOccurs="0" name="region" nillable="true" type="xsd:string"/>
                    <xsd:element maxOccurs="1" minOccurs="0" name="shape_len" nillable="true" type="xsd:int"/>
                    <xsd:element maxOccurs="1" minOccurs="0" name="the_geom" nillable="true" type="gml:MultiSurfacePropertyType"/>
                </xsd:sequence>
            </xsd:extension>
        </xsd:complexContent>
    </xsd:complexType>
    <xsd:element name="mf" substitutionGroup="gml:_Feature" type="Calk:mfType"/>
</xsd:schema>

Where is the problem? Why server reply Error performing insert: java.lang.String cannot be cast to com.vividsolutions.jts.geom.Geometry?

5
  • It looks as though you are sending GML3 to a WFS 1.1 service which is expecting GML2
    – Ian Turton
    Aug 31, 2015 at 8:16
  • I texted it with GML2 and result was same Aug 31, 2015 at 8:21
  • Try to add region and shape_len var to your properties object before the newFeature.sertProperties Aug 31, 2015 at 8:25
  • @mortezamalvandi please put all the relevant information in your question
    – Ian Turton
    Aug 31, 2015 at 8:28
  • Francisco Puga I do it and updated the requested in question. Aug 31, 2015 at 9:57

2 Answers 2

1

It's occur because you are drawing a polygon, But server accept a multipolygon. When you define drawInteraction, you have to define it as follow:

drawInteraction = new ol.interaction.Draw({
   source: mySource,
   type: 'MultiPolygon'
});
1
  • this saved my day. If I may also further suggest import GeometryType from 'ol/geom/GeometryType' and then using type: GeometryType.MULTI_POLYGON. Jan 28, 2021 at 17:41
0

The schema of your layer expects a gml:MultiSurfacePropertyType for the_geom field but you are filling the field with a Polygon. Check this thread.

I'm not sure if sending a MultiPolygon automatically converts to MultiSurface.

Try something like

newFeature = new ol.Feature({
    the_geom: OpenLayers.Geometry.MultiPolygon([geometry])
});
1
  • I saw that, I'm using OpenLayers-3. This code is for OpneLayers-2 Aug 31, 2015 at 11:06

Your Answer

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

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