博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PostgreSQL9.1 with PostGIS 2.1.4 for mapping coordinates on linux/ubuntu 已经打包成deb 可下载...
阅读量:4361 次
发布时间:2019-06-07

本文共 6122 字,大约阅读时间需要 20 分钟。

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.bz2tar xfj geos-3.3.9.tar.bz2cd geos-3.3.9./configuremakesudo make installcd ..

 

[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 makesudo make installsudo ldconfig

 

 

Then you may compile the postgis package.

Build PostGIS

wget http://download.osgeo.org/postgis/source/postgis-2.0.6.tar.gztar xfz postgis-2.0.6.tar.gzcd 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.

./configuremakesudo make installsudo ldconfigsudo 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/shp2pgsqlsudo ln -sf /usr/share/postgresql-common/pg_wrapper /usr/local/bin/pgsql2shpsudo 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_postgissudo -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.sqlsudo -u postgres psql -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-2.0/spatial_ref_sys.sqlsudo -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.sqlsudo -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.sqlsudo -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 TopologyCREATE EXTENSION postgis_topology;-- fuzzy matching needed for TigerCREATE EXTENSION fuzzystrmatch;-- Enable US Tiger GeocoderCREATE EXTENSION postgis_tiger_geocoder;

 

For spatial objects!

-- Create table with spatial columnCREATE TABLE mytable (   id SERIAL PRIMARY KEY,  geom GEOMETRY(Point, 26910),  name VARCHAR(128));  -- Add a spatial indexCREATE INDEX mytable_gix  ON mytable   USING GIST (geom);  -- Add a pointINSERT INTO mytable (geom) VALUES (  ST_GeomFromText('POINT(0 0)', 26910)); -- Query for nearby pointsSELECT id, nameFROM mytableWHERE 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 EXTENSIONgis=# create extension postgis_tiger_geocoder;CREATE EXTENSIONgis=#

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

 

 

 

deb packages download and their installation order:

geos_3.4.2-1_amd64.deb 

gdal_1.11.1-1_amd64.deb  

postgis_2.1.4-1_amd64.deb 

 

Happy hacking! 

转载于:https://www.cnblogs.com/spaceship9/p/4057907.html

你可能感兴趣的文章
【Golang 接口自动化08】使用标准库httptest完成HTTP请求的Mock测试
查看>>
前端必读:浏览器内部工作原理
查看>>
Uri、URL和URN三者的区别
查看>>
数据字典的转换
查看>>
关于动态添加iview admin路由以及刷新侧边栏
查看>>
ApplicationInsights的探测器尝鲜
查看>>
java 解析Json格式数据
查看>>
unix中的线程池技术详解
查看>>
CSS简介
查看>>
常用三大软件评价1
查看>>
MVC各层介绍使用---初步理解
查看>>
单例对象的创建与销毁
查看>>
知识点关键词(记录一下)
查看>>
国际结算业务
查看>>
嵌套循环概念
查看>>
C# 生成订单号的几种方式
查看>>
IOS开发札记
查看>>
1.2.2 OSI参考模型 上
查看>>
centos服务器设置代理上网的方法
查看>>
Spring入门教程:通过MyEclipse开发第一个Spring项目
查看>>