dpxbc88022 2013-05-15 07:20
浏览 51
已采纳

使用列名作为mysql中POINT几何的参数

I am working on a query which fetches all the rows in which lat and longs are inside given polygon. I am using geometry functions to do so. I am able to use contain method with polygon and point, However In my case I am using polygon coordinates explicitly in query and want to use "latitude" and "longitude" column name as parameters of POINT. I tried to use concat method but I am getting a "false" return from contain method.

query:

  SELECT 
    * 
  from table  
  WHERE 
    contains(
       GeomFromText(
         'POLYGON(
            (32.717399 -117.144126,32.714655  -117.136487,32.710827 -117.145843,32.714005 -117.146444, 32.717399 -117.144126))
         '),
       GeomFromText(
         'POINT(
            concate(latitude," ",longitude))
         '))

My table structure is:

property_id                 int(11)
latitude                    decimal(10,6)    
longitude                   decimal(10,6)
Address_f1365               char(100)
AddressOnTheInternet_f27    char(255)
  • 写回答

1条回答 默认 最新

  • douduidui1046 2013-05-15 07:38
    关注

    Try something like this, before using in actual query:

    SELECT asWKT(GeomFromText(CONCAT('POINT(', 15, ' ', 26, ')')));
    

    Shows:

    'POINT(15 26)'
    

    I suggest you to test anything, that would be part of spatial data query with function asWKT() / asText(). Check the manual for supported formats and conversion functions.

    You have wrongly used CONCAT(). Try:

    SELECT 
        * 
    FROM
        `table`
    WHERE 
        CONTAINS(
           GeomFromText('POLYGON((32.717399 -117.144126,32.714655  -117.136487,32.710827 -117.145843,32.714005 -117.146444, 32.717399 -117.144126))')
        ,
           GeomFromText(CONCAT('POINT(', latitude, ' ', longitude, ')'))
        )
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题