Spatial SQL:最适合正方形的数据类型?
我有一个支持空间的数据库(在本例中为 DB2)。我需要在表中存储大量方块。哪种标准空间 SQL 数据类型最合适?
我想我可以使用 ST_polygon,但也许有一种更专门的类型,可以提供
- 更好的性能
- 和更好的数据保证(如果有人存储非平方值,我想将其捕获为错误)在特定的列中)
我试图找到 ST_rectangle 或 ST_square 类型,但它们似乎不存在(?)
当我使用 DB2 时,我还对不适用于 DB2 的解决方案感兴趣,只要它们符合标准即可。
I have a spatially enabled database (DB2, in this case). I need to store a large number of squares in a table. Which standard spatial SQL datatype is most suitable?
I guess I could use an ST_polygon, but maybe there is a more specialized type which would give
- better performance
- better data guarantees (I want to catch it as an error if someone where to store a non-square value in the particular column)
I've tried to find an ST_rectangle or ST_square type, but they don't seem to exist(?)
While I'm working with DB2, I'm also interested in solutions which don't work on DB2, as long as they are standards-compliant.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
即使您的数据表示矩形或正方形,您仍然需要使用 ST_POLYGON 类型。但是,当您对数据执行查询时,可以使用一阶过滤器,例如 ST_EnvIntersects。
通常,空间数据库将比较包络线(即包含多边形的矩形)是否有交集。然后,它执行更昂贵的多边形与多边形相交计算。在这种情况下,由于您的多边形等于包络线,因此您可以跳过第二个更昂贵的步骤。
至于数据验证,您可以添加一个数据库触发器来检查 ST_EQUALS(ST_ENVELOPE(geom),geom) = 1。
Even if your data represents a rectangle or square, you will still need to use the ST_POLYGON type. However, when you perform a query against the data, you can use a first-order filters such as ST_EnvIntersects.
Normally, a spatial database will compare the envelopes (i.e. a rectangle that contains the polygon) for an intersection. Then it performs the more expensive polygon-to-polygon intersection calculation. In this case, since your polygons are equal to the envelope, you can skip the second more expensive step.
As far as data validation, you can add a database trigger that checks ST_EQUALS(ST_ENVELOPE(geom),geom) = 1.
在 DB2 中它也是一个多边形。看起来您正在存储网格,因此快速检查可能是如果 ST_ENVELOPE(geometry) == Geometry 那么您有一个正方形
此代码来自
DB2 文档
结果:
看到 ID = 5 了吗?最后一个 POLYGON == ST_ENVELOPE(几何)
In DB2 it is also a Polygon. It looks like you are storing grids, so a quick check could be that if ST_ENVELOPE(geometry) == geometry then you have a square
This code is from
DB2's documentation
Results:
See ID = 5? the last POLYGON == ST_ENVELOPE(geometry)
您可能正在寻找 ST_Envelope ——我不太确定 DB2,但是它是 OGC 标准的一部分。任何非垂直或非水平线或多边形都将通过此函数生成一个矩形,通常将坐标存储为浮点数。
You may be looking for ST_Envelope -- I don't know for sure about DB2 but it is part of the OGC standard. Any non-vertical or non-horizontal line, or polygon, will generate a rectangle via this function, storing the coordinates typically as floats.