【问题标题】:Jooq and postGISJooq 和 postGIS
【发布时间】:2022-02-18 15:48:03
【问题描述】:

我正在尝试让 Jooq 使用 GIS 查询,并在 SO 上找到了一些示例。我对其中一个样本有疑问。我找到了以下构建多边形的函数(How to select points within polygon in PostGIS using jOOQ?)。比如:

public static Field<?> stPolygon(Field<?> geom, int value) {
    return DSL.field("ST_Polygon({0}, {1})", Object.class, geom, DSL.val(value));
}

我试图弄清楚如何使用它从 GIS 坐标中构建一个多边形字段(指定为 [latitude, longitude] 列表的双倍)

之后,如果我想选择某个列(点)位于该多边形内的记录,我该如何创建比较运算符。 field.in 函数能否满足此类需求?

【问题讨论】:

    标签: kotlin postgis jooq


    【解决方案1】:

    您不能使用IN 谓词来检查一个几何体是否“在”另一个几何体。相反,您必须使用空间谓词。例如:

    select st_contains(
      st_makepolygon(st_makeline(array[
        st_point(0, 0), 
        st_point(0, 1), 
        st_point(1, 1), 
        st_point(1, 0), 
        st_point(0, 0)
      ])),
      st_point(0.5, 0.5)
    )
    

    Inspiration taken from this question。如果您有一个包含点的几何形状的表格,您还可以将这些点聚合到一个数组中,如下所示:

    select st_contains(
      st_makepolygon(st_makeline(array_agg(points.point))), 
      st_point(0.5, 0.5)
    )
    from points
    

    从 jOOQ 3.16 开始内置支持

    从 jOOQ 3.16 开始,在 jOOQ 的商业版中内置了 GIS 支持。手册中可以看到一些原生支持的功能:

    【讨论】:

      猜你喜欢
      • 2019-09-20
      • 2016-11-17
      • 2011-05-27
      • 2011-01-24
      • 2015-12-17
      • 2012-09-17
      • 2019-03-26
      • 1970-01-01
      • 2021-12-12
      相关资源
      最近更新 更多