前言
PostGIS是PostgreSQL数据库中处理GIS数据的空间数据库扩展,提供大量的空间图形处理和分析函数。很多初学者肯定是安装Linux单机版做做研究学习,而企业级服务器一般会选择Linux环境,所以本文以简短的图文结合,阐述在两种典型环境中快速搭建PostGIS服务。当然本人文采有限,"文字不够图来凑",尽量使小白都能看懂。
一 Windows环境
1.1 安装PostgreSQL
在PostgreSQL官网下载页,选择windows版本的下载。

图1-1 PostgreSQL下载页面
下载完成后,直接双击安装.exe文件,执行安装:

图1-2 安装首页

图1-3 安装目录

图1-4 安装组件

图1-5 设置数据目录

图1-6 设置数据库密码

图1-7 设置数据库端口

图1-8 高级设置
然后直接next直到安装结束。
1.2 安装PostGIS
介质获取方式:
-
图1-9 选择对应版本
PostGIS版本应该与当前的操作系统和安装的PostgreSQL版本对应,比如上文我们在Win上安装的PostgreSQL10版本,这里我们就选择针对PostgreSQL10的PostGIS版本。 -
Stack Builder下载
安装完成PG后,会自动有个Stack Builder的工具,用于下载一些PG基础的插件。
图1-10 Stack Builder位置

图1-11 打开Stack Builder

图1-12 下载PostGIS
等待介质下载完毕。
无论从哪种形式获取安装介质后,下载完成后,双击PostGIS的exe进行安装。

图1-13 PostGIS安装首页
安装组件的时候,不需要勾选创建空间数据库,这没什么用,我们会自己创建数据库,通过创建扩展形式建立,下文会给出示例。

图1-14 选择组件
PostGIS安装目录选择安装到PostgreSQL的安装目录中。

图1-14 安装目录
然后next安装,弹出对话框都选是即可。
1.3 验证安装
PostgreSQL安装后会自带一个PgAdmin4的客户端,使用该客户端即可操作数据库,另一种方式是psql的命令行客户端。PgAdmin4是图形界面操作,各位读者可以自己捣鼓捣鼓怎么使用这个工具,执行ACID的sql操作。为了简化说明,本文以psql来说明,打开cmd,输入以下命令:
$ psql -U postgres
psql (10.3)
Type "help" for help.
postgres=# create database test;
CREATE DATABASE
postgres=# \c test
You are now connected to database "test" as user "postgres".
test=# create extension postgis;
CREATE EXTENSION

图1-15 验证.png