Spatial SQL:最适合正方形的数据类型?

发布于 2024-08-02 11:22:08 字数 315 浏览 5 评论 0原文

我有一个支持空间的数据库(在本例中为 DB2)。我需要在表中存储大量方块。哪种标准空间 SQL 数据类型最合适?

我想我可以使用 ST_polygon,但也许有一种更专门的类型,可以提供

  • 更好的性能
  • 和更好的数据保证(如果有人存储非平方值,我想将其捕获为错误)在特定的列中)

我试图找到 ST_rectangleST_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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

筱武穆 2024-08-09 11:22:08

即使您的数据表示矩形或正方形,您仍然需要使用 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.

哑剧 2024-08-09 11:22:08

在 DB2 中它也是一个多边形。看起来您正在存储网格,因此快速检查可能是如果 ST_ENVELOPE(geometry) == Geometry 那么您有一个正方形

此代码来自

DB2 文档

SET CURRENT PATH = CURRENT PATH, db2gse;
CREATE TABLE sample_geoms (id INTEGER, geometry ST_Geometry);

INSERT INTO sample_geoms VALUES
(1, ST_Geometry(ST_Point('point EMPTY',0)));

INSERT INTO sample_geoms VALUES
(2, ST_Geometry(ST_Point('point zm (10 10 16 30)' ,0)));

INSERT INTO sample_geoms VALUES
(3, ST_Geometry(ST_Multipoint('multipoint m (10 10 5, 50 10 6, 
         10 30 8)' ,0)));

INSERT INTO sample_geoms VALUES
(4, ST_Geometry(ST_Linestring('linestring (10 10, 20 10)',0)));

INSERT INTO sample_geoms VALUES
(5, ST_Geometry(ST_Polygon('polygon((40 120, 90 120, 90 150, 
         40 150, 40 120))',0)));


SELECT id, CAST(ST_AsText(ST_Envelope(geometry)) as VARCHAR(160))  Envelope
FROM sample_geoms;

结果:

ID          ENVELOPE
----------- ---------------------------------------------------------------
      1     -

      2     POLYGON (( 9 9, 11 9, 11 11, 9 11, 9 9))

      3     POLYGON (( 10 10, 50 10, 50 30, 10 30, 10 10))

      4     POLYGON (( 10 9, 20 9, 20  11, 10 11, 10 9))

      5     POLYGON (( 40 120, 90 120, 90 150, 40 150, 40 120))

看到 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

SET CURRENT PATH = CURRENT PATH, db2gse;
CREATE TABLE sample_geoms (id INTEGER, geometry ST_Geometry);

INSERT INTO sample_geoms VALUES
(1, ST_Geometry(ST_Point('point EMPTY',0)));

INSERT INTO sample_geoms VALUES
(2, ST_Geometry(ST_Point('point zm (10 10 16 30)' ,0)));

INSERT INTO sample_geoms VALUES
(3, ST_Geometry(ST_Multipoint('multipoint m (10 10 5, 50 10 6, 
         10 30 8)' ,0)));

INSERT INTO sample_geoms VALUES
(4, ST_Geometry(ST_Linestring('linestring (10 10, 20 10)',0)));

INSERT INTO sample_geoms VALUES
(5, ST_Geometry(ST_Polygon('polygon((40 120, 90 120, 90 150, 
         40 150, 40 120))',0)));


SELECT id, CAST(ST_AsText(ST_Envelope(geometry)) as VARCHAR(160))  Envelope
FROM sample_geoms;

Results:

ID          ENVELOPE
----------- ---------------------------------------------------------------
      1     -

      2     POLYGON (( 9 9, 11 9, 11 11, 9 11, 9 9))

      3     POLYGON (( 10 10, 50 10, 50 30, 10 30, 10 10))

      4     POLYGON (( 10 9, 20 9, 20  11, 10 11, 10 9))

      5     POLYGON (( 40 120, 90 120, 90 150, 40 150, 40 120))

See ID = 5? the last POLYGON == ST_ENVELOPE(geometry)

妖妓 2024-08-09 11:22:08

您可能正在寻找 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文