簡體   English   中英

Java - 如何將gml數據存儲到postgres數據庫(使用postgis)

[英]Java - How to store gml data to postgres database (with postgis)

我想存儲在我的數據庫中:

示例數據:

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>');

我制作了一個 API,在條目中有 2 個參數(字符串 id 和幾何形狀):

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

我的 model:

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

對於這種情況,有一個 hibernate 方言稱為 org.hibernate.spatial.dialect.postgis.PostgisDialect

這能夠使用 JPA 直接將幾何圖形加載和存儲到帶有 PostGis 的 Postgres DB。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM