Loading and displaying Shapefile supply

Open ‘PG Admin’ from the Windows desktop and, using the menu options available, create a new database and a new schema within the database to hold the OS OpenMap-Local data. It is recommended that the user not use the ‘public’ schema to hold the data itself.

OS OpenMap local data shown in a new database schema
OS OpenMap local data in PG Admin

In the example above, a database called ‘osopenmap’ has been created along with a schema called ‘openmap’ into which the data will be loaded. As the data to be loaded comes in shapefile format, there is an easy to use PostGIS plugin available within PostgreSQL to load shapefile data.

A screenshot of the PostGIS plugin in the Plugins menu of the PG Admin toolbar
PostGIS plugin

Select ‘plugins’ from the main menu followed by ‘PostGIS Shapefile and DBF Loader

The next window allows the user firstly to view connection details and then to add files to the database. The first thing to do will be to test connection details. Click on the ‘view connection details’ button.

PostGIS connection window showing localhost server on port 5432 connecting to osopenmap database
PostGIS connection window

The resulting box should contain the username and password already entered along with the host name. The database being used to contain the data should already be selected. Click ‘OK

PostGIS Shapefile Import/Export manager showing a successful database connection
PostGIS Shapefile Import/Export manager

If everything is working OK, ‘connection succeeded’ should appear in the Log Window. Click the ‘Add File’ button.

In the next box which appears, use the file tree in the ‘Places’ box on the left to navigate to the folder in which the OS OpenMap-Local data resides. A list of the files will appear in the main window. It is possible to load one or all of the files into the database. In the example below, all of the shapefiles have been selected. The click ‘Open’.

Shape file selection window showing available Shape Files
Shape file selection window

Another window will open listing the selected shapefiles. The Schema and SRID will need to be changed. The schema will need to be changed to the schema in the database into which the data is being loaded (in this case ‘openmap’). The SRID (or co-ordinate reference system) will need to be changed to 27700, which is the code for British National Grid. This will need to be done for all of the shapefiles being loaded. No other element will need to be changed. Once this has been done click ‘Import’.

PostGIS Shapefile import/Export Manager window highlighting changes to the coordinate reference system to the British National Grid code 27700
PostGIS Shapefile import/Export Manager window

At the end of the procedure, the log window at the bottom of the PostGIS import/export manager box should indicate that all of the shapefiles have loaded successfully. However one or two of the shapefiles may fail to load because the text encoding needs to be changed from UTF-8 to LATIN1. If this is the case, the user will need to close down the plugin and start again selecting just the shapefiles which failed to load previously. The schema and SRID must be changed again and this time, the character encoding will need to be changed. This can be done by clicking the ‘options’ button;

Change the DBF character encoding to LATIN1 and click ‘OK.

Import options dialog showing LATIN1 file character encoding entered
Import options dialog showing LATIN1 file character
PostGIS Shapefile Import/Export manager window showing two files in the import list
PostGIS Shapefile Import/Export manager window

Changing this should allow the import to complete successfully. For information, the shapefiles which are mostly likely to need this change to be made are the ‘named place, important building and functional site’ files. This is because these files contain text which may have accents within them which are not part of the UTF-8 character set.

Once the import has been completed, the user can check if the data is loaded properly by refreshing the schema in PGAdmin and opening up the ‘table’ tree. If the data has loaded correctly, there should be 20 tables in the schema.

The data is now loaded into the PostGIS database and is now ready to be viewed in a GIS application. As QGIS, the open-source GIS, has been developed to work seamlessly with PostGIS, we will open up and view the data using that application. However, any GI application which includes support for PostGIS can be used.

Last updated

Was this helpful?

#345: Adding What's next networking links

Change request updated