PG+PostGIS 空间函数查询
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PG+PostGIS 空间函数查询相关的知识,希望对你有一定的参考价值。
参考技术A 1、计算线路长度(米)SELECT patrolid, st_length(ST_Transform(geom,3857))
FROM public.patrolrecord where patrolid='3d4f8e0d-e759-469f-b78e-50f6445b56c9'
ST_Area(ST_Transform(geom,3857))
2、空间相交计算
判断点是否在面内:
select ST_DWithin(ST_SetSRID(ST_MakePoint(117.272031,31.868486),4326),(SELECT geom from sxkwg where xzqhcode='340103009'),0)
3、矩形查询
_st_intersects(st_transform(ST_MakeEnvelope(" + leftTopX + "," + leftTopY + "," + rightBottomX + "," + rightBottomY + ",4326" + "),4326),geom)
4、多边形查询
SELECT gid,year,cc,gb,ec,name,type,cc,gb,ec,name,type,st_astext(geom) wkt FROM V_ARCP where ST_Intersects(st_geometryfromtext('wkt',4326), geom) and year='2017'
5、根据已存在经纬度字段更新geometry字段
update map_thematicinfo set geom =ST_SetSRID(ST_MakePoint(longitude,altitude),4326) where gid=138
6、查询两点之间的距离(获取面状要素几何中心)
select jdm,st_distance(ST_Centroid(geom),ST_GeomFromText('POINT(117.12927656982 31.9223723088035)',4326),true) as distance from jzw order by distance asc limit 5
7、合并多个几何对象
update tb_duty_area set geom=SELECT st_union(geom) from tb_duty_area where (uid=49 or uid =107) WHERE uid=363
以上是关于PG+PostGIS 空间函数查询的主要内容,如果未能解决你的问题,请参考以下文章
GISpostgres(postgis) --》nodejs+express --》geojson --》leaflet
PostGIS 错误 - PG::InternalError: 错误: 无法加载库