PostGIS 测试 - 点(POINT)

1.建表

    创建包含空间数据的表mytable。

CREATE TABLE pointtable ( 
  id SERIAL PRIMARY KEY,
  name VARCHAR(128),
   geom GEOMETRY(Point, 26910)
);

2.添加GIST索引

CREATE INDEX pointtable_gix ON pointtable USING GIST (geom); 

3.插入数据

INSERT INTO pointtable (name, geom) VALUES ('p1',
  ST_GeomFromText('POINT(0 0)', 26910)
);
INSERT INTO pointtable (name,geom) VALUES ('p2',
  ST_GeomFromText('POINT(5 0)', 26910)
);
INSERT INTO pointtable (name,geom) VALUES ('p3',
  ST_GeomFromText('POINT(0 10)', 26910)
);

4.QGIS中显示几何数据

    PostGIS 测试 - 点(POINT)_第1张图片

5.查询

select id, name, ST_AsEwkt(geom) from pointtable ;

     查询结果:

   PostGIS 测试 - 点(POINT)_第2张图片

     查询与POINT(0 0) 相距 5以内的数据。

SELECT id, name, ST_AsEwkt(geom) FROM pointtable WHERE ST_DWithin(
 geom, ST_GeomFromText('POINT(0 0)', 26910), 5);

     查询结果:

  PostGIS 测试 - 点(POINT)_第3张图片

 

你可能感兴趣的:(PostGIS)