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

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

  • 相关阅读:
    模板方法设计模式(未完待续)
    适配器模式
    g2o:一种图优化的C++框架
    U14.04 teamviewer install
    小教训
    卡2-SLAM
    Odometry的发布和发布odom到base_link的tf变换
    #pragma once
    友元
    Ubuntu 14.04 安装配置强大的星际译王(stardict)词典
  • 原文地址:https://www.cnblogs.com/tsxylhs/p/12925061.html
Copyright © 2011-2022 走看看