= 3) like this one : let defaultFeature = new ol.Feature({ geometry: new ol.geom.Mult" /> = 3) like this one : let defaultFeature = new ol.Feature({ geometry: new ol.geom.Mult" /> = 3) like this one : let defaultFeature = new ol.Feature({ geometry: new ol.geom.Mult"/>

save empty multilinestring into postgis using openlayers

477 Views Asked by At

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.

1

There are 1 best solutions below

0
Thomas Gratier On

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>