如何解决如何在 kotlin-exposed 中编写 insideOP postgis 扩展?
这是一段代码,让我能够以几何体作为输入运行 postgis &&
private class Withinop(val expr1: Expression<*>,val geom: PGgeometry) : Op<Boolean>() {
override fun toQueryBuilder(queryBuilder: QueryBuilder) {
expr1.toQueryBuilder(queryBuilder)
queryBuilder.args
queryBuilder.append(" && \'${geom.value}\'")
}
查询的样子:
SELECT * FROM table WHERE table."location" && 'SRID=4326;polyGON((1 2,2 2,2 3,1 3,1 2))
现在这成了一个问题,因为 && 是通过 minimum bounding rectangle
搜索的。它对我的目标来说不够准确,所以我想用更准确的 postgis 方法替换它,例如 ST_Intersects
但是当我更新我的构建器时它不起作用,因为暴露错误地构建了这个查询:
private class Withinop(val expr1: Expression<*>,val geom: PGgeometry) : Op<Boolean>() {
override fun toQueryBuilder(queryBuilder: QueryBuilder) {
expr1.toQueryBuilder(queryBuilder)
queryBuilder.args
queryBuilder.append(" ST_Intersects($expr1,\'${geom.value}\'")
查询:SELECT * FROM table WHERE table."location" ST_Intersects(waycare.sql.Table.location,'SRID=4326;polyGON((1 2,1 2))
- 不正确
正确的语法是:SELECT * FROM table WHERE ST_Intersects(table."location",1 2))
如何在公开的情况下构建漂亮的扩展没有很好的文档记录。但我必须找到一些解决办法。任何帮助表示赞赏。
解决方法
我认为您需要在此处使用 CustomFunction。我没有测试下面的代码,但应该足以理解这个想法:
class ST_IntersectsFunction(val expr1: Expression<*>,val geom: String)
: CustomFunction<Boolean>("ST_Intersects",BooleanColumnType(),expr1,stringParam(geom.value))
并使用:
table.select { ST_IntersectsFunction(table.id,geom) eq true }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。