开发者

Using Select Statement in MySQL Function Call

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, ')' ) ) , POLYFR开发者_C百科OMTEXT( '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?


Try doing this.

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜