我正在尝试使用openlayers(版本> = 3)存储“空”功能,例如:
let defaultFeature = new ol.Feature({
geometry: new ol.geom.MultiLineString([]),
});
如您所见,它只是一个空的多行字符串,等待被行填充。
我有一个像这样构建的数据库表:
CREATE TABLE md (
id SERIAL PRIMARY KEY NOT NULL,
name varchar(40) NOT NULL,
geometry geometry(MULTILINESTRING, 3857)
);
然后我将该功能发送到tinyows进行存储(此处为有效负载)
<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>
但是数据库返回错误:
Geometry has Z dimension but column does not
在收到该错误后,我尝试像这样使用参数“ opt_layout”(http://openlayers.org/en/latest/apidoc/module-ol_geom_MultiLineString-MultiLineString.html):
let defaultMdFeature = new ol.Feature({
geometry: new ol.geom.MultiLineString([], 'XY'),
});
和有效载荷:
<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>
可悲的是,即使指定布局,我也会遇到相同的错误。
我的问题是:有没有一种方法可以将空的2d multilinestring存储到postgis中?
预先感谢您的支持,
G.R。
答案 0 :(得分:0)
我尝试了以下操作:
// 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);
console.log(str)
返回以下内容:
<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>
您可能希望尝试这种方式,因为XML LineString
标签包含<posList srsDimension="2"></posList>