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 坐标系下。