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?

  • It looks as though you are sending GML3 to a WFS 1.1 service which is expecting GML2 – Ian Turton Aug 31 '15 at 8:16
  • I texted it with GML2 and result was same – Morteza Malvandi Aug 31 '15 at 8:21
  • Try to add region and shape_len var to your properties object before the newFeature.sertProperties – Francisco Puga Aug 31 '15 at 8:25
  • @mortezamalvandi please put all the relevant information in your question – Ian Turton Aug 31 '15 at 8:28
  • Francisco Puga I do it and updated the requested in question. – Morteza Malvandi Aug 31 '15 at 9:57
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])
});
  • I saw that, I'm using OpenLayers-3. This code is for OpneLayers-2 – Morteza Malvandi Aug 31 '15 at 11:06
0

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'
});

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.