在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
。
修改
我能够用Joseph Victor提供的提示解决问题。可以在插入上有效地计算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)
);
,如下所示:
realpath
答案 0 :(得分:3)
所以,这种情况很糟糕,但是lat1
的东西都在一个字符串中。
此外,GEOAGRAPHY_AREA返回双倍,而不是地理。
试试
area AS GEOGRAPHY_AREA(CONCAT("POLYGON((",
lon1,
" ",
lon2,
",",
...
")")) PERSISTED DOUBLE