简体   繁体   English

在集群数据库上运行PostGIS命令

[英]Running PostGIS Commands on Clustered DB

Using Postgresql in clustered database (stado) on two nodes, I want to test this query: 在两个节点上的集群数据库(stado)中使用Postgresql,我想测试以下查询:

select id,position,timestamp from table t1 WHERE id!=0 AND ST_Intersects ((Select ST_Buffer_Meters(ST_SetSRID(ST_MakePoint(61.4019,15.218205), 4326) ,1160006)),position) AND timestamp Between '2013-10-01' and '2013-12-30';

When I run it in command line or psql (on coordinator), I get this error: 当我在命令行或psql(在协调器上)运行它时,出现此错误:

Encountered ")" at line 1, column 171.

While other sql commands (insert, update, select... etc) are working fine. 当其他SQL命令(插入,更新,选择...等)运行正常时。 also Geometry columns seems okay in the table so i don't think there is a problem with installing PostGIS. 表格中的“几何”列也似乎还可以,所以我认为安装PostGIS不会出现问题。

Generally-speaking, don't buffer a geometry to do a proximity search. 一般来说,不要缓冲几何图形以进行邻近搜索。 With the above attempt, it is for just one point geometry, but in other queries you could be potentially buffering all the geometries of a table, which would make the query expensive since it would need to create new geometries and would not be able to use indexes. 通过上述尝试,它仅适用于一个点几何,但是在其他查询中,您可能正在缓冲表的所有几何,这将使查询变得昂贵,因为它将需要创建新的几何并且无法使用索引。 Use ST_DWithin instead . 改用ST_DWithin

ST_DWithin with geometry types will use the same distance units as the the spatial reference system. 具有geometry类型的ST_DWithin将使用与空间参考系统相同的距离单位。 So for SRID=4326, this is in degrees, which is not helpful in any way. 因此,对于SRID = 4326,以度为单位,这毫无用处。 However, if position is a geography type, ST_DWithin will use distance arguments in meters, which is much more useful. 但是,如果positiongeography类型,则ST_DWithin将使用以米为单位的距离参数,这将更加有用。 So the WHERE filter would look like: 因此WHERE过滤器如下所示:

WHERE id <> 0
  AND ST_DWithin(ST_MakePoint(61.4019, 15.218205)::geography, position, 1160006)
...

This will do a proximity search of positions that are 1160006 m or 1160 km from the queried location (which, by the way is not in Sweden, if that's where you were thinking). 这将对距查询位置1160006 m或1160 km的位置进行邻近搜索(顺便说一句,如果您正在考虑的话,该位置不在瑞典)。 If position is a geometry type, you can either consider changing the type, or do a cast ( position::geography ) or an index of that cast operation. 如果positiongeometry类型,则可以考虑更改类型,或者进行强制转换( position::geography )或该强制转换操作的索引。

I can't find the function ST_Buffer_Meters() in the PostGis manual, only ST_Buffer() 我在ST_Buffer_Meters()手册中找不到函数ST_Buffer_Meters() ,只有ST_Buffer()

Either way, I can't imagine any function would require a subquery as parameter. 无论哪种方式,我都无法想象任何函数都需要子查询作为参数。 Try instead: 请尝试:

SELECT id,position,timestamp
FROM   table t1
WHERE  id <> 0
AND    ST_Intersects(ST_Buffer_Meters(ST_SetSRID(
                     ST_MakePoint(61.4019, 15.218205), 4326), 1160006), position)
AND    timestamp BETWEEN '2013-10-01' AND '2013-12-30';

And don't use timestamp as identifier. 并且不要使用timestamp作为标识符。 It's a base type name and a reserved word in SQL . 它是SQL中的基本类型名称和保留字

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM