我可以在postgis中的同一空间索引列中存储圆形和多边形吗? [英] Can I store circle and polygon within the same spatially indexed column in postgis?

查看:329
本文介绍了我可以在postgis中的同一空间索引列中存储圆形和多边形吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据其文档,空间对象可以是以下

According to their documentation the spatial objects can be of the following

POINT(0 0)

LINESTRING(0 0,1 1,1 2)

POLYGON((0 0,4 0,4 4,0 4,0 0),(1 1, 2 1, 2 2, 1 2,1 1))

MULTIPOINT(0 0,1 2)

MULTILINESTRING((0 0,1 1,1 2),(2 3,3 2,5 4))

MULTIPOLYGON(((0 0,4 0,4 4,0 4,0 0),(1 1,2 1,2 2,1 2,1 1)), ((-1 -1,-1 -2,-2 -2,-2 -1,-1 -1)))

GEOMETRYCOLLECTION(POINT(2 3),LINESTRING(2 3,3 4))

但是,没有圆形类型,我只能在其中存储一个点及其半径.并且具有相同的功能,当我查询点中是否存在该点时,可以得到该圆的边界框.

However , there is no circle type, where I can just store a point and its radius. And have the same feature where I can get a bounding box for that circle when do I query if the point exist within it.

推荐答案

与SQL Server的圆弧.如评论中所指出的,您可以使用 ST_Buffer 的第二种形式近似圆. ST_Buffer(point, distance, num_seg_quarter_circle).当您增加第3个参数时,您会更接近实际的圆,以增加计算时间和存储空间为代价. 从运行中可以看出,缓冲点的返回类型将是多边形,例如:

There is no Postgis type for representing a circle with 100% accuracy, ie, with a centre point and a radius, as there is with SQL Server's circular arcs. As pointed out in the comments, you can approximate a circle with the 2nd form of ST_Buffer, ie, ST_Buffer(point, distance, num_seg_quarter_circle). As you increase the 3rd parameter, you get closer to an actual circle, at the cost of greater calculation times and storage space. The return type of buffering a point will be a Polygon, as can be seen from running, something like:

SELECT ST_GeometryType(ST_Buffer(ST_MakePoint(0,0),100));

我的个人观点是,虽然允许使用圆弧类型可以提高涉及圆的计算精度,但同时也使事情变得复杂,因为您不再处理完全由点,线串和多边形组成的几何对象(后两个,也由点组成.

My personal view is that while allowing for an arc type may improve the precision of calculations involving circles, it also complicates things, as you are no longer dealing with geometric objects composed entirely of points, linestrings and polygons (the latter two, being also composed of points).

您始终可以运行测试以增加ST_Buffer的第3个参数,直到获得可接受的结果为止,但是鉴于空间固有的其他误差,例如大地水准面近似地球,我认为由近似值引起的问题像这样的地理围栏是很少见的.如果您运行,

You can always run tests increasing the 3rd parameter of ST_Buffer, until you get a result that is acceptable, but given other inaccuracies inherent in spatial, such as the earth being approximated by a geoid, I would think that issues caused by approximating a geofence like this would be rare. If you run,

SELECT ST_Area(ST_Buffer(ST_MakePoint(0, 0), 1, num_segments));

对于num_seg_quarter_circle的不同值并与PI进行比较,您可以了解到您离真实圆有多近.

for different values of num_seg_quarter_circle and compare to PI, you can get an idea how close you are to a true circle.

这篇关于我可以在postgis中的同一空间索引列中存储圆形和多边形吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆