3

Im trying to store an "empty" feature using openlayers (version >= 3) like this one :

let defaultFeature =  new ol.Feature({
    geometry: new ol.geom.MultiLineString([]),
});

As you can see, it's just an empty multilinestring waiting to be filled with lines.

I have a database table built like this :

CREATE TABLE md (
   id SERIAL PRIMARY KEY NOT NULL,
   name varchar(40) NOT NULL,
   geometry geometry(MULTILINESTRING, 3857)
);

then i send the feature to tinyows for storage, (here the payload)

<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>
    <md
        xmlns="http://www.tinyows.org/">
        <geometry>
            <MultiLineString
                xmlns="http://www.opengis.net/gml" srsName="EPSG:3857"/>
            </geometry>
        </md>
    </Insert>
</Transaction>

but the database returns an error :

Geometry has Z dimension but column does not

After getting that error i tried to use the parameter "opt_layout" (http://openlayers.org/en/latest/apidoc/module-ol_geom_MultiLineString-MultiLineString.html) like this :

let defaultMdFeature =  new ol.Feature({
    geometry: new ol.geom.MultiLineString([], 'XY'),
});

and the payload :

<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>
    <md
        xmlns="http://www.tinyows.org/">
        <geometry>
            <MultiLineString
                xmlns="http://www.opengis.net/gml" srsName="EPSG:3857"/>
            </geometry>
        </md>
    </Insert>
</Transaction>

Sadly, i get the same error even by specifying the layout.

My question is : is there a way to store an empty 2d multilinestring into postgis ?

thank you in advance for your support,

G.R.

Jim Jones
  • 9,620
  • 2
  • 21
  • 31
G. Ribeiro
  • 31
  • 1
  • Can you check in the postgresql log files which sql statement is being sent to the db? – Jim Jones Jul 03 '18 at 13:31
  • btw, in case it applies to your geometries, have you tried using `geometry geometry(MULTILINESTRINGZ, 3857)` instead of `geometry geometry(MULTILINESTRING, 3857)`? – Jim Jones Jul 03 '18 at 13:41
  • Hi Jim, i tried the `geometry(MULTILINESTRINGZ, 3857)` too but as im working with 2d linestring, when i tried to update the multilinestring i got another error `2018-07-03 14:38:30.501 CEST [17816] ERREUR: Column has Z dimension but geometry does not` – G. Ribeiro Jul 03 '18 at 13:57
  • i dont know if it can help, i checked the postgresql logs and saw this : `2018-07-03 14:12:25.315 CEST [9372] ERREUR: Geometry has Z dimension but column does not 2018-07-03 14:12:25.315 CEST [9372] INSTRUCTION : INSERT INTO "public"."md" ("id","geometry") VALUES ('1','01050000A0110F000000000000') ` – G. Ribeiro Jul 03 '18 at 13:58
  • Your code is generating a `MULTILINESTRING Z EMPTY`, which does not match with your table structure -> check: `select st_astext('01050000A0110F000000000000') as z,st_astext('010500000000000000') as notz` – Jim Jones Jul 03 '18 at 14:15
  • Try this: `` – Jim Jones Jul 03 '18 at 14:27
  • i tried to send to tinyows this payload ` ` using httprequester and with the `srsDimension="2"` – G. Ribeiro Jul 03 '18 at 14:54
  • And what the log file says this time? – Jim Jones Jul 03 '18 at 14:59
  • im getting again `ERREUR: Geometry has Z dimension but column does not`. Maybe the issue is comming from tinyows? – G. Ribeiro Jul 03 '18 at 14:59
  • log file : `2018-07-03 16:39:24.007 CEST [11456] ERREUR: Geometry has Z dimension but column does not 2018-07-03 16:39:24.007 CEST [11456] INSTRUCTION : INSERT INTO "public"."md" ("id","geometry") VALUES ('1','01050000A0110F000000000000') ` still trying to insert a multilinestring z – G. Ribeiro Jul 03 '18 at 15:00
  • That's weird. The parameter `srsDimension="2"` explicitly states that the geometry has only 2 dimensions. The problem might be somewhere else. Unfortunately I am not familiar with tinyows. – Jim Jones Jul 03 '18 at 15:09
  • Example: ``. The only thing that differs to your XML is the fact that this one uses a namespace `gml:` and you don't – Jim Jones Jul 03 '18 at 15:12
  • thank you a lot for your help, if i ever find the solution i'll post it here. – G. Ribeiro Jul 03 '18 at 15:12
  • alright then. good luck :) – Jim Jones Jul 03 '18 at 15:14

1 Answers1

0

I've tried the following:

// MultiLineString takes an array of array (or the constructor does not receive a valid input)
var defaultMdFeature =  new ol.Feature({
  geometry: new ol.geom.MultiLineString([[]]),
});

var wfs = new ol.format.WFS();

var transaction = wfs.writeTransaction([defaultMdFeature], null, null, {
  featureNS: 'http://www.tinyows.org/',
  featureType: 'md',
  hasZ: false,  // To be sure there are only 2 dimensions
  gmlOptions: {
    srsName: 'EPSG:3857'
  }
})

var s = new XMLSerializer();
var str = s.serializeToString(transaction);

console.log(str);

The console.log(str) returns the following:

<Transaction
    xmlns="http://www.opengis.net/wfs" service="WFS" version="1.1.0" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <Insert>
        <md
            xmlns="http://www.tinyows.org/">
            <geometry>
                <MultiLineString
                    xmlns="http://www.opengis.net/gml" srsName="EPSG:3857">
                    <lineStringMember>
                        <LineString srsName="EPSG:3857">
                            <posList srsDimension="2"></posList>
                        </LineString>
                    </lineStringMember>
                </MultiLineString>
            </geometry>
        </md>
    </Insert>
</Transaction>

You may want to try this way of doing as you can see that XML differs as LineString tag contains<posList srsDimension="2"></posList>

Thomas Gratier
  • 2,163
  • 1
  • 13
  • 15