1.栅格数据
WorldClim是一个高空间分辨率的全球天气和气候数据的数据库。可以从该网站下载天气数据。网址如下:https://www.worldclim.org。
下面是12个月份温度统计数据。
2.使用工具gdainfo查询栅格文件信息
>gdalinfo tmax1.bil
Driver: EHdr/ESRI .hdr Labelled
Files: tmax1.bil
tmax1.hdr
Size is 2160, 900
Coordinate System is:
GEOGCRS["WGS 84",
DATUM["World Geodetic System 1984",
ELLIPSOID["WGS 84",6378137,298.257223563,
LENGTHUNIT["metre",1]]],
PRIMEM["Greenwich",0,
ANGLEUNIT["degree",0.0174532925199433]],
CS[ellipsoidal,2],
AXIS["latitude",north,
ORDER[1],
ANGLEUNIT["degree",0.0174532925199433]],
AXIS["longitude",east,
ORDER[2],
ANGLEUNIT["degree",0.0174532925199433]],
ID["EPSG",4326]]
Data axis to CRS axis mapping: 2,1
Origin = (-180.000000000000057,90.000000000000000)
Pixel Size = (0.166666666666667,-0.166666666666667)
Corner Coordinates:
Upper Left (-180.0000000, 90.0000000)
Lower Left (-180.0000000, -60.0000000)
Upper Right ( 180.0000000, 90.0000000)
Lower Right ( 180.0000000, -60.0000000)
Center ( 0.0000000, 15.0000000)
Band 1 Block=2160x1 Type=Int16, ColorInterp=Undefined
Min=-478.000 Max=418.000
NoData Value=-9999
文件信息包含:文件组成tmax1.bil和tmax1.hdr,大小 2160*900像素,坐标系统WGS 84,中心位置和像素大小,最小值-478.000(对应-47.8度),最大值418(对应41.8度)等。
3.使用工具raster2pgsql 将栅格数据导入到postgis
首先,生成sql文件。
raster2pgsql -I -C -F -t 100x100 -s 4326 tmax1.bil public.tmax01 > tmax01.sql
命令中的参数如下:
参数 | 含义 |
---|---|
-I | 在栅格数据列上生成GIST空间索引 |
-C | 在栅格数据列上生成约束 |
-F | 增加一列,值为文件名 |
-t | 将栅格数据切分为片,片的大小格式为WIDTHxHEIGHT,然后插入每一行。 |
-s | 空间坐标系 |
然后,执行sql文件。
psql -d postgis_32_sample -U postgres -f tmax01.sql
参数 | 含义 |
---|---|
-d | 数据库 |
-U | 用户名 |
-f | 文件名 |
4.查询表信息
SELECT rid, filename, rast FROM public.tmax01;
在pgAdmin中显示查询结果:

5.生成栅格数据分块的轮廓,存入文件temp_grid.shp
ogr2ogr temp_grid.shp PG:"host=localhost port=5432 dbname=postgis_32_sample user=postgres password=postgres schemas=public" -sql "select rid, filename, ST_Envelope(rast) as the_geom from public.tmax01"
在QGIS中查看数据库表tmax1 和文件temp_grid.shp如下:
版权声明:本文为liyazhen2011原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。