pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

  • <i id='E7ACZ'><tr id='E7ACZ'><dt id='E7ACZ'><q id='E7ACZ'><span id='E7ACZ'><b id='E7ACZ'><form id='E7ACZ'><ins id='E7ACZ'></ins><ul id='E7ACZ'></ul><sub id='E7ACZ'></sub></form><legend id='E7ACZ'></legend><bdo id='E7ACZ'><pre id='E7ACZ'><center id='E7ACZ'></center></pre></bdo></b><th id='E7ACZ'></th></span></q></dt></tr></i><div class="sfj3mhr" id='E7ACZ'><tfoot id='E7ACZ'></tfoot><dl id='E7ACZ'><fieldset id='E7ACZ'></fieldset></dl></div>
    • <bdo id='E7ACZ'></bdo><ul id='E7ACZ'></ul>
    <tfoot id='E7ACZ'></tfoot>
  • <legend id='E7ACZ'><style id='E7ACZ'><dir id='E7ACZ'><q id='E7ACZ'></q></dir></style></legend>

      1. <small id='E7ACZ'></small><noframes id='E7ACZ'>

        用 SQLite 計算大圓距離

        Calculating Great-Circle Distance with SQLite(用 SQLite 計算大圓距離)
          1. <legend id='Keq8T'><style id='Keq8T'><dir id='Keq8T'><q id='Keq8T'></q></dir></style></legend>

              <i id='Keq8T'><tr id='Keq8T'><dt id='Keq8T'><q id='Keq8T'><span id='Keq8T'><b id='Keq8T'><form id='Keq8T'><ins id='Keq8T'></ins><ul id='Keq8T'></ul><sub id='Keq8T'></sub></form><legend id='Keq8T'></legend><bdo id='Keq8T'><pre id='Keq8T'><center id='Keq8T'></center></pre></bdo></b><th id='Keq8T'></th></span></q></dt></tr></i><div class="yjrgftw" id='Keq8T'><tfoot id='Keq8T'></tfoot><dl id='Keq8T'><fieldset id='Keq8T'></fieldset></dl></div>
            • <small id='Keq8T'></small><noframes id='Keq8T'>

                <tbody id='Keq8T'></tbody>

                • <bdo id='Keq8T'></bdo><ul id='Keq8T'></ul>
                  <tfoot id='Keq8T'></tfoot>

                • 本文介紹了用 SQLite 計算大圓距離的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  這是我的問題,我有一個包含位置和緯度/經度的 SQLite 表.基本上我需要:

                  Here is my problem, I have a SQLite table with locations and latitudes / longitudes. Basically I need to:

                  SELECT location, HAVERSINE(lat, lon) AS distance FROM location ORDER BY distance ASC;
                  

                  HAVERSINE() 是一個 PHP 函數,它應該返回 大圓距離(以英里或公里為單位)給定一對緯度和經度值.其中一對應由 PHP 提供,另一對應由 locations 表中的每個緯度/經度行提供.

                  HAVERSINE() is a PHP function that should return the Great-Circle Distance (in miles or km) given a pair of latitude and longitude values. One of these pairs should be provided by PHP and the other pair should be provided by each latitude / longitude row available in the locations table.

                  因為 SQLite 沒有任何地理空間擴展 (AFAIK SpatiaLite 存在,但仍然......) 我猜最好的方法是將自定義函數與 PDO 方法之一一起使用:

                  Since SQLite doesn't has any Geo Spatial extension (AFAIK SpatiaLite exists but still...) I'm guessing the best approach would be to use a custom function with either one of the PDO methods:

                  • PDO::sqliteCreateFunction()
                  • PDO::sqliteCreateAggregate()

                  我認為對于這種情況 PDO::sqliteCreateFunction() 就足夠了,但是我對這個函數的有限經驗可以簡化為類似于 PHP 手冊中提供的用例:

                  I think for this case PDO::sqliteCreateFunction() would be enough, however my limited experience with this function can be reduced to usage cases similar to the one provided in the PHP Manual:

                  $db = new PDO('sqlite:geo.db');
                  
                  function md5_and_reverse($string) { return strrev(md5($string)); }
                  
                  $db->sqliteCreateFunction('md5rev', 'md5_and_reverse', 1);
                  $rows = $db->query('SELECT md5rev(filename) FROM files')->fetchAll();
                  

                  我在弄清楚如何讓 SQLite 用戶定義函數同時處理來自 PHP 和表數據的數據時遇到了一些麻煩,如果有人能幫我解決這個問題,我將不勝感激問題,同時也更好地理解 SQLite UDF(SQLite IMO 的一大勝利).

                  I'm having some trouble figuring out how can I get an SQLite user defined function to process data from PHP and table data at the same time and I would appreciate if someone could help me solve this problem while also understanding SQLite UDFs (a big win of SQLite IMO) a little bit better.

                  提前致謝!

                  推薦答案

                  來自您的有趣鏈接".

                  function sqlite3_distance_func($lat1,$lon1,$lat2,$lon2) {
                      // convert lat1 and lat2 into radians now, to avoid doing it twice below
                      $lat1rad = deg2rad($lat1);
                      $lat2rad = deg2rad($lat2);
                      // apply the spherical law of cosines to our latitudes and longitudes, and set the result appropriately
                      // 6378.1 is the approximate radius of the earth in kilometres
                      return acos( sin($lat1rad) * sin($lat2rad) + cos($lat1rad) * cos($lat2rad) * cos( deg2rad($lon2) - deg2rad($lon1) ) ) * 6378.1;
                  }
                  
                  $db->sqliteCreateFunction('DISTANCE', 'sqlite3_distance_func', 4);
                  

                  然后進行查詢:

                  "SELECT * FROM location ORDER BY distance(latitude,longitude,{$lat},{$lon}) LIMIT 1"
                  

                  <小時>

                  編輯(按 QOP):我終于再次需要這個,這個解決方案效果很好,我只是稍微修改了代碼,讓它不那么冗長,并且可以處理非數字值優雅地,這里是:


                  EDIT (by QOP): I finally needed this again and this solution worked out great, I just ended up modifying the code a bit to it is a bit less verbose and handles non-numeric values gracefully, here it is:

                  $db->sqliteCreateFunction('distance', function () {
                      if (count($geo = array_map('deg2rad', array_filter(func_get_args(), 'is_numeric'))) == 4) {
                          return round(acos(sin($geo[0]) * sin($geo[2]) + cos($geo[0]) * cos($geo[2]) * cos($geo[1] - $geo[3])) * 6378.14, 3);
                      }
                  
                      return null;
                  }, 4);
                  

                  這篇關于用 SQLite 計算大圓距離的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死鎖異常代碼?)
                  PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滾動游標不起作用)
                  PHP PDO ODBC connection(PHP PDO ODBC 連接)
                  Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔術方法)
                  php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個值;等于變量的值)
                  MSSQL PDO could not find driver(MSSQL PDO 找不到驅動程序)

                    <small id='iQSVk'></small><noframes id='iQSVk'>

                    • <bdo id='iQSVk'></bdo><ul id='iQSVk'></ul>
                      <tfoot id='iQSVk'></tfoot>
                        <tbody id='iQSVk'></tbody>
                          <legend id='iQSVk'><style id='iQSVk'><dir id='iQSVk'><q id='iQSVk'></q></dir></style></legend>
                          <i id='iQSVk'><tr id='iQSVk'><dt id='iQSVk'><q id='iQSVk'><span id='iQSVk'><b id='iQSVk'><form id='iQSVk'><ins id='iQSVk'></ins><ul id='iQSVk'></ul><sub id='iQSVk'></sub></form><legend id='iQSVk'></legend><bdo id='iQSVk'><pre id='iQSVk'><center id='iQSVk'></center></pre></bdo></b><th id='iQSVk'></th></span></q></dt></tr></i><div class="jskhlvp" id='iQSVk'><tfoot id='iQSVk'></tfoot><dl id='iQSVk'><fieldset id='iQSVk'></fieldset></dl></div>
                            主站蜘蛛池模板: 广州二手电缆线回收,旧电缆回收,广州铜线回收-广东益福电缆线回收公司 | 营养师网,营养师考试时间,报名入口—网站首页 | 隆众资讯-首页_大宗商品资讯_价格走势_市场行情| 企典软件一站式企业管理平台,可私有、本地化部署!在线CRM客户关系管理系统|移动办公OA管理系统|HR人事管理系统|人力 | 即用型透析袋,透析袋夹子,药敏纸片,L型涂布棒-上海桥星贸易有限公司 | 盐城网络公司_盐城网站优化_盐城网站建设_盐城市启晨网络科技有限公司 | 带锯机|木工带锯机圆木推台锯|跑车带锯机|河北茂业机械制造有限公司| | 重庆小面培训_重庆小面技术培训学习班哪家好【终身免费复学】 | 利浦顿蒸汽发生器厂家-电蒸汽发生器/燃气蒸汽发生器_湖北利浦顿热能科技有限公司官网 | LED太阳能中国结|发光红灯笼|灯杆造型灯|节日灯|太阳能灯笼|LED路灯杆装饰造型灯-北京中海轩光电 | 3A别墅漆/3A环保漆_广东美涂士建材股份有限公司【官网】 | 焊管生产线_焊管机组_轧辊模具_焊管设备_焊管设备厂家_石家庄翔昱机械 | 纸布|钩编布|钩针布|纸草布-莱州佳源工艺纸布厂| 电地暖-电采暖-发热膜-石墨烯电热膜品牌加盟-暖季地暖厂家 | 充气膜专家-气膜馆-PTFE膜结构-ETFE膜结构-商业街膜结构-奥克金鼎 | 闸阀_截止阀_止回阀「生产厂家」-上海卡比阀门有限公司 | 建大仁科-温湿度变送器|温湿度传感器|温湿度记录仪_厂家_价格-山东仁科 | 3d打印服务,3d打印汽车,三维扫描,硅胶复模,手板,快速模具,深圳市精速三维打印科技有限公司 | 动库网动库商城-体育用品专卖店:羽毛球,乒乓球拍,网球,户外装备,运动鞋,运动包,运动服饰专卖店-正品运动品网上商城动库商城网 - 动库商城 | 食品质构分析仪-氧化诱导分析仪-瞬态法导热系数仪|热冰百科 | 钢丝绳探伤仪-钢丝绳检测仪-钢丝绳探伤设备-洛阳泰斯特探伤技术有限公司 | 彩信群发_群发彩信软件_视频短信营销平台-达信通 | 水上浮桥-游艇码头-浮动码头-游船码头-码瑞纳游艇码头工程 | 盘式曝气器-微孔曝气器-管式曝气器-曝气盘-斜管填料 | 郑州市前程水处理有限公司 | 小型手持气象站-空气负氧离子监测站-多要素微气象传感器-山东天合环境科技有限公司 | 上海道勤塑化有限公司| 冻干机(冷冻干燥机)_小型|实验型|食品真空冷冻干燥机-松源 | 2025黄道吉日查询、吉时查询、老黄历查询平台- 黄道吉日查询网 | 低温等离子清洗机(双气路进口)-嘉润万丰| 水轮机密封网 | 水轮机密封产品研发生产厂家 | 成都热收缩包装机_袖口式膜包机_高速塑封机价格_全自动封切机器_大型套膜机厂家 | 净化车间_洁净厂房_净化公司_净化厂房_无尘室工程_洁净工程装修|改造|施工-深圳净化公司 | 游戏版号转让_游戏资质出售_游戏公司转让-【八九买卖网】 | GEDORE扭力螺丝刀-GORDON防静电刷-CHEMTRONICS吸锡线-上海卓君电子有限公司 | 聚合氯化铝_喷雾聚氯化铝_聚合氯化铝铁厂家_郑州亿升化工有限公司 | 顶空进样器-吹扫捕集仪-热脱附仪-二次热解吸仪-北京华盛谱信仪器 | 洗石机-移动滚筒式,振动,螺旋,洗矿机-青州冠诚重工机械有限公司 | 模具ERP_模具管理系统_模具mes_模具进度管理_东莞市精纬软件有限公司 | 西安耀程造价培训机构_工程预算实训_广联达实作实操培训 | 头条搜索极速版下载安装免费新版,头条搜索极速版邀请码怎么填写? - 欧远全 | 电竞馆加盟,沈阳网吧加盟费用选择嘉棋电竞_售后服务一体化 |