ogr2ogr导入导出数据。

1.导入shp数据

ogr2ogr -f "PostgreSQL"  -sql "SELECT  ISO2, NAME FROM TM_WORLD_BORDERS_3 WHERE REGION=2 " -nlt MULTIPOLYGON   PG:"host=localhost port=5432 dbname=postgis_32_sample user=postgres password=postgres schemas=public"  -nln africa_countries -lco GEOMETRY_NAME=the_geom TM_WORLD_BORDERS_3.shp

其中,参数的含义如下:

参数含义
-f 表示输出文件类型。
-sql表示要执行的sql语句。
 -nln图层的名称
 -nlt图层定义的几何类型

2.查找日照时间最长的100个地区。

select ST_AsText(the_geom) AS the_geom, bright_t31 from global_24h 
order by bright_t31 desc limit 100;

在pgAdmin中的查询结果如下:

3.查找非洲日照时间最长的100个地区。

select ST_AsText(f.the_geom) AS the_geom, f.bright_t31, ac.iso2, ac.name 
from global_24h as f
join africa_countries as ac
on ST_Contains(ac.the_geom, ST_Transform(f.the_geom,4326))
order by f.bright_t31 desc limit 100;

在pgAdmin中的查询结果如下:

4.将查询结果以GeoJson的格式导出

ogr2ogr -f  "GeoJSON"  -t_srs EPSG:4326 warmest_hs.geojson  -sql "select f.the_geom AS the_geom, f.bright_t31, ac.iso2, ac.name from global_24h as f  join africa_countries as ac on ST_Contains(ac.the_geom, ST_Transform(f.the_geom,4326)) order by f.bright_t31 desc limit 100"  PG:"host=localhost port=5432 dbname=postgis_32_sample user=postgres password=postgres schemas=public" 

其中,参数-t_srs表示 在输出上重新投影或转换为 EPSG:4326 坐标系下。

5.在QGIS中,查看africa_countries 和 warmest_hs.geojson 信息

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值