1.安装PostGIS插件
1 2 |
sudo apt-get install PostGIS sudo apt-get install postgresql-9.3-postgis |
2.开启PostgreSql对于PostGIS 的支持,在psql
或者 PgAdmin 中执行命令
1 2 3 4 5 6 7 8 |
-- 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; |
3.测试例子
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
-- 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 ); |