数据库
首页 > 数据库> > mysql-ST_Area()用于纬度和经度

mysql-ST_Area()用于纬度和经度

作者:互联网

我有一个包含MariaDB中多个坐标的多边形:

POLYGON((50.4668 -6.90665,51.73607 0.14657,55.3032 -4.52724,50.4668 -6.90665))

我想像这样用MariaDB计算该多边形的面积:

SELECT ST_Area(ST_GeomFromText('POLYGON((50.4668 -6.90665,51.73607 0.14657,55.3032 -4.52724,50.4668 -6.90665))'))

上面的查询结果是15.546039738650009,这是错误的.我使用this工具计算了多边形的面积,得出119116192747.1.

如何使mariaDB理解此多边形包含经度和纬度以正确计算面积?

解决方法:

根据MariaDB文件,它不提供此功能:

In MariaDB, the SRID value is just an integer associated with the geometry value. All calculations are done assuming Euclidean (planar) geometry.

但是,在Mysql 8.0.13中提供了此功能,您可以使用ST_Area()计算多边形面积:

Incompatible Change: Previously, ST_Area() supported only geometry arguments having a Cartesian spatial reference system (SRS) and produced an error when invoked with geometry arguments that specified a geographic SRS. ST_Area() now supports geometry arguments having a geographic SRS and returns the geodetic area in square meters.

因此,如果您将数据库更改为MYSQL> 8.0.13您可以使用以下查询计算多边形面积:

SELECT ST_Area(ST_PolyFromText('POLYGON((50.4668 -6.90665,51.73607 0.14657,55.3032 -4.52724,50.4668 -6.90665))', 4326));

标签:geometry,mariadb,coordinates,spatial-query,mysql
来源: https://codeday.me/bug/20191211/2106079.html