The steps you need to follow to complete this recipe are as follows:
- Create a shapefile from the virtual driver created in the previous recipe using the ogr2ogr command (note that in this case, you do not need to specify the -f option as the shapefile is the default output format for the ogr2ogr command):
$ ogr2ogr global_24h.shp global_24h.vrt
- Generate the SQL dump file for the shapefile using the shp2pgsql command. You are going to use the -G option to generate a PostGIS spatial table using the geography type, and the -I option to generate the spatial index on the geometric column:
$ shp2pgsql -G -I global_24h.shp
chp01.global_24h_geographic > global_24h.sql
- Analyze the global_24h.sql file (in Windows, use a text editor such as Notepad):
$ head -n 20 global_24h.sql
The output of the preceding command is as follows:
- Run the global_24h.sql file in PostgreSQL:
$ psql -U me -d postgis_cookbook -f global_24h.sql
If you are on Linux, you may concatenate the commands from the last two steps in a single line in the following manner:
$ shp2pgsql -G -I global_24h.shp chp01.global_24h_geographic | psql -U me -d postgis_cookbook
- Check if the metadata record is visible in the geography_columns view (and not in the geometry_columns view, as with the -G option of the shp2pgsql command, we have opted for a geography type):
postgis_cookbook=# SELECT f_geography_column, coord_dimension,
srid, type FROM geography_columns
WHERE f_table_name = 'global_24h_geographic';
The output of the preceding command is as follows:
- Analyze the new PostGIS table with ogrinfo (use the -fid option just to display one record from the table):
$ ogrinfo PG:"dbname='postgis_cookbook' user='me'
password='mypassword'" chp01.global_24h_geographic -fid 1
The output of the preceding command is as follows:
Now, open QGIS and try to add the new layer to the map. Navigate to Layer | Add Layer | Add PostGIS layers and provide the connection information, and then add the layer to the map as shown in the following screenshot: