Adding a Shapefile

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

Note

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

Getting started

  1. Download the zip file nyc_roads.zip. It contains a Shapefile with a subset of roads from New York City that will be used during in this tutorial.

  2. Unzip nyc_roads.zip into <GEOSERVER_DATA_DIR>/data where GEOSERVER_DATA_DIR is the root of the GeoServer data directory. Unzipping the archive will result in the following four files:

    nyc_roads.shp
    nyc_roads.shx
    nyc_roads.dbf
    nyc_roads.prj
    

Create a new data store

The first step is to create a data store for the Shapefile. The data store tells GeoServer how the Shapefile should be loaded, in particular where it is located.

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

  2. Navigate to Config‣Data‣DataStores.

    Data stores
  3. Create a new data store by clicking the New link.

    Creating a new data store
  4. Select Shapefile from the drop down and enter “nyc_roads_shapefile” in the text field. Then click the New button.

    Adding a new Shapefile
  5. Specify the Shapefile location by entering file:data/nyc_roads.shp in the url text field. Then click the Submit button.

    Specifying Shapefile location
  6. Click the Apply button located in the upper left hand corner of the page.

Configure the feature type

The next step is to configure the feature type for the Shapefile. The feature type tells GeoServer how the Shapefile should be published.

  1. Set the style by selecting line from the Style drop down list.

  2. Generate the bounds by clicking the Generate button.

  3. Scroll to the bottom of the and click the Submit button.

  4. Finalize changes by clicking the Apply button in the upper left hand corner of the page.

Preview the Layer

The final step is to verify that the Shapefile has been published properly. To do this Map Preview will be used.

Navigate to the map preview and select the topp:nyc_roads link.

../../_images/32-nyc_roads-preview-link.png

If the shapefile was added properly the result should be an OpenLayers map:

../../_images/33-nyc_roads-preview.png