Loading a Shapefile into PostGIS¶
This task shows how to load a shapefile into PostGIS database:
- Open the terminal window and enter the following command and press enter to creating a new database named ‘shape’:
Linux:
createdb -U postgres -T postgis20 shapeWindows:
setenv.bat createdb -U postgres -T postgis20 shape
- Enter the following command and press enter to load the shapefile into ‘shape’ database:
Linux:
shp2pgsql -I ${TRAINING_ROOT}/data/user_data/Mainrd.shp public.main_roads | psql -d shapeWindows:
shp2pgsql -I "%TRAINING_ROOT%\data\user_data\Mainrd.shp" public.main_roads | psql -U postgres -d shapeThe shapefile will be loaded within the ‘main_roads’ table of the ‘shape’ database. The following screenshot shows some of the table contents in
pgAdmin III
In the next section we will see how to add a PostGIS layer into GeoServer.