【问题标题】:Java - How to store gml data to postgres database (with postgis)Java - 如何将 gml 数据存储到 postgres 数据库(使用 postgis)
【发布时间】:2021-05-05 00:58:15
【问题描述】:

我想存储在我的数据库中:

示例数据:

ST_GeomFromGML('
        <gml:LineString srsName="EPSG:4269">
            <gml:coordinates>
                -71.16028,42.258729 -71.160837,42.259112 -71.161143,42.25932
            </gml:coordinates>
        </gml:LineString>');

我在条目中创建了一个带有 2 个参数的 API(字符串 id 和几何形状):

{
  "id": "string",
  "shape": {
    "envelope": {},
    "factory": {
      "coordinateSequenceFactory": {},
      "precisionModel": {
        "scale": 0
      }
    },
    "srid": 0,
    "userData": {}
  }
}

我的模特:

Entity
@Table(name = "test", schema = "aaa")
public class rectangle {

    @Id
    @Column(name = "id", length = 32)
    private String id;

    @Column(name = "shape")
    private Geometry shape;

    public rectangle() {
    }

    public rectangle(String id, Geometry shape) {
        this.id = id;
        this.shape = shape;
    }

如何将我的示例日期解析到我的数据库中?

找到有关 st_GeomFromGml 的文档:

https://postgis.net/docs/ST_GeomFromGML.html

【问题讨论】:

  • 这与游戏制作语言有什么关系?添加标签时请阅读标签说明,并确保它与您的实际意思有关...我删除了gml 标签并将其替换为您可能的意思的gml-geographic-markup-lan

标签: java postgresql geometry postgis gml-geographic-markup-lan


【解决方案1】:

对于这种情况,有一种休眠方言称为 org.hibernate.spatial.dialect.postgis.PostgisDialect

这能够使用 JPA 将几何图形直接加载并存储到带有 PostGis 的 Postgres DB。

http://www.hibernatespatial.org/documentation/02-Tutorial/01-tutorial4/,您可以找到使用它的教程。

【讨论】:

    猜你喜欢
    • 2013-10-24
    • 2012-05-27
    • 1970-01-01
    • 2013-02-09
    • 1970-01-01
    • 2018-08-10
    • 1970-01-01
    • 2013-03-10
    • 2022-01-24
    相关资源
    最近更新 更多