postgresql基于postgis常用空间函数

1、ST_AsGeoJSON 图元转geojson格式

select ST_AsGeoJSON(l.geom) from g_zd l limit 10

  postgresql基于postgis常用空间函数_第1张图片

2、 ST_Transform 坐标转换

select st_transform(l.shape, 3857) from sde_wf_cyyq l limit 10
select st_astext(st_transform(l.shape, 3857)) from sde_wf_cyyq l limit 10

  postgresql基于postgis常用空间函数_第2张图片

3、st_astext 图元二进制转文本

select st_srid(shape) from sde_wf_cyyq

4、st_srid 查询数据表坐标系

select st_srid(shape) from sde_wf_cyyq

   postgresql基于postgis常用空间函数_第3张图片

  如果为0的话那就没有坐标系

 6、st_geometry 文本转二进制

INSERT INTO sde.pro_gc ( objectid, shape )
VALUES
 (11,st_geometry ( 'POLYGON((116.403322 39.920255,116.410703 39.897555,116.402292 39.892353,116.389846 39.891365,116.403322 39.920255))', 4326));

 7、ST_Intersects 求相交

update g_fw a set block=q.grid_block from g_qy q where st_intersects(a.geom, q.geom)

8、表转geojson数据

SELECT
	row_to_json ( fc ) AS geojson 
FROM
	(
	SELECT
		'FeatureCollection' AS TYPE,
		array_to_json ( ARRAY_AGG ( f ) ) AS features 
	FROM
		(
		SELECT
			'Feature' AS TYPE,
			ST_AsGeoJSON ( ( lg.geom ), 15, 0 ) :: json AS geometry,
			row_to_json ( lg ) AS properties 
		FROM
			g_fj AS lg 
		) AS f 
	) AS fc;

  

 

 

你可能感兴趣的:(数据库)