2

I'm using OpenLayers-3. I have a wfs layer. I want to sync this layer with my server as follow(I use geoserver 2.7-SNAPSHOT and my datastore's type is shapefile):

var opt = {
    featureType: "Calk:Point",
    featureNS: "http://itsme.calk.org",
    srsName: "EPSG:4326"
}
var s = new XMLSerializer();

var url = "http://localhost:8080/geoserver/wfs";

var node = wfs.writeTransaction(InsertFeaturesArr, updateFeaturesArr, deleteFeaturesArr, opt);
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 create a payload request 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>
        <Point xmlns="http://itsme.calk.ir">
            <the_geom>
                <Point xmlns="http://www.opengis.net/gml">
                    <pos>44.53857421875 25.492868271257123</pos>
                </Point>
            </the_geom>
                ...
            <NAME>asdf</NAME>
        </Point>
    </Insert>
    <Update typeName="Calk:Point" xmlns:Calk="http://itsme.calk.ir">
        <Property>
            <Name>the_geom</Name>
            <Value>
                <Point xmlns="http://www.opengis.net/gml">
                    <pos>29.614517211914062 52.532684326171875</pos>
                </Point>
            </Value>
        </Property>
           ...
        <Filter xmlns="http://www.opengis.net/ogc">
            <FeatureId fid="Point.21"/>
        </Filter>
    </Update>
    <Delete typeName="Calk:Point" xmlns:Calk="http://itsme.calk.ir">
        <Filter xmlns="http://www.opengis.net/ogc">
            <FeatureId fid="Point.24"/>
        </Filter>
    </Delete>
</Transaction>

It doesn't work properly. Geoserver's response is as follow:

<?xml version="1.0" encoding="UTF-8"?>
<wfs:TransactionResponse 
    xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ogc="http://www.opengis.net/ogc" 
    xmlns:Calk="http://itsme.calk.ir" xmlns:wfs="http://www.opengis.net/wfs" 
    xmlns:ows="http://www.opengis.net/ows" xmlns:xlink="http://www.w3.org/1999/xlink" 
    xmlns:gml="http://www.opengis.net/gml" xmlns:opengeo="http://opengeo.org" xmlns:usa="http://census.gov" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.1.0" 
    xsi:schemaLocation="http://www.opengis.net/wfs http://localhost:8080/geoserver/schemas/wfs/1.1.0/wfs.xsd">

    <wfs:TransactionSummary>
        <wfs:totalInserted>1</wfs:totalInserted>
        <wfs:totalUpdated>2</wfs:totalUpdated>
        <wfs:totalDeleted>3</wfs:totalDeleted>
    </wfs:TransactionSummary>
    <wfs:TransactionResults/>
    <wfs:InsertResults>
        <wfs:Feature>
            <ogc:FeatureId fid="new0"/>
        </wfs:Feature>
    </wfs:InsertResults>
</wfs:TransactionResponse>

In this case, it must add a feature with NAME property: asdf(it does not add new feature), and update a feature(It does not update any feature), and delete a feature(It do this correctly). But when I create 3 request and as follow, It doesn't delete the feature some times:

var insertNode = wfs.writeTransaction(InsertFeaturesArr, [], [], opt);
Ext.Ajax.request({
    ...
    xmlData: s.serializeToString(insertNode),
    ...
});

var updateNode = wfs.writeTransaction([], updateFeaturesArr [], opt);
Ext.Ajax.request({
    ...
    xmlData: s.serializeToString(updateNode),
    ...
});

var deleteNode = wfs.writeTransaction([], [], deleteFeaturesArr, opt);
Ext.Ajax.request({
    ...
    xmlData: s.serializeToString(deleteNode),
    ...
});

Where is the problem?
I tested this code with geoserver 2.8 t0o and it does not correctly too.

8
  • What datastore do you have? PostGIS or shapefile?
    – user30184
    Commented Aug 18, 2015 at 12:28
  • It's shapefile. Commented Aug 18, 2015 at 12:31
  • 3
    Shapefile datastores cannot be trusted for WFS-T don't use it.
    – bartvde
    Commented Aug 18, 2015 at 12:47
  • Could you either share it or repeat your tests with the tiger:poi layer? Only proper way to test is to have same set-up than you have, fire the same requests, and look at the logs. But WFS-T with shapefiles may be good for playing but not for production.
    – user30184
    Commented Aug 18, 2015 at 12:48
  • 1
    Does you insert miss typeName? I am not sure if shapefiles has stable feature-IDs so if you originally had IDs 1-25 and you delete ID=24, I don't know if ID=25 exists any more or if it is now ID=24, the last feature in the shapefile. That should be tested. And Geoserver is not good at reporting partial success/failure as you can see from your TransactionSummary. Everything is reported to be right but is not.
    – user30184
    Commented Aug 18, 2015 at 12:58

1 Answer 1

1

Geoserver dose not work properly with shape file datastore. For reliable transaction you must define a postgis datastore.

Your Answer

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

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