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) 五公里的所有数据

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

  • 相关阅读:
    Java JDK在Mac下的配置方法
    Kubernetes 在知乎上的应用
    kubernetes 简介:kube-dns 和服务发现
    CNI:容器网络接口
    SkyDNS试用
    docker 跨主机网络:overlay 简介
    为什么Kubernetes不使用libnetwork
    libnetwork 源码浅析
    NVMe到底是什么?用它的SSD有啥优势?
    TUNING FOR ALL FLASH DEPLOYMENTS
  • 原文地址:https://www.cnblogs.com/tsxylhs/p/12925061.html
Copyright © 2011-2022 走看看