开源空间运算 opengis 相关产品 :
搭建 postgis + postgresql
需要安装
postgresql
proj
geos
postgis
$$在搭建时 postgis 编译时 ,参数 新版本 有变化
./configure
--with-pgconfig=/usr/local/pgsql/bin/pg_config
--with-projdir=/usr/local/share/proj
--with-geosconfig=/usr/local/bin/geos-config
启动 和 mysql 一样使用 非 root 帐号
[postgres@hpc] $ /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
[postgres@hpc] $ /usr/local/pgsql/bin/postmaster -D /usr/local/pgsql/data
[postgres@hpc] $ /usr/local/pgsql/bin/createdb testgisdb
#注入 postgis functions
$postgis.sql 文件在 postgis 安装目录下有
[postgres@hpc] $ /usr/local/pgsql/bin/psql -f postgis/postgis.sql
-d testgisdb
使用参考:
#官方文档
这 用个 实用小例 :
$> su postgres
$> /usr/local/pgsql/bin/psql -d test
testgisdb =# create table test1 (myID int4, pt geometry, myName varchar );
testgisdb =# alter table test1 add primary key (myID);
testgisdb =# insert into test1 values (1, 'POINT(0 0)', 'beijing' );
testgisdb
=# insert into test1 values (2, 'POINT(31.5 60.87)', 'shanghai' );
testgisdb
=# insert into test1 values (3, 'POINT(10.77 85.902)', 'tianjin' );
testgisdb =# select myname,AsText(pt) from test1;
myname | astext
----------+---------------------
beijing | POINT(0 0)
shanghai | POINT(31.5 60.87)
tianjin | POINT(10.77 85.902)
#这里 你们应该懂的!!
testgisdb=# select myname,AsText(pt) from test1 where ST_within( pt, 'POLYGON((0 0,0 70,100 70,100 0,0 0))' ) ;
myname | astext
----------+-------------------
shanghai | POINT(31.5 60.87)