Raster import was covered in Chapter 1, Importing Spatial Data, subject and exporting is on its way in the next chapter, so we can look strictly into vector <-> raster conversion and processing.
For our use case, we will use EU-DEM dataset, produced using Copernicus data and information funded by European Union - EU-DEM layers. It's one arc second model of the whole European Union (without overseas territories). With its open license, we can use it with no concerns. The dataset is accessible by http://www.eea.europa.eu/data-and-maps/data/eu-dem.
As a vector layer, we can use OpenStretMap data for the Poland and Czech Republic administrative units.
In the first step, let's import the dataset as we learned in Chapter 1, Importing Spatial Data. For optimization of import processes, look into metadata, for SRID and size of raster, gdalinfo makes it easy:
user@machine:~/dev/gis/dem$ gdalinfo eudem_dem_5deg_n45e015.tif
Driver: GTiff/GeoTIFF
Files: eudem_dem_5deg_n45e015.tif
Size is 18000, 18000
Coordinate System is:
GEOGCS["ETRS89",
DATUM["European_Terrestrial_Reference_System_1989",
SPHEROID["GRS 1980",6378137,298.2572221010042,
AUTHORITY["EPSG","7019"]],
AUTHORITY["EPSG","6258"]],
PRIMEM["Greenwich",0],
UNIT["degree",0.0174532925199433],
AUTHORITY["EPSG","4258"]]
Origin = (15.000000000000000,50.000000000000000)
Pixel Size = (0.000277777777778,-0.000277777777778)
Metadata:
AREA_OR_POINT=Area
Image Structure Metadata:
COMPRESSION=LZW
INTERLEAVE=BAND
Corner Coordinates:
Upper Left ( 15.0000000, 50.0000000) ( 15d 0' 0.00"E, 50d 0' 0.00"N)
Lower Left ( 15.0000000, 45.0000000) ( 15d 0' 0.00"E, 45d 0' 0.00"N)
Upper Right ( 20.0000000, 50.0000000) ( 20d 0' 0.00"E, 50d 0' 0.00"N)
Lower Right ( 20.0000000, 45.0000000) ( 20d 0' 0.00"E, 45d 0' 0.00"N)
Center ( 17.5000000, 47.5000000) ( 17d30' 0.00"E, 47d30' 0.00"N)
Band 1 Block=18000x1 Type=Float32, ColorInterp=Gray
Min=54.810 Max=2424.210
Minimum=54.810, Maximum=2424.210, Mean=317.651, StdDev=254.987
NoData Value=nan
Metadata:
STATISTICS_MAXIMUM=2424.2099609375
STATISTICS_MEAN=317.65072388322
STATISTICS_MINIMUM=54.810001373291
STATISTICS_STDDEV=254.98702538825
Now we know that EPSG:4258 (ETRS89) should be taken and tiling applied; in our case, 4500 px will be good approach. Using copy, it will be done faster.
raster2pgsql -s 4258 -C -I -l 2,4,8 -t 4500x4500 -F -Y *.tif raster_ops.dem | psql -d mastering_postgis -U osm
If you don't use -C flag during import, probably the AddRasterConstraints() function will be used later to fill in correct values in the raster_columns catalog.