postgis常用函数实践

参照:https://note.youdao.com/share/index.html?id=baa8fff3251212023a179f2e85faacef&type=note#/

PostGIS中的常用函数:https://www.w3cschool.cn/wqf_database/wqf_database-ip53284h.html

官方文档https://postgis.net/docs/

https://postgis.net/docs/reference.html#Management_Functions

1、存储在数据库中ways 表格数据如下

postgis常用函数实践_第1张图片

postgres中,可以通过函数st_astext(geom)实现geometry到wkt的转换,通过st_geomfromtext(wkt,wkid)实现wkt到geometry的转换,具体使用如下:

select st_astext(linestring) as wkt from ways where id = 4860359;

SELECT ST_GeomFromText('CIRCULARSTRING(220268 150415,220227 150505,220227 150406)');

postgis常用函数实践_第2张图片

2、st_geomfromtext(wkt,wkid)

如: SELECT ST_GeomFromText(('point(87.5758 43.7822)'),4326) as geom limit 100;

3、 获取点的x和y坐标值,获取线/面的xmin,ymin,xmax,ymax

如:

1) select st_astext(geom) as wkt from nodes limit 100;select st_astext(geom) as wkt from nodes where id = 25423131;

postgis常用函数实践_第3张图片

或 select st_x(geom) as x,st_y(geom) as y from(select geom from nodes where id = 25423131)alais;

postgis常用函数实践_第4张图片

2) select st_xmin(geom) as xmin,st_ymin(geom) as ymin,st_xmax(geom) as xmax,st_ymax(geom) as ymax from nodes limit 100;

postgis常用函数实践_第5张图片

 

4、查看长度st_length

如:select st_length((select linestring as wkt from ways where id = 4860359)) as length ;

postgis常用函数实践_第6张图片

5、计算距离st_distance(geom,geom)或st_distance(wkt,wkt)

文档参照https://postgis.net/docs/ST_Distance.html

如: SELECT ST_Distance(gg1, gg2) As spheroid_dist, ST_Distance(gg1, gg2, false) As sphere_dist

FROM (SELECT

ST_GeogFromText('SRID=4326;POINT(-72.1235 42.3521)') As gg1,

ST_GeogFromText('SRID=4326;LINESTRING(-72.1260 42.45, -72.123 42.1546)') As gg2

) As foo ;

6、计算面积st_area(geom)或st_area(wkt)

文档参照https://postgis.net/docs/ST_Area.html

如:SELECT ST_Area(the_geom) As sqft, ST_Area(ST_Transform(the_geom,26986)) As sqm

FROM (SELECT

ST_GeomFromText('POLYGON((743238 2967416,743238 2967450,

743265 2967450,743265.625 2967416,743238 2967416))',2249) ) As foo(the_geom);

postgis常用函数实践_第7张图片

7、数据导出,存为csv格式

如 3.2 案例

COPY ( select st_xmin(geom) as xmin,st_ymin(geom) as ymin,

st_xmax(geom) as xmax,st_ymax(geom) as ymax from nodes)

TO 'D:/aa_lamda/map/aa.csv' DELIMITER ',' CSV HEADER;

postgis常用函数实践_第8张图片

 

 

 

 

 

 

 

 

你可能感兴趣的:(架构,GIS)