Wechat: yu389741| Email: gisdqy@163.com

Shop:https://www.giserdqy.com/shop

PostGIS 测试 – 建表,插入及查询数据(点)


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中显示几何数据

    

5.查询

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

     查询结果:

   

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

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

     查询结果:

  

 

转载自:https://blog.csdn.net/liyazhen2011/article/details/88850741