Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I develop a WebGIS application with GeoServer (2.1.1) and GeoExt (with the last version of OL). Data (polygons features) are stored in a postgis DB.

I've implemented editing tools that allow users to add/delete and modify features and their attributes directly on-line. It's work fine.

Now, I add a new control for splitting polygons in two (or more) parts. It's possible with the GeoServer's split polygon WPS process (gs:SplitPolygon).

I've followed the tuto here (http://blog.opengeo.org/2012/07/24/splitpolygon-wps-process-p2/) and implemented the tools on my appl. For information, this is the code I've used:

function handleSplitDraw(event) {
var splitter = event.feature;
var features = map.layers[2].features;
var candidates = OpenLayers.Array.filter(map.layers[2].features, function(feature) {
var hit = false;
    if (feature.geometry.intersects(splitter.geometry)) {
        hit = true;
    }
    return hit;
    });
var candidate;
for (var i=0, ii=candidates.length; i<ii; ++i) {
    candidate = candidates[i];
    if (candidate.geometry.intersects(splitter.geometry)) {
        map.layers[2].removeFeatures([candidate]);
        executeSplit(candidate, splitter);
    }
}
return false;}
var wktFormat = new OpenLayers.Format.WKT();
var wpsFormat = new OpenLayers.Format.WPSExecute();
function executeSplit(poly, line) {      
var doc = this.wpsFormat.write({
    identifier: "gs:SplitPolygon",
    dataInputs: [{
        identifier: "polygon",
        data: {
            complexData: {
                mimeType: "application/wkt",
                value: wktFormat.write(poly)
            }
        }
    }, {
        identifier: "line",
        data: {
            complexData: {
                mimeType: "application/wkt",
                value: wktFormat.write(line)
            }
        }
    }],
    responseForm: {
        rawDataOutput: {
            mimeType: "application/wkt",
            identifier: "result"
        }
    }
});
    OpenLayers.Request.POST({
    url: "http://localhost:8080/geoserver/wps",
    data: doc,
    success: function(response) {
        handleSuccess(response, poly);
    }
});}
function handleSuccess(response, poly) {
var features = wktFormat.read(response.responseText);
if (features && features.length > 0) {
    map.layers[2].addFeatures(features);
} else {
   // map.layers[1].addFeatures([poly]);
}}

Control:

var drawLine = new OpenLayers.Control.DrawFeature(map.layers[2], OpenLayers.Handler.Path); 
 mapPanel.map.addControls(drawLine]);

WFS definition:

saveStrategy = new OpenLayers.Strategy.Save();
wfs_layer =     new OpenLayers.Layer.Vector(
        "Editable plot Layer", 
        {
        styleMap: WFSStyle,
            eventListeners: {
                sketchcomplete: function(event) {
                        var proceed = true;
                        if (event.feature.geometry instanceof OpenLayers.Geometry.LineString) {
                            handleSplitDraw(event);
                            proceed = false;
                        }
                        return proceed;
                    }
                },
                visibility: false,
                strategies: [new OpenLayers.Strategy.BBOX(), saveStrategy],
                    projection: new OpenLayers.Projection("EPSG:4326"),
                    protocol: new OpenLayers.Protocol.WFS({
                        version: "1.1.0",
                        url: "note_url",
                        featureNS :  "FNS",
                        featureType: "fname",
                        geometryName: "the_geom",
                        extractAttributes: true,
                        schema: "myschema"
                    })
                }
        ),

The process work very fine. I can split polygons by line and splitted features are added on my map. In FB consol, I receive a correct response (Geom Collection).

Now, I would like to save back these changes (splitted polygons) to GeoServer. How can I do this? Can I use the WKT response and save the Geometry on a GeoJSON File (for example) for update the database? Do you have any idea of this step?

Thanks very much

Geoffroy

share|improve this question
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.