作者名:Dominik Mikiewicz Michal Mackiewicz Tomasz Nycz
本章字數:250字
更新時間:2021-07-02 22:52:24
Importing multiple rasters
Let's import a directory of rasters now. We have four files with the file name mask gray_50m_partial*.tif. In order to import all the files at once, we'll issue the following command:
Processing 1/4: gray_50m_partial_bl.tif BEGIN CREATE TABLE CREATE TABLE CREATE TABLE INSERT 0 1 INSERT 0 1 INSERT 0 1 Processing 2/4: gray_50m_partial_br.tif (...) Processing 3/4: gray_50m_partial_tl.tif (...) Processing 4/4: gray_50m_partial_tr.tif (...) CONTEXT: PL/pgSQL function addrasterconstraints(name,name,name,boolean,boolean,boolean,boolean,boolean,boolean,boolean,boolean,boolean,boolean,boolean,boolean) line 53 at RETURN NOTICE: Adding maximum extent constraint CONTEXT: PL/pgSQL function addrasterconstraints(name,name,name,boolean,boolean,boolean,boolean,boolean,boolean,boolean,boolean,boolean,boolean,boolean,boolean) line 53 at RETURN addrasterconstraints ---------------------- t (1 row)
addoverviewconstraints ------------------------ t (1 row)
addoverviewconstraints ------------------------ t (1 row)
COMMIT
The command used to import multiple rasters was very similar to the one we used to import a single file. The difference was a filename mask used in place of a filename: gray_50m_partial*.tif. If we had used a bit more griddy pattern such as *.tif, all the TIF files present in a directory would be imported.
When processing multiple files, one can pipe the output to psql without the connection info specified as psql params, but in such a case, equivalent environment variables will have to be set (on Windows, use the set command, and on Linux, export):
set PGPORT=5434 set PGHOST=localhost set PGUSER=postgres set PGPASSWORD=somepass set PGDATABASE=mastering_postgis raster2pgsql -s 4326 -C -l 2,4 -I -F -t 2700x2700 gray_50m_partial*.tif data_import.gray_50m_partial | psql