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:8090/geoserver/web.

Getting Started

  1. Download the file nyc_roads.zip. This file contains a shapefile of roads from New York City that will be used during in this tutorial.

  2. Unzip the nyc_roads.zip. The extracted folder consists of the following four files:

    nyc_roads.shp
    nyc_roads.shx
    nyc_roads.dbf
    nyc_roads.prj
    
  3. Move the nyc_roads folder into <GEOSERVER_DATA_DIR>/data where GEOSERVER_DATA_DIR is the root of the GeoServer data directory. If no changes were were made to the GeoServer file structure, the path should be geoserver/data_dir/data/nyc_roads.

Create a New Workspace

The first step is to create a workspace for the Shapefile. The workspace is a container used to group similar layers together.

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

  2. Log into GeoServer as described in the Logging In quick start.

  3. Navigate to Data‣Workspaces.

    ../../_images/data_workspaces.png

    Workspaces page

  4. To create a new workspace click, select the Add new workspace button. You will be prompted to enter a workspace Name and Namespace URI.

    ../../_images/new_workspace.png

    Configure a New Worksapce

  5. Enter the name nyc_roads and the URI http://opengeo.org/nyc_roads A workspace name is a name describing your project and cannot exceed ten characters or contain a space. A Namespace URI (Uniform Resource Identifier), is typically a URL associated with your project, with perhaps a different trailing identifier.

    ../../_images/workspace_nycroads.png

    NYC Roads Workspace

  6. Click the Submit button. GeoServer will append the nyc_roads workspace to the bottom of the Workspace View list.

Create a Store

  1. Navigate to Data‣Stores.

  2. In order to add the nyc_roads data, we need to create a new Store. Click on the Add new store button. You will be redirected to a list of data types GeoServer supports.

    ../../_images/stores_nycroads.png

    Data Sources

  3. Because nyc_roads is a shapefile, select Shapefile: ESRI(tm) Shapefiles (.shp).

  4. On the New Vector Data Source page begin by configuring the Basic Store Info. Select the workspace nyc_roads from the drop down menu, type NYC Roads for the name and enter a brief description, such as Roads in New York City.

  5. Under the Connections Parameters specify the location of the shapefile–file:data/nyc_roads/nyc_roads.shp.

    ../../_images/new_shapefile.png

    Data Info and Parameters for nyc_roads

  6. Press Save. You will be redirected to New Layer chooser page in order to configure nyc_roads layer.

Layer Configuration

  1. On the New Layer chooser page, select the Layer name nyc_roads.

    ../../_images/new_layer.png

    New Layer Chooser

  2. The following configuration define the data and publishing parameters for a layer. Enter a short Title and Abstract for the nyc_roads shapefile.

    ../../_images/new_data.png

    Basic Resource Information for Shapefile

  3. Generate the shapefile’s bounds by clicking the Compute from data and then Compute from Native bounds.

    ../../_images/boundingbox1.png

    Generate Bounding Box

  4. Set the shapefile’s style by first moving over to the Publishing tab.

  5. The select line from the Default Style drop down list.

    ../../_images/style1.png

    Select Default Style

  6. 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_roads is probably published we will preview the layer. Navigate to the Map Preview and search for the nyc_roads:nyc_roads 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 line style.

    ../../_images/openlayers1.png

    OpenLayers map of nyc_roads