SELECT ST_GeometryFromText('POINT(116.39088 39.90763)',4326);
SELECT ST_GeomFromText('POINT(116.39088 39.90763)',4326);
SELECT ST_PointFromText('POINT(116.39088 39.90763)',4326);
1、创建点类型的表,类型不要选择postgresql提供的空间数据类型,要选择postgis提供的数据类型。
CREATE TABLE pointtable ( id SERIAL PRIMARY KEY, name VARCHAR(128), geom GEOMETRY(Point) );
2、插入点
INSERT INTO pointtable (name, geom) VALUES ('p1', ST_GeomFromText('POINT(120.205707 31.839323)', 4326) );
3、查询点
SELECT ST_X(geom) as x,ST_Y(geom) as y from pointtable;
--SRID=4326;POINT(120.205707 31.839323)
SELECT st_asewkt(geom) as point from pointtable;
--POINT(120.205707 31.839323)
SELECT ST_AsText(geom) as point from pointtable;
--{"type":"Point","coordinates":[120.205707,31.839323]}
SELECT ST_AsGeoJSON(geom) as point from pointtable;