gpt4 book ai didi

H2 Mem & Geometry Data with Spring Boot 3.2(H2使用Spring Boot 3.2的内存和几何数据)

翻译 作者:bug小助手 更新时间:2023-10-26 22:46:31 30 4
gpt4 key购买 nike



Context

语境


I have a application that uses POINT data for latitude and longitude in my database in Spring Boot 3.2. The production database is MySQL and I can insert the point data with statements like:

我在Spring Boot3.2的数据库中有一个应用程序,它使用点数据来表示纬度和经度。生产数据库是MySQL,我可以用如下语句插入点数据:


ST_PointFromText('POINT(-36.5 174.5)', 4326)

But for developement I am using H2 in-memory database. How can I insert latitude longitude data into the H2 database. I am using Hibernate Geolatte dependency.

但对于开发,我使用的是H2内存数据库。如何将纬度经度数据插入到H2数据库。我正在使用Hibernate Geolatte依赖项。


Build.gradle

Build.gradle


implementation group: 'org.geolatte', name: 'geolatte-geom', version: '1.9.0'
implementation group: 'org.geolatte', name: 'geolatte-geojson', version: '1.9.0'
implementation group: 'org.hibernate.orm', name: 'hibernate-spatial', version: '6.2.6.Final'
implementation group: 'org.orbisgis', name: 'h2gis', version: '2.2.0'
runtimeOnly 'com.h2database:h2'

Entity

实体


import org.geolatte.geom.G2D;
import org.geolatte.geom.Point;

@AllArgsConstructor
@NoArgsConstructor
@ToString
@Entity
@Data
@Table(name = "test_check")
public class TestCheck {

@Id
@GeneratedValue(strategy = IDENTITY)
private Long id;

private Point<G2D> location;

When I try to run the same data.sql that I use for MySQL I am getting errors related to the insertion of the geometry.

当我尝试运行我用于MySQL的相同data.sql时,我得到了与插入几何体相关的错误。


更多回答
优秀答案推荐

The answer is to ensure that you reference the call to load H2GIS_SPATIAL first in data.sql.

答案是确保首先在data.sql中引用调用以加载H2GIS_SPATIAL。


CREATE ALIAS IF NOT EXISTS H2GIS_SPATIAL FOR "org.h2gis.functions.factory.H2GISFunctions.load";
CALL H2GIS_SPATIAL();

Then change from ST_PointFromText('POINT(-36.5 174.5)', 4326) to using the H2 syntax of the same statement ST_SetSRID(ST_MakePoint(-32.5, 174.5), 4326))

然后从ST_PointFromText(‘POINT(-36.5 174.5)’,4326)更改为使用相同语句ST_SetSRID(ST_MakePoint(-32.5,174.5),4326)的H2语法)


H2 seems to store the points in a Text based format instead of binary - perhaps someone know more on why this is.

H2似乎以基于文本的格式而不是二进制格式存储点数--也许有人知道更多关于这一点的原因。


更多回答

H2 has own GEOMETRY data type with binary encoding and H2GIS extension has ST_PointFromText function.

H2有自己的二进制编码的几何数据类型,H2的扩展有ST_PointFromText函数。

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com