1

I am working on merging two features and splitting in openlayers 3. Features may be a line or polygon without any plugin like turf.

Below is code of merge two polygon

f1 = selectclick.getFeatures().item(0);
        f2 = selectclick.getFeatures().item(1);
       console.log(f1.getGeometry().getCoordinates());
       console.log(f2.getGeometry().getCoordinates());
        var f3 = new ol.Feature({
            geometry: new ol.geom.MultiPolygon(
              f1.getGeometry().getCoordinates().concat(f2.getGeometry().getCoordinates().slice(1))
            ),
            name: "I'm the joined geom"
        });
        console.log(f3);
        selectclick.getFeatures().clear();
        sourceWFS_polygon.removeFeature(f2);
        sourceWFS_polygon.removeFeature(f1);
        sourceWFS_polygon.addFeature(f3);

There are no errors in the above code but it's still not working. Can anyone help me to merge two selected features?

UPDATE

I have changed code like below. In database both f1 and f2 are deleted and f3 is inserted as in image enter image description here

A is showing f1 and f2 B is showing f3. As observed in image f3 is same as f2 it means merging is not working properly.

   f1 = selectclick.getFeatures().item(0);
        f2 = selectclick.getFeatures().item(1);
        var f3 = new ol.Feature({
            geometry: new ol.geom.MultiPolygon(
                f1.getGeometry().getCoordinates().concat(f2.getGeometry().getCoordinates().slice(1)) ),
            name: "I'm the joined geom"
        });
        console.log(f3);
        f3.getGeometry().transform('EPSG:3857', 'EPSG:4326');
        transactWFS_polygon('insert', f3);
        transactWFS_polygon('delete', f1);
        transactWFS_polygon('delete', f2);

XML:

 var payload = xs.serializeToString(node);
       $.ajax('http://localhost:8066/geoserver/spatial_editing/ows', {
        type: 'POST',
        dataType: 'xml',
        processData: false,
        contentType: 'text/xml',
        data: payload
    }).done(function () {
        sourceWFS_polygon.clear();
    });

Response from geoserver

<?xml version="1.0" encoding="UTF-8"?><wfs:TransactionResponse xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:wfs="http://www.opengis.net/wfs" xmlns:gml="http://www.opengis.net/gml" xmlns:spatial_editing="http://spatial_editing" xmlns:ogc="http://www.opengis.net/ogc" xmlns:ows="http://www.opengis.net/ows" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.1.0" xsi:schemaLocation="http://www.opengis.net/wfs http://localhost:8066/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="polygon.71"/></wfs:Feature></wfs:InsertResults></wfs:TransactionResponse>
  • please add the xml that is sent to the WFS-T and any log messages that the server writes – Ian Turton Oct 21 '17 at 11:24
  • I have updated my question – veena hosur Oct 23 '17 at 5:29

Your Answer

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

Browse other questions tagged or ask your own question.