zoukankan      html  css  js  c++  java
  • PostgreSQL 添加postgis插件实现获取经纬度间的距离

    概念: geometry和geography的区别

    geometry:planar 平面坐标系【supported by SQL Server conforms to the Open Geospatial Consortium (OGC) Simple Features for SQL Specification version 1.1.0.】
    geography: terrestrial 地理坐标系【stores ellipsoidal (round-earth) data, such as GPS latitude and longitude coordinates.】

    安装 postgresql-12 可postgis 网上查找与postgresql对应版本的postgis

       sudo apt install postgresql-12
       sudo add-apt-repository ppa:ubuntugis/ppa
       sudo apt-get install postgis
       sudo -i -u postgres

    安转完成之后:执行

    sudo -i -u postgres

    进入psql命令行/切换到需要的gis的数据库执行

    CREATE EXTENSION postgis;
    CREATE EXTENSION postgis_topology;

    之后在所需表新建字段

    alter 表名
        add where_is geography;

    将经纬度信息转到geography

    update表名 set where_is=ST_POINT(lat,lng) where 1=1;
    lat 为单独字段,lng为单独字段

    具体查询信息

    select  *, st_distance(t_shop.where_is,ST_POINT(31.23037,121.4737)) as distance   FROM t_shop  where st_distance(t_shop.where_is,ST_POINT(31.23037,121.4737))  < 5000 ORDER BY distance;
    查询距离坐标点(31.23037,121.4737) 五公里的所有数据

    查询出来的数据以米为单位

  • 相关阅读:
    题解报告——垃圾陷阱
    后缀自动机
    计算几何之凸包
    平衡树——treap
    图论--最小费用最大流(MCMF)
    很重要的吐槽!
    图论--网络流初步(最大流,增广路)
    字符串--Trie树(字典树)
    图论--Tarjan求强联通分量
    数据结构--堆
  • 原文地址:https://www.cnblogs.com/tsxylhs/p/12925061.html
Copyright © 2011-2022 走看看