首页 > 解决方案 > 如何在spring-boot中使用pologon postgis查询

问题描述

执行以下查询时出现此异常 我使用 postgis 如何以正确的方式使用 pologon

无法提取结果集;SQL [不适用];嵌套异常是 org.hibernate.exception.SQLGrammarException: could not extract ResultSet

    @Query(name = "getCellIdsForRectangle", value = "SELECT * FROM lk_location as lk "
        + "LEFT JOIN lk_slocation as s "
        + "ON ST_DWithin(POLYGON((-4.43 54.31,-4.39 54.31,-4.39 54.29,-4.43 54.29,-4.43 54.31))\\:\\:GEOMETRY, ST_MakePoint(s.longitude,s.latitude)\\:\\:geometry, s.range) "
        + "WHERE ST_DWithin(POLYGON((-4.43 54.31,-4.39 54.31,-4.39 54.29,-4.43 54.29,-4.43 54.31))\\:\\:GEOMETRY, ST_MakePoint(lk.longitude,lk.latitude)\\:\\:geometry, lk.range) AND s.location_id IS NULL;", nativeQuery = true)
List<Location> getCellIdsForRectangle();

标签: javaspring-bootpostgis

解决方案


您正在从文本构造一个多边形,因此必须引用该多边形

  + "ON ST_DWithin('POLYGON((-4.43 54.31,-4.39 54.31,-4.39 54.29,-4.43 54.29,-4.43 54.31))'\\:\\:GEOMETRY, ST_MakePoint(s.longitude,s.latitude)\\:\\:geometry, s.range) "

推荐阅读