从 MemSQL 中的插入值自动计算 GEOGRAPHY 多边形
Automatically compute GEOGRAPHY polygon from inserted values in MemSQL
在 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_AREA
创建有效表达式=17=].
编辑:
我能够通过 Joseph Victor 提供的提示解决问题。 A 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 returns 是双精度数,而不是 GEOGRAPHY。
尝试
area AS GEOGRAPHY_AREA(CONCAT("POLYGON((",
lon1,
" ",
lon2,
",",
...
")")) PERSISTED DOUBLE
在 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_AREA
创建有效表达式=17=].
编辑:
我能够通过 Joseph Victor 提供的提示解决问题。 A 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 returns 是双精度数,而不是 GEOGRAPHY。
尝试
area AS GEOGRAPHY_AREA(CONCAT("POLYGON((",
lon1,
" ",
lon2,
",",
...
")")) PERSISTED DOUBLE