Adding a PostGIS Table

This tutorial walks through the steps of publishing a PostGIS table with GeoServer.

Note

This tutorial assumes that GeoServer is running on http://localhost:8080/geoserver.

Note

This tutorial assumes PostGIS has been previously installed on the system.

Getting started

  1. Download the zip file nyc_buildings.zip. It contains a PostGIS dump of a subset of buildings from New York City that will be used during in this tutorial.

  2. Create a PostGIS database called “nyc”. This can be done with the following command line:

    createdb -T template_postgis nyc

    If the PostGIS install is not set up with the “postgis_template” then the following sequence of commands will perform the equivalent:

    ...
    
  3. Unzip nyc_buildings.zip to some location on the file system. This will result in the file nyc_buildings.sql.

  4. Import nyc_buildings.sql into the nyc database:

    psql -f nyc_buildings.sql nyc

Create a new data store

The first step is to create a data store for the PostGIS database “nyc”. The data store tells GeoServer how to connect to the database.

  1. In a web browser navigate to http://localhost:8080/geoserver.

  2. Navigate to Data‣Stores.

    ../../_images/datastores.png

    Adding a New Data Source

  3. Create a new data store by clicking the PostGIS NG link.

  4. Keeping the default Workspace enter Basic Store Info of Name and Description.

    ../../_images/basicStore.png

    Basic Store Info

  5. Specify the PostGIS database Connection Parameters

    dbtype

    postgisng

    host

    localhost

    post

    5432

    database

    nyc

    schema

    public

    user

    postgres

    passwd

    enter postgres password

    validate connections

    enable with check box

    Note

    The username and password parameters specific to the user who created the postgis database. Depending on how PostgreSQL is configured the password parameter may be unnecessary.

    ../../_images/connectionParameters.png

    Connection Parameters

  6. Click the Save button.

Layer Configuration

  1. Navigate to Data‣Layers.

  2. Select Add a new resource button.

  3. From the New Layer chooser drop down menu, select cite:nyc_buidings.

    ../../_images/newlayerchooser.png

    New Layer drop down selection

  4. On the resulting layer row, select the Layer name nyc_buildings.

    ../../_images/layerrow.png

    New Layer row

  5. The following configurations define the data and publishing parameters for a layer. Enter the Basic Resource Info for nyc_buildings.

    ../../_images/basicInfo.png

    Basic Resource Info

  6. Generate the database bounds by clicking the Compute from data and then Compute from Native bounds.

    ../../_images/boundingbox.png

    Generate Bounding Box

  7. Set the layer’s style by first moving over to the Publishing tab.

  8. The select polygon from the Default Style drop down list.

    ../../_images/style.png

    Select Default Style

  9. Finalize your data and publishing configuration by scrolling to the bottom and clicking Save.

Preview the Layer

  1. In order to verify that the nyc_building is probably published we will preview the layer. Navigate to the Map Preview and search for the cite:nyc_buildings link.

    ../../_images/layer-preview.png

    Layer Preview

  2. Click on the OpenLayers link under the Common Formats column.

  3. Success! An OpenLayers map should load with the default polygon style.

    ../../_images/openlayers.png

    OpenLayers map of nyc_buildings