postgresql - 使用openlayers将空的多线串保存到postgis中

标签 postgresql openlayers postgis web-feature-service

我正在尝试使用像这样的 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>

遗憾的是,即使指定了布局,我也会遇到同样的错误。

我的问题是:有没有办法将空的二维多线串存储到 postgis 中?

提前感谢您的支持,

G.R.

最佳答案

我试过以下方法:

// 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>

关于postgresql - 使用openlayers将空的多线串保存到postgis中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51154701/

相关文章:

r - 如何将 OSM 多边形数据从 PostGIS 导入到 R?

postgresql - Postgres Postgis 错误 : Library not loaded:/usr/local/lib/libspatialite. 5.dylib

sql - 添加新列作为两行之间的差异

openlayers - 如何使用 OpenLayers 4.6.4 将图标/标记添加到 OSM map

Javascript在匿名函数内为变量赋值

javascript - ol-ext Controller 中的控制栏和功能

区域内点的 Hibernate-Spatial 查询

Postgresql 增量如果存在或创建一个新行

python - 提示 : No function matches the given name and argument types. 您可能需要添加显式类型转换。 TrigramSimilarity Django

postgresql - Postgres Glassfish 池化