PostgreSQL with PostGIS for mapping coordinates

For location based service, I try to use postgresql with postgis.

You can download postgis from here.

http://postgis.net/source

It is recommended that you need to download and compile yourself since there are many packages dependencies need to be done.

Here is a tutorial which is very handy if you are using ubuntu12.04/mint13 or its derived ones.

=================8X----------------------------------X8============================

http://trac.osgeo.org/postgis/wiki/UsersWikiPostGIS20Ubuntu1204src

How to install PostGIS 2.0 on Ubuntu 12.04 LTS (precise) from source

Prerequisites

Several components are needed, which can either be built from source or installed from pre-built packages, as shown below.

Install prerequisite packages using:

sudo apt-get install build-essential postgresql-9.1 postgresql-server-dev-9.1 libxml2-dev libproj-dev libjson0-dev xsltproc docbook-xsl docbook-mathml

Optional package for raster support (this is required if you want to build the PostgreSQL extensions):

sudo apt-get install libgdal1-dev

Build GEOS 3.3.x

PostGIS 2.0 requires GEOS >= 3.3.2 for topology support, however Ubuntu 12.04 only has GEOS 3.2.2 available in packages, so it needs to be built from source. If you don‘t need topology, you don‘t need to build this component, but it is highly recommended.

There are multiple ways to build GEOS, but this is the simplest:

wget http://download.osgeo.org/geos/geos-3.3.9.tar.bz2
tar xfj geos-3.3.9.tar.bz2
cd geos-3.3.9
./configure
make
sudo make install
cd ..

[NEW ADDED]

Since there will be another package which needs a higher version.

So you need to install    gdal-config ( version 1.8.0+). By default ubuntu 12.04 is of 1.7.3

http://www.gdal.org/

download the source codes and compile as you want.

cd {the_souce_codes_folder}

sudo ./configure --prefix=/usr/local/

sudo make

sudo make install

sudo ldconfig

Then you may compile the postgis package.

Build PostGIS

wget http://download.osgeo.org/postgis/source/postgis-2.0.6.tar.gz
tar xfz postgis-2.0.6.tar.gz
cd postgis-2.0.6

PostGIS 2.0 can be configured to disable topology or raster components, using the configure flags --without-raster and/or --without-topology. The default is to build both. Note that raster is required for the extension installation method for PostgreSQL.

./configure
make
sudo make install
sudo ldconfig
sudo make comments-install

Lastly, enable the command-line tools to work from your shell:

sudo ln -sf /usr/share/postgresql-common/pg_wrapper /usr/local/bin/shp2pgsql
sudo ln -sf /usr/share/postgresql-common/pg_wrapper /usr/local/bin/pgsql2shp
sudo ln -sf /usr/share/postgresql-common/pg_wrapper /usr/local/bin/raster2pgsql

Spatially enabling a database

With PostgreSQL 9.1, there are two methods to add PostGIS functionality to a database: using extensions, or using enabler scripts.

PostGIS Extension for PostgreSQL

Spatially enabling a database using extensions is a new feature of PostgreSQL 9.1.

Connect to your database using pgAdmin or psql, and run the following commands. To add postgis with raster support:

CREATE EXTENSION postgis;

To add topology support, a second extension can be created on the database:

CREATE EXTENSION postgis_topology;

Enabler Scripts / Template

Enabler scripts can be used to either build a template, or directly spatially enable a database. This method is older than the extension method, but is required if the raster support is not built.

The following example creates a template, which can be re-used for creating multiple spatially-enabled databases. Or if you just want to make one spatially enabled database, you can modify the commands for your needs.

PostGIS:

sudo -u postgres createdb template_postgis
sudo -u postgres psql -d template_postgis -c "UPDATE pg_database SET datistemplate=true WHERE datname=‘template_postgis‘"
sudo -u postgres psql -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-2.0/postgis.sql
sudo -u postgres psql -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-2.0/spatial_ref_sys.sql
sudo -u postgres psql -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-2.0/postgis_comments.sql

with raster support:

sudo -u postgres psql -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-2.0/rtpostgis.sql
sudo -u postgres psql -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-2.0/raster_comments.sql

with topology support:

sudo -u postgres psql -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-2.0/topology.sql
sudo -u postgres psql -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-2.0/topology_comments.sql

See also

=================8X----------------------------------X8============================

In the database console, try these!!

Connect to your database with psql or PgAdmin. Run the following SQL:

-- Enable PostGIS (includes raster)
CREATE EXTENSION postgis;
-- Enable Topology
CREATE EXTENSION postgis_topology;
-- fuzzy matching needed for Tiger
CREATE EXTENSION fuzzystrmatch;
-- Enable US Tiger Geocoder
CREATE EXTENSION postgis_tiger_geocoder;

For spatial objects!

-- Create table with spatial column
CREATE TABLE mytable (
  id SERIAL PRIMARY KEY,
  geom GEOMETRY(Point, 26910),
  name VARCHAR(128)
); 

-- Add a spatial index
CREATE INDEX mytable_gix
  ON mytable
  USING GIST (geom); 

-- Add a point
INSERT INTO mytable (geom) VALUES (
  ST_GeomFromText(‘POINT(0 0)‘, 26910)
);

-- Query for nearby points
SELECT id, name
FROM mytable
WHERE ST_DWithin(
  geom,
  ST_GeomFromText(‘POINT(0 0)‘, 26910),
  1000
); 

If you system alerts that "

gis=# create extension fuzzystrmatch;
ERROR: could not open extension control file "/usr/share/postgresql/9.1/extension/fuzzystrmatch.control": No such file or directory

"

, try to

sudo apt-get install postgresql-contrib-9.1 -y

then , you will see something:

gis=# create extension fuzzystrmatch;
CREATE EXTENSION
gis=# create extension postgis_tiger_geocoder;
CREATE EXTENSION
gis=# 

notice the ‘gis‘ is the name of the database.

时间: 2024-12-26 14:51:51

PostgreSQL with PostGIS for mapping coordinates的相关文章

ubuntu 安装 postgresql 和 postgis

1.安装postgresql$sudo apt-cache search postgresql //查找最新的postgresql包$sudo gem apt-get install postgresql包名 //选择包名进行安装安装postgis$sudo apt-cache search postgis //查找最新的postgresql$sudo apt-get install postgis包名(如:postgresql-9.3-postgis-2.1) 2.后创建postgresql超

PostgreSQL 与 PostGIS 在CentOS上的安装

PostgreSQL和PostGIS的安装主要有两种方式,从源码安装和用包管理工具安装,推荐用包管理工具安装,下面是在CentOS 7.1 X64 上安装的具体步骤 安装YUM repository. 推荐使用 PGDG(PostgreSQL Global Development Group)的repository,这个repository包含官方最新的PostgreSQL及匹配的PostGIS,使用别的repository没有最新的或者没有匹配的PostGIS. 在如下链接页面找到相应操作系统

PostgreSQL及PostGIS使用

基础知识 参考文档:http://www.postgis.net/docs/ PostGIS支持的GIS对象是OpenGIS Consortium(OGC)定义的"简单特征"的超集.OpenGIS规范定义了两种表达空间对象的标准方法:the Well-Known Text (WKT) form and the Well-Known Binary (WKB) form.WKT和WKB都包括有关对象类型和形成对象的坐标的信息.WKT实例:POINT(0 0)LINESTRING(0 0,1

CentOS7使用yum安装PostgreSQL和PostGIS

更新yum源 CentOS7默认yum源的PostgreSQL版本过低,不适合在本版本上使用.在https://yum.postgresql.org/repopackages.php上找到适合CentOS7的RPM源,复制其url地址,使用yum安装. 同时安装epel(Extra Packages for Enterprise Linux 7),为了稳定性,CentOS7的默认yum源缺少很多组件,这些组件可以在epel上找到. 命令: yum install -y https://downl

centos 使用yum 安装自定义安装postgresql和postgis扩展已经phpPgAdmin

系统信息: #head -1  /etc/issue CentOS release 6.5 (Final) 安装postgresql9.3版本: #rpm -ivh http://yum.postgresql.org/9.3/redhat/rhel-6-x86_64/pgdg-centos93-9.3-1.noarch.rpm # yum install postgresql93 postgresql93-server postgresql93-libs postgresql93-contrib

Win7(X64) 下安装PostgreSQL及postgis

最快捷径: 1. 从官网直接 下载postgresql-9.6.5-1-windows-x64-binaries.zip,解压,手动执行cmd,...安装完毕! 2. http://download.osgeo.org/postgis/windows/pg96/ ,挑选合适的版本,其它无可言. 注:BigSQL的PGC本意好,可网络不好,安装起来相当坑!

ArcCatalog/arcgis怎么连接postgresql/postpis

在ArcCatalog左侧目录树中有Database Connections. 双击后选择database plantform:postgresql,instance为localhost(127.0.0.1一样),输入用户和密码(默认用户postgres),database最好不要选择默认系统数据库postgres(有的会提示不能选择系统数据库) Unable to connect to database server to retrieve database list; please veri

基于Jmeter的PostgreSQL空间性能测试笔记

这是很早之前做过的一个测试,最近在整理postgresql测试相关的资料,所以也把它拿出来了与大家分享. 首先解释一下所谓的PostgreSQL空间性能,主要是基于postgis的空间数据导入性能,详细的postgis知识请baidu,下面记录一下整个测试过程. PostgreSQL中空间图层手动创建 1.  跳过PostgreSQL.postgis和jmeter的部署操作(如果此步骤不会跳过一下所有步骤) 2.  创建模板为postgis数据库的数据库,创建成功的数据库模式中存在topolog

Ubuntu下postgre与postgis安装

卸载老版本sudo dpkg --purge postgis postgresql-9.3-postgis 1.安装postgresql $sudo apt-cache search postgresql //查找最新的postgresql包 $sudo gem apt-get install postgresql包名 //选择包名进行安装 2.设置postgres用户密码 sudo passwd postgres 3.登陆postgresql, $sudo -u postgres psql 4