gpt4 book ai didi

MySQL 地理空间函数来识别矩形是否在非均匀的四边形多边形中有点,反之亦然

转载 作者:行者123 更新时间:2023-11-29 02:58:33 26 4
gpt4 key购买 nike

输入:有两个输入,都画在地球表面

  • 输入 1:矩形,具有左上角坐标和右下角坐标。这些坐标以纬度、经度对定义。
  • 输入 2:一个四边形(严格来说不是矩形的形状),具有左上角、右上角、左下角和右下角坐标。这些坐标以纬度、经度对定义。每个值的数据类型为十进制,数据存储在 mySQL 表中。

如何使用 MySQL 地理空间函数确定矩形内的任何点是否位于多边形内,反之亦然?

请在 http://i.stack.imgur.com/KDju4.jpg 查看图示

最佳答案

select * from( (SELECT * FROM table WHERE ST_Intersects(geomfromtext( 'POLYGON((
$rectanglePoint1X $rectanglePoint1Y, $rectanglePoint2X $rectanglePoint2Y,$rectanglePoint3X
$rectanglePoint3Y,$rectanglePoint4X $rectanglePoint4Y,$rectanglePoint1X $rectanglePoint1Y))') , geomfromtext( 'POLYGON((
$polygonPoint1X $polygonPoint1Y, $polygonPoint2X $polygonPoint2Y,$polygonPoint3X
$polygonPoint3Y,$polygonPoint4X $polygonPoint4Y,$polygonPoint1X $polygonPoint1Y))')))
union(SELECT * FROM usgs_data_repo WHERE ST_Contains(geomfromtext( 'POLYGON((
$rectanglePoint1X $rectanglePoint1Y, $rectanglePoint2X $rectanglePoint2Y,$rectanglePoint3X
$rectanglePoint3Y,$rectanglePoint4X $rectanglePoint4Y,$rectanglePoint1X $rectanglePoint1Y))') , geomfromtext( 'POLYGON((
$polygonPoint1X $polygonPoint1Y, $polygonPoint2X $polygonPoint2Y,$polygonPoint3X
$polygonPoint3Y,$polygonPoint4X $polygonPoint4Y,$polygonPoint1X $polygonPoint1Y))')))
union(SELECT * FROM usgs_data_repo WHERE ST_Contains(geomfromtext( 'POLYGON((
$polygonPoint1X $polygonPoint1Y, $polygonPoint2X $polygonPoint2Y,$polygonPoint3X
$polygonPoint3Y,$polygonPoint4X $polygonPoint4Y,$polygonPoint1X $polygonPoint1Y))'),geomfromtext( 'POLYGON((
$rectanglePoint1X $rectanglePoint1Y, $rectanglePoint2X $rectanglePoint2Y,$rectanglePoint3X
$rectanglePoint3Y,$rectanglePoint4X $rectanglePoint4Y,$rectanglePoint1X $rectanglePoint1Y))') )))

where { $rectanglePoint1X $rectanglePoint1Y, $rectanglePoint2X $rectanglePoint2Y,$rectanglePoint3X $rectanglePoint3Y,$rectanglePoint4X $rectanglePoint4Y} are the co-ordinates of the rectangle(Input 1)

and {$polygonPoint1X $polygonPoint1Y, $polygonPoint2X $polygonPoint2Y,$polygonPoint3X $polygonPoint3Y,$polygonPoint4X $polygonPoint4Y} are the co-ordinates of the polygon(Input 2)

Note that the above code will work in the case of any polygon instead of a rectangle as Input1

关于MySQL 地理空间函数来识别矩形是否在非均匀的四边形多边形中有点,反之亦然,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27417440/

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