【问题标题】:Invalid endian flag value encountered on Spring Boot Spatial Query on PostGis在 PostGis 上的 Spring Boot 空间查询中遇到无效的字节序标志值
【发布时间】:2021-01-20 04:36:50
【问题描述】:

我正在尝试查询由点定义的圆形区域中的所有property。 我在 Spring Boot 中使用以下功能实现了一个基本的 CRUDRepository,我希望使用该功能从一个点通过区域搜索属性。

@Query(value = "SELECT * FROM property p WHERE ST_DWithin(geography(p.location), geography(:center), :radius)", nativeQuery = true)
 List<Property> searchPropertyByArea(@Param("center") Point center,
                                    @Param("radius") Integer radius);

但我不断收到:错误:遇到无效的字节序标志值。

实体对象:

public class Property {
 @Id
 @GeneratedValue(generator = "UUID")
 @GenericGenerator(name = "UUID", strategy = "org.hibernate.id.UUIDGenerator")
 @Column(name = "id", columnDefinition = "uuid", updatable = false, nullable = false, unique  = true)
 private UUID id;

 @Column(name = "location", nullable = true, columnDefinition = "geometry(POINT,4326)")
 @JsonSerialize(using = PointSerializer.class)
 @JsonDeserialize(using = PointDeserializer.class)
 private Point location;
}

我正在使用的库是:

<dependency>
    <groupId>net.postgis</groupId>
    <artifactId>postgis-jdbc</artifactId>
    <version>2.2.1</version>
 </dependency>
 <dependency>
   <groupId>org.hibernate</groupId>
   <artifactId>hibernate-core</artifactId>
   <version>5.4.4.Final</version>
 </dependency>
 <dependency>
   <groupId>org.hibernate</groupId>
   <artifactId>hibernate-spatial</artifactId>
   <version>5.4.27.Final</version>
 </dependency>

我的application.properties

spring.jpa.database-platform=org.hibernate.spatial.dialect.postgis.PostgisPG95Dialect

【问题讨论】:

    标签: postgresql spring-boot gis postgis


    【解决方案1】:

    该错误消息意味着以 WKB 或 EWKB 格式给出的几何图形的第一个字节既不是 0(大端)也不是 1(小端):

    SELECT geometry('0101000000000000000000F03F0000000000000040');
    
                      geometry                  
    --------------------------------------------
     0101000000000000000000F03F0000000000000040
    (1 row)
    
    SELECT geometry('0401000000000000000000F03F0000000000000040');
    ERROR:  Invalid endian flag value encountered.
    LINE 1: SELECT geometry('0401000000000000000000F03F0000000000000040'...
                            ^
    

    所以p.location:center 以数字开头,但不能以0001 开头。

    【讨论】:

    • 谢谢,center 值不正确。
    猜你喜欢
    • 2017-04-19
    • 1970-01-01
    • 1970-01-01
    • 2020-05-09
    • 2013-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-22
    相关资源
    最近更新 更多