0
点赞
收藏
分享

微信扫一扫

gis 中常用cql 记录(mysql、sql server)(主要是投影转换)


常用sql整理

//获取投影坐标

SELECT ST_SRID(the_geom) from gis_fx_xjxzq



// 更新投影,将投影转为 EPSG:4326
update gis_fx_xjxzq set the_geom = st_geomfromtext(st_astext(the_geom),4326)



// ST_AsText 方法返回表示几何的文本字符串
SELECT ST_astext(the_geom) from gis_fx_cjqy


// 某个表中没有行政区划代码,可以根据行政区划空间字段和该表的空间字段匹配得出 行政区划code
update gis_taijiang_spl as a join gis_taijiang_xjqy as b on st_within(ST_Centroid(a.the_geom), b.the_geom) set a.xjqydm = b.XJQYDM


update gis_taijiang_spl as a join gis_taijiang_xjqy as b on st_within(ST_Centroid(a.the_geom), b.the_geom) set a.XJQYMC = b.XJQYMC

// 根据坐标点转成 几何点

create view ddd as select *,st_geometryfromtext(concat('POINT(',substring_index(`admin_well`.`gps`,',',1),' ',substring_index(`admin_well`.`gps`,',',-(1)),')'),4326) AS `the_geom` from admin_well

判断两个面是否相交(场景: 高标表中没有行政区划代码,所以我们用县级表和高标表进行一个相交查询,如果相交,将县级行政区划代码添加到高标表中)

create table gis_fx_gbzxm_final as  SELECT a.*,b.XJQYDM as xjqydm from gis_fx_gbzxm_copy as a LEFT JOIN gis_fx_xjqy b on st_within(a.the_geom,b.the_geom)

示例:

bmfw_jyyl_hospital 表中的the_geom是一个点空间字段

gis_gaolan_xjxzq 表中的the_geom 是一个面空间字段

判断 bmfw_jyyl_hospital 的the_geom是否和gis_gaolan_xjxzq的the_geom相交

select  id,
`name`,
`type`,
`address`,
`location`,
`photos`,
the_geom from bmfw_jyyl_hospital a
join
gis_gaolan_xjxzq b
on ST_Intersects (a.the_geom,b.the_geom)

本人在项目中使用的时候,因为  bmfw_jyyl_hospital 给的是一个经纬度(字符串,对应location字段103.948966,36.328377) 

所以使用的sql是如下

select  id,
`name`,
`type`,
`address`,
`location`,
`photos`,
st_geometryfromtext ( concat( 'POINT(', substring_index( `location`, ',', 1 ), ' ', substring_index( `location`, ',',-( 1 )), ')' ), 4326 ) AS `the_geom`
from bmfw_jyyl_hospital a
join
gis_gaolan_xjxzq b
on ST_Intersects (st_geometryfromtext ( concat( 'POINT(', substring_index( `location`, ',', 1 ), ' ', substring_index( `location`, ',',-( 1 )), ')' ), 4326 ),b.the_geom)

 

MySQL5.6中查询多边形包含点情况(ST_Contains、ST_Within)

SET @x = 121;
SET @y = 30;
-- SET @point = CONCAT('POINT(',@x,' ',@y,')');
set @point= Point(@x,@y);
set @geometry=ST_GeomFromText('POLYGON((121 30, 121 30, ..., 121 30, 121 30))');
SELECT ST_Contains(@geometry,@point);//面包含点
SELECT ST_Within(@point, @geometry);//点在面

Sql Server  

// 查询投影
select the_geom.STSrid from XJQY


// 投影转换
update XJQY SET the_geom.STSrid=4326 FROM XJQY

mysql 记录

1、对一个表的过滤根据另外一个表来

示例:对一个表的过滤根据另外一个表来,比如返回 bmfw_jyyl_hospital 表中的the_geom 和gis_gaolan_xjxzq中的the_geom相交的数据

select  id,
`name`,
`type`,
`address`,
`location`,
`photos`,
the_geom from bmfw_jyyl_hospital a
join
gis_gaolan_xjxzq b
on ST_Intersects (a.the_geom,b.the_geom)

还有一种方式

SELECT id,`name`,`type`,`address`,`location`,`photos`,the_geom  
FROM `bmfw_jyyl_hospital` WHERE ST_Intersects(the_geom), (SELECT the_geom from gis_gaolan_xjxzq))

举报

相关推荐

0 条评论