Postgis

本文介绍了如何使用PostGIS扩展PostgreSQL的地理空间存储能力,包括安装PostGIS、创建数据库扩展、数据转储、数据组织、操作几何数据、查看数据以及创建索引。还探讨了各种几何数据类型、操作符和应用示例。
摘要由CSDN通过智能技术生成

Postgis

2012年2月29日

2015年6月8日重构

2015年7月4日添加数据组织、数据操作

2015年7月6日添加运算符

1 目标:使用postgis扩展PostgreSQL的空间存储能力

2 方法:安装、使用postgis。

2.1 安装postgis数据库

下载与postgresql对应的postgis安装文件,按照提示进行安装;

postgis-pg91-setup-1.5.3-2.exe

安装完成postgis后,会出现template_postgis模板库和postgis数据库;

2.2 扩展Postgresql

扩展sql文件应该在安装目录下,share/extension文件夹中。

可以通过以下几种方式加入扩展。

参考:http://www.xuebuyuan.com/1655300.html

2.2.1 创建扩展(推荐):CREATE EXTENSION postgis

或者使用PgAdmin,拓展-》添加拓展,添加sql文件名,自动生成sql,点击确定添加扩展。

安装完成后,可以看到扩展中的内容,postgis中导入大量函数。所有函数都可以在此处查看。

函数的定义可以架构-》函数中查看定义,详细说明请参见帮助文件。

2.2.2 加载sql:pgsql -f ../share/extension/postgis.sql

加载postgis,创建相应的空间数据表。

2.2.3 新建一个以template_postgis为模板的数据库

在定义中选择模板,其它的选项根据需要填写;

成功创建后会在数据表中出现geometry_columns(地理数据)和spatial_ref_sys(所有的地理参考系统)两个表;

3 方法:数据转储

目标:将shp格式的矢量数据,存储到postgres中。

3.1 方法:使用命令行工具shp2pgsql

3.1.1 shp2pgsql工具用法

D:\Program Files\PostgreSQL\9.1\bin>shp2pgsql

RCSID: $Id: shp2pgsql-core.h 5983 2010-09-1911:27:05Z mcayland $ RELEASE: 1.5

SE_GEOS=1 USE_PROJ=1 USE_STATS=1

USAGE: shp2pgsql[<options>] <shapefile> [<schema>.]<table>

OPTIONS:

  -s <srid>  Set the SRID field. Defaults to -1.

  (-d|a|c|p) These are mutually exclusiveoptions:

      -d Drops the table, then recreates it and populates

          it with current shape file data.

      -a Appends shape file into current table, must be

          exactly the same table schema.

      -c Creates a new table and populates it, this is the

          default if you do not specify anyoptions.

      -p Prepare mode, only creates the table.

  -g <geocolumn> Specify the name of thegeometry/geography column.

      (mostl

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

弗里曼的小伙伴

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值