PostgreSQL 地图两点之间,经纬度距离计算, PostGIS方式计算, 电子围栏功能实现
PostGIS在对象关系型数据库PostgreSQL上增加了存储管理空间数据的能力,相当于Oracle的spatial部分。PostGIS最大的特点是符合并且实现了OpenGIS的一些规范,是最著名的开源GIS数据库。
PostGIS的版权被纳入到GNU的GPL中,也就是说任何人可以自由得到PostGIS的源码并对其做研究和改进。正是由于这一点,PostGIS得到了迅速的发展,越来越多的爱好者和研究机构参与到PostGIS的应用开发和完善当中。
PostGIS是由Refractions Research
Inc开发的,Refractions是一家GIS和数据库咨询公司,Refraction公司最初是在PostgreSQL的基础上研究空间数据库的实
现,由于PostgreSQL所提供的空间数据类型和功能远远不能满足GIS的需求,研究工作经常陷入到进退维谷的境地,最终的结果往往是耗费了大量的人
力物力,而产品却极其复杂并且性能低下。这些原因直接或间接促成PostGIS项目的实施。
PostGIS介绍 - PostgreSQL空间数据存储扩展 PostGIS
PostGIS在对象关系型数据库PostgreSQL上增加了存储管理空间数据的能力,相当于Oracle的spatial部分。PostGIS最大的特点是符合并且实现了OpenGIS的一些规范,是最著名的开源GIS数据库。
PostGIS的版权被纳入到GNU的GPL中,也就是说任何人可以自由得到PostGIS的源码并对其做研究和改进。正是由于这一点,PostGIS得到了迅速的发展,越来越多的爱好者和研究机构参与到PostGIS的应用开发和完善当中。
PostGIS是由Refractions Research Inc开发的,Refractions是一家GIS和数据库咨询公司,Refraction公司最初是在PostgreSQL的基础上研究空间数据库的实 现,由于PostgreSQL所提供的空间数据类型和功能远远不能满足GIS的需求,研究工作经常陷入到进退维谷的境地,最终的结果往往是耗费了大量的人 力物力,而产品却极其复杂并且性能低下。这些原因直接或间接促成PostGIS项目的实施。
安装插件PostGIS
1、导入repo(导入过程省略)
2、安装pg-10(安装过程省略)
3、检查插件
yum search postgis
# yum search postgis
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
================================================ N/S matched: postgis =================================================
postgis-docs.x86_64 : Extra documentation for PostGIS
postgis-utils.x86_64 : The utils for PostGIS
postgis23_10-client.x86_64 : Client tools and their libraries of PostGIS
postgis23_10-devel.x86_64 : Development headers and libraries for PostGIS
postgis23_10-docs.x86_64 : Extra documentation for PostGIS
postgis23_10-utils.x86_64 : The utils for PostGIS
postgis24_10-client.x86_64 : Client tools and their libraries of PostGIS
postgis24_10-devel.x86_64 : Development headers and libraries for PostGIS
postgis24_10-docs.x86_64 : Extra documentation for PostGIS
postgis24_10-gui.x86_64 : GUI for PostGIS
postgis24_10-utils.x86_64 : The utils for PostGIS
postgis25_10-client.x86_64 : Client tools and their libraries of PostGIS
postgis25_10-devel.x86_64 : Development headers and libraries for PostGIS
postgis25_10-docs.x86_64 : Extra documentation for PostGIS
postgis25_10-gui.x86_64 : GUI for PostGIS
postgis25_10-utils.x86_64 : The utils for PostGIS
postgis25_12-client.x86_64 : Client tools and their libraries of PostGIS
postgis25_12-devel.x86_64 : Development headers and libraries for PostGIS
postgis25_12-docs.x86_64 : Extra documentation for PostGIS
postgis25_12-gui.x86_64 : GUI for PostGIS
postgis25_12-utils.x86_64 : The utils for PostGIS
postgis30_10-client.x86_64 : Client tools and their libraries of PostGIS
postgis30_10-devel.x86_64 : Development headers and libraries for PostGIS
postgis30_10-docs.x86_64 : Extra documentation for PostGIS
postgis30_10-gui.x86_64 : GUI for PostGIS
postgis30_10-utils.x86_64 : The utils for PostGIS
postgis30_12-client.x86_64 : Client tools and their libraries of PostGIS
postgis30_12-devel.x86_64 : Development headers and libraries for PostGIS
postgis30_12-docs.x86_64 : Extra documentation for PostGIS
postgis30_12-gui.x86_64 : GUI for PostGIS
postgis30_12-utils.x86_64 : The utils for PostGIS
SFCGAL.x86_64 : C++ wrapper library around CGAL for PostGIS
pgrouting_10.x86_64 : Routing functionality for PostGIS
pgrouting_12.x86_64 : Routing functionality for PostGIS
postgis.x86_64 : Geographic Information Systems Extensions to PostgreSQL
postgis23_10.x86_64 : Geographic Information Systems Extensions to PostgreSQL
postgis24_10.x86_64 : Geographic Information Systems Extensions to PostgreSQL
postgis25_10.x86_64 : Geographic Information Systems Extensions to PostgreSQL
postgis25_12.x86_64 : Geographic Information Systems Extensions to PostgreSQL
postgis30_10.x86_64 : Geographic Information Systems Extensions to PostgreSQL
postgis30_12.x86_64 : Geographic Information Systems Extensions to PostgreSQL
Name and summary matches only, use "search all" for everything.
4、安装插件
yum install postgis.x86_64 postgis24_10.x86_64 -y --skip-broken
等待插件安装完成即可
在数据库中启用插件
-- 添加空间插件
CREATE EXTENSION postgis;
CREATE EXTENSION postgis_topology;
启用插件之后,public
下会新增一个表spatial_ref_sys
坐标点相关函数使用
坐标系 AddGeometryColumn
POINT数据类型支持
AddGeometryColumn
函数使用 https://postgis.net/docs/AddGeometryColumn.html
Synopsis
text AddGeometryColumn(varchar table_name, varchar column_name, integer srid, varchar type, integer dimension, boolean use_typmod=true);
text AddGeometryColumn(varchar schema_name, varchar table_name, varchar column_name, integer srid, varchar type, integer dimension, boolean use_typmod=true);
text AddGeometryColumn(varchar catalog_name, varchar schema_name, varchar table_name, varchar column_name, integer srid, varchar type, integer dimension, boolean use_typmod=true);
函数测试示例
-- Create schema to hold data
CREATE SCHEMA my_schema;
-- Create a new simple PostgreSQL table
CREATE TABLE my_schema.my_spatial_table (id serial);
-- Describing the table shows a simple table with a single "id" column.
postgis=# \d my_schema.my_spatial_table
Table "my_schema.my_spatial_table"
Column | Type | Modifiers
--------+---------+-------------------------------------------------------------------------
id | integer | not null default nextval('my_schema.my_spatial_table_id_seq'::regclass)
-- Add a spatial column to the table
SELECT AddGeometryColumn ('my_schema','my_spatial_table','geom',4326,'POINT',2);
-- Add a point using the old constraint based behavior
SELECT AddGeometryColumn ('my_schema','my_spatial_table','geom_c',4326,'POINT',