gpt4 book ai didi

geospatial - 根据 MemSQL 中插入的值自动计算 GEOGRAPHY 多边形

转载 作者:行者123 更新时间:2023-12-02 20:24:39 28 4
gpt4 key购买 nike

在 MemSQL 中,我可以轻松地根据插入的值自动计算 GEOGRAPHYPOINT:

CREATE TABLE point_test (
id INTEGER NOT NULL,
lon DECIMAL,
lat DECIMAL,
point AS GEOGRAPHY_POINT(lon, lat) PERSISTED GEOGRAPHYPOINT,
PRIMARY KEY (id)
);

如何对 GEOGRAPHY 多边形执行相同操作?我尝试过几种变体,例如

CREATE TABLE area_test (
id INTEGER NOT NULL,
lon1 DECIMAL,
lon2 DECIMAL,
lat1 DECIMAL,
lat2 DECIMAL,
area AS GEOGRAPHY_AREA("POLYGON((lon1 lat1, lon1 lat2, lon2 lat2, lon2 lat1, lon1 lat1))") PERSISTED GEOGRAPHY,
PRIMARY KEY (id)
);

但无济于事。我可以看到多边形中的字段在插入期间不会扩展,因此导致 NULL 区域,但我似乎无法为 GEOGRAPHY_AREA 创建有效的表达式与 GEOGRAPHY_POINT 的方式相同。

编辑:我能够根据约瑟夫·维克多提供的提示解决这个问题。 GEOGRAPHY 可以在插入时有效地计算,如下所示:

CREATE TABLE area_test (
id INTEGER NOT NULL,
lon1 DECIMAL,
lon2 DECIMAL,
lat1 DECIMAL,
lat2 DECIMAL,
area AS CONCAT("POLYGON((", lon1," ",lat1,",",lon1," ",lat2,",",lon2," ",lat2,",",lon2," ",lat1,",",lon1," ",lat1,"))") PERSISTED GEOGRAPHY,
PRIMARY KEY (id)
);

最佳答案

所以,这很糟糕,但是 lat1 的东西在一个字符串中。另外,GEOAGRAPHY_AREA 返回 double 值,而不是 GEOGRAPHY。尝试一下

area AS GEOGRAPHY_AREA(CONCAT("POLYGON((",
lon1,
" ",
lon2,
",",
...
")")) PERSISTED DOUBLE

关于geospatial - 根据 MemSQL 中插入的值自动计算 GEOGRAPHY 多边形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33980283/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com