RASTER2PGSQL(1)

πŸ’– NAME πŸ’–

raster2pgsql β€” bestie, it loads GDAL supported raster formats into a PostGIS raster table. That's the whole job description and she slays it. πŸ’…


✨ DESCRIPTION ✨

okay so raster2pgsql is a raster loader executable, right? She takes GDAL supported raster formats and turns them into sql that's ready to be loaded into a PostGIS raster table. And not to flex but she can also load folders of raster files and create overviews of rasters. main character behavior honestly. πŸ‘‘

Since raster2pgsql is compiled as part of PostGIS most often (unless you compile your own GDAL library, look at you go 🧚), the raster types supported by the executable will be the same as those compiled in the GDAL dependency library. Wanna see the list of raster types your particular raster2pgsql supports? Use the -G switch, bestie. πŸ“‹ Those should be the same as those provided by your PostGIS install documented here ST_GDALDrivers if you are using the same gdal library for both. iykyk. 🌸


πŸ› οΈ SYNOPTIS πŸ› οΈ

(yes she's spelled like that, don't perceive it πŸ™ˆ)

raster2pgsql [<options>] <raster>[ <raster>[ ...]] [[<schema>.]<table>]

Multiple rasters can also be specified using wildcards (*,?). Go off, wildcards. πŸ¦‹


πŸ‘‘ OPTIONS πŸ‘‘

  • -s <srid> β€” Set the raster's SRID. Defaults to 0. If SRID not provided or is 0, raster's metadata will be checked to determine an appropriate SRID. she'll figure it out herself, trust. πŸ”
  • -b <band> β€” Index (1-based) of band to extract from raster. For more than one band index, separate with comma (,). Ranges can be defined by separating with dash (-). If unspecified, all bands of raster will be extracted. all of them. every single one. no crumbs left. πŸ“
  • -t <tile size> β€” Cut raster into tiles to be inserted one per table row. <tile size> is expressed as WIDTHxHEIGHT. <tile size> can also be "auto" to allow the loader to compute an appropriate tile size using the first raster and applied to all rasters. let her cook. πŸ”₯
  • -P β€” Pad right-most and bottom-most tiles to guarantee that all tiles have the same width and height. symmetry queen. ✨
  • -R β€” Register the raster as an out-of-db (filesystem) raster. Provided raster should have absolute path to the file.
  • (-d|a|c|p) β€” These are mutually exclusive options. pick ONE bestie, you cannot have all four, that's not how this works πŸ’€
    • -d β€” Drops the table, then recreates it and populates it with current raster data. out with the old, in with the new. πŸ—‘οΈ
    • -a β€” Appends raster into current table, must be exactly the same table schema. exactly. do not play with her. 😭
    • -c β€” Creates a new table and populates it, this is the default if you do not specify any options. the no-notes default. πŸŽ€
    • -p β€” Prepare mode, only creates the table. structure only, no data, we're just setting the vibe. πŸ—οΈ
  • -f <column> β€” Specify the name of the raster column.
  • -F β€” Add a column with the filename of the raster. so you never lose track of who's who 🫢
  • -n <column> β€” Specify the name of the filename column. Implies -F.
  • -l <overview factor> β€” Create overview of the raster. For more than one factor, separate with comma (,). Overview table name follows the pattern o_<overview factor>_<table>. Created overview is stored in the database and is not affected by -R. she lives in the db now, she does not care about your filesystem drama. πŸ’…
  • -q β€” Wrap PostgreSQL identifiers in quotes.
  • -I β€” Create a GIST spatial index on the raster column. The ANALYZE command will automatically be issued for the created index. she does the extra step for you, unprovoked. iconic. ⭐
  • -M β€” Run VACUUM ANALYZE on the table of the raster column. Most useful when appending raster to existing table with -a. glow-up for your table. 🌈
  • -C β€” Set the standard set of constraints on the raster column after the rasters are loaded. Some constraints may fail if one or more rasters violate the constraint. ⚠️ no cap, this one can genuinely bounce if your data is messy.
  • -x β€” Disable setting the max extent constraint. Only applied if -C flag is also used.
  • -r β€” Set the constraints (spatially unique and coverage tile) for regular blocking. Only applied if -C flag is also used.
  • -T <tablespace> β€” Specify the tablespace for the new table.

Note that indices (including the primary key) will still use the default tablespace unless the -X flag is also used. don't get got by this one, it's sneaky πŸ™ˆ

  • -X <tablespace> β€” Specify the tablespace for the table's new index.

This applies to the primary key and the spatial index if the -I flag is used.

  • -N <nodata> β€” NODATA value to use on bands without a NODATA value. giving the void a little name tag 🏷️
  • -k β€” Skip NODATA value checks for each raster band. living dangerously, we love that for you πŸ’€
  • -E <endian> β€” Control endianness of generated binary output of raster. Use 0 for XDR and 1 for NDR (default). Only NDR is supported at this time. so yeah, 1 or nothing, bestie. 🀷
  • -V <version> β€” Specify version of output WKB format. Default is 0. Only 0 is supported at this time. one version, one vibe. πŸŽ€
  • -e β€” Execute each statement individually, do not use a transaction. every statement on its own little journey. πŸ¦‹
  • -Y β€” Use COPY statements instead of INSERT statements.
  • -G β€” Print the supported GDAL raster formats. the receipts, the whole roster. πŸ“œ
  • -? β€” Display the help screen. when in doubt, ask her directly. πŸ’œ

quick vibe check, bestie: -d, -a, -c and -p are mutually exclusive, so choose exactly one or the universe will choose for you (it won't, it'll just be sad 😭). Also -x and -r only do anything if -C is also along for the ride, and -n quietly drags -F in with it. kthxbye. 🫢

and that's the whole page!! this is raster2pgsql, RELEASE: 2.1.2, from way back in April 2014 β€” shoutout to the PostGIS / GDAL girlies who wrote her, absolute legends, and to whoever owns the copyright and license on this thing, we appreciate you fr fr. πŸŒΈβœ¨πŸ’–