3

I'm developing a gis Application with java. I use Spring 4.0.1 and GeoTools-13-RC1 in server side and OpenLayers 2.13.1 in client side. In client side, I have a wfs layer and it is as follow:

var saveStrategy = new OpenLayers.Strategy.Save();

wfs_Layer = new OpenLayers.Layer.Vector("Editable Features", {
    strategies: [new OpenLayers.Strategy.BBOX(), saveStrategy],
    projection: new OpenLayers.Projection("EPSG:4326"),
    protocol: new OpenLayers.Protocol.WFS({
        version: "1.1.0",
        srsName: "EPSG:4326",
        url: 'point/read',
        featureType: "point",
        featureNS: "http://itsme.opengeo.org",
        geometryName: "the_geom",
        readFormat: new OpenLayers.Format.GeoJSON({}),
    })
});

wfs_layer get all features from server. Sever return features with follow code:

try {
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("dbtype", "postgis");
    params.put("host", "localhost");
    params.put("port", 5432);
    params.put("schema", "public");
    params.put("database", "template_postgis");
    params.put("user", "postgres");
    params.put("passwd", "postgres");

    DataStore dataStore = DataStoreFinder.getDataStore(params);

    SimpleFeatureStore pointStore = (SimpleFeatureStore) dataStore.getFeatureSource("point");

    SimpleFeatureCollection featuresCollection = pointStore.getFeatures();
    SimpleFeatureIterator features = featuresCollection.features();

    FeatureJSON fjson = new FeatureJSON();
    StringWriter writer = new StringWriter();
    fjson.writeFeatureCollection(featuresCollection, writer);

    String json = writer.toString();
    return json;

} catch (IOException ex) {
    Logger.getLogger(PointController.class.getName()).log(Level.SEVERE, null, ex);
}

The returned features format is as bellow:

{
    "type": "FeatureCollection",
    "features": [{
            "type": "Feature",
            "geometry": {
                "type": "Point",
                "coordinates": [40, 45]
            },
            "properties": {
                "name": "itsme 1"
            },
            "id": "point.1"
        }, {
            "type": "Feature",
            "geometry": {
                "type": "Point",
                "coordinates": [35, 40]
            },
            "properties": {
                "name": "itsme 2"
            },
            "id": "point.2"
        }]
}

User can edit this layer in client side and with saveStrategy.save() send edited features to server. Browser send edited features as follows: Request Payload:

<wfs:Transaction xmlns:wfs="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">
    <wfs:Update typeName="feature:point" xmlns:feature="http://iran.opengeo.org">
        <wfs:Property>
            <wfs:Name>the_geom</wfs:Name>
            <wfs:Value>
                <gml:Point xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326">
                    <gml:pos>48.694467049643556 35.41594833365911</gml:pos>
                </gml:Point>
            </wfs:Value>
        </wfs:Property>
        <wfs:Property>
            <wfs:Name>name</wfs:Name>
            <wfs:Value>itsme edited</wfs:Value>
        </wfs:Property>
        <ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
            <ogc:FeatureId fid="point.2"/>
        </ogc:Filter>
    </wfs:Update>
</wfs:Transaction>

Now I want to modify featuers in server side. How do I do?

2
HttpServletRequest request=...;
org.geotools.xml.parser.Parser parser = new Parser(new org.geotools.wfs.v1_1.WFSConfigration());
TransactionType tt = (TransactionType) parser.parse(request.getReader());
InsertElementType insert1 = (InsertElementType) tt.getInsert().get(0);

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.