在 MySQL 函数调用中使用 Select 语句

发布于 2024-12-01 06:50:39 字数 1435 浏览 2 评论 0原文

在下面的 MySQL 存储函数调用中,我不想手动输入经纬度坐标,而是从另一个表中选择一个多边形进行测试。我在获取正确的语法时遇到问题。

SELECT IS_POINT_IN_POLYGON(
POINTFROMTEXT( CONCAT( 'POINT(', latitude, ' ', longitude, ')' ) ) , POLYFROMTEXT( 'POLYGON((43.40930419213147, -72.5537109375
43.40884544242924, -72.53695249557495
43.38754804789373, -72.5437331199646
43.378580946950244, -72.58398771286011
43.40930419213147, -72.5537109375 ))' )
)AS result, latitude, longitude
FROM sport
WHERE sport_type = 'lacrosse' AND IS_POINT_IN_POLYGON(
POINTFROMTEXT( CONCAT( 'POINT(', latitude, ' ', longitude, ')' ) ) , POLYFROMTEXT( 'POLYGON((43.40930419213147, -72.5537109375
43.40884544242924, -72.53695249557495
43.38754804789373, -72.5437331199646
43.378580946950244, -72.58398771286011
43.40930419213147, -72.5537109375))' )
) = 1;

所以,我想删除 43.40930419213147,-72.5537109375 43.40884544242924,-72.53695249557495 43.38754804789373,-72.5437331199646 43.378580946950244,-72.58398771286011 43.40930419213147, -72.5537109375

相反,我想使用这个选择语句:

SELECT neighborhood_polygon FROM `neighborhood_shapes` WHERE neighborhood="XYZ neighborhood"

我将多边形存储在neighborhood_shapes中。其结构如下:

  • Neighborhood_index Smallint(3)
  • Neighborhood varchar(50)
  • Neighborhood_Polygon(geometry)

附加信息:

IS_POINT_IN_POLYGON 的调用方式如下: IS_POINT_IN_POLYGON(p POINT, poly POLYGON)

有什么建议吗?

In the following MySQL stored function call, instead of having to manually type in the lat long coordinates, I'd like to select a polygon from another table to be tested. I'm having problems getting the syntax right.

SELECT IS_POINT_IN_POLYGON(
POINTFROMTEXT( CONCAT( 'POINT(', latitude, ' ', longitude, ')' ) ) , POLYFROMTEXT( 'POLYGON((43.40930419213147, -72.5537109375
43.40884544242924, -72.53695249557495
43.38754804789373, -72.5437331199646
43.378580946950244, -72.58398771286011
43.40930419213147, -72.5537109375 ))' )
)AS result, latitude, longitude
FROM sport
WHERE sport_type = 'lacrosse' AND IS_POINT_IN_POLYGON(
POINTFROMTEXT( CONCAT( 'POINT(', latitude, ' ', longitude, ')' ) ) , POLYFROMTEXT( 'POLYGON((43.40930419213147, -72.5537109375
43.40884544242924, -72.53695249557495
43.38754804789373, -72.5437331199646
43.378580946950244, -72.58398771286011
43.40930419213147, -72.5537109375))' )
) = 1;

So, I'd like to remove
43.40930419213147, -72.5537109375
43.40884544242924, -72.53695249557495
43.38754804789373, -72.5437331199646
43.378580946950244, -72.58398771286011
43.40930419213147, -72.5537109375

And instead, I'd like to use this select statement:

SELECT neighborhood_polygon FROM `neighborhood_shapes` WHERE neighborhood="XYZ neighborhood"

I have polygons stored in neighborhood_shapes. Its structure is as follows:

  • neighborhood_index smallint(3)
  • neighborhood varchar(50)
  • neighborhood_polygon(geometry)

Additional Info:

The IS_POINT_IN_POLYGON is called as follows: IS_POINT_IN_POLYGON(p POINT, poly POLYGON)

Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

嘿嘿嘿 2024-12-08 06:50:39

尝试这样做。

... POLYFROMTEXT(
    (SELECT neighborhood_polygon 
      FROM neighborhood_shapes 
      Where neighborhood = "XYZ neighborhood") as coords)

Try doing this.

... POLYFROMTEXT(
    (SELECT neighborhood_polygon 
      FROM neighborhood_shapes 
      Where neighborhood = "XYZ neighborhood") as coords)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文