Publishing a Shapefile

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

Note

This tutorial assumes that GeoServer is running at http://localhost:8090/geoserver/web.

Getting Started

  1. Download the file nyc_roads.zip. This archive 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 nyc_roads contains the following four files:

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

#. 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 have been made to the GeoServer file structure, the path is geoserver/data_dir/data/nyc_roads.

Create a New Workspace

The first step is to create a workspace for the Shapefile. A 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 Logging In.

  3. Navigate to Data‣Workspaces.

    ../../_images/data_workspaces.png

    Workspaces page

  4. To create a new workspace click 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 as nyc_roads and the Namespace URI as http://opengeo.org/nyc_roads. A workspace name is a identifier describing your project. It must not exceed ten characters or contain spaces. A Namespace URI (Uniform Resource Identifier) is typically a URL associated with your project, perhaps with an added trailing identifier indicating the workspace.

    ../../_images/workspace_nycroads.png

    NYC Roads Workspace

  6. Click the Submit button. The nyc_roads workspace will be added to the Workspaces list.

Create a Data Store

  1. Navigate to Data‣Stores.

  2. In order to add the nyc_roads Shapefile, you need to create a new Store. Click on the Add new store button. You will be redirected to a list of the data sources supported by GeoServer.

    ../../_images/stores_nycroads.png

    Data Sources

  3. Select Shapefile - ESRI(tm) Shapefiles (.shp). The New Vector Data Source page will display.

  4. Begin by configuring the Basic Store Info. Select the workspace nyc_roads from the drop down menu. Enter the Data Source Name as NYC Roads. and enter a brief Description (such as “Roads in New York City”).

  5. Under Connection Parameters specify the location URL of the Shapefile as file:data/nyc_roads/nyc_roads.shp.

    ../../_images/new_shapefile.png

    Basic Store Info and Connection Parameters

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

Create a Layer

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

    ../../_images/new_layer.png

    New Layer chooser

  2. The Edit Layer page defines the Data and Publishing parameters for a layer. Enter a short Title and an Abstract for the nyc_roads layer.

    ../../_images/new_data.png

    Basic Resource Information

  3. Generate the layer’s bounding boxes by clicking the Compute from data and then Compute from Native bounds.

    ../../_images/boundingbox1.png

    Generate Bounding Boxes

  4. Set the layer’s style by switching to the Publishing tab.

  5. Select the line style from the Default Style drop down list.

    ../../_images/style1.png

    Select Default Style

  6. Finalize the layer configuration by scrolling to the bottom of the page and clicking Save.

Preview the Layer

  1. In order to verify that the nyc_roads layer is published correctly you can preview the layer. Navigate to the Layer Preview screen and find the nyc_roads:nyc_roads layer.

    ../../_images/layer_preview.png

    Layer Preview

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

  3. Success! An OpenLayers map loads in a new page and displays the Shapefile data with the default line style. You can use the Preview Map to zoom and pan around the dataset, as well as display the attributes of features.

    ../../_images/openlayers1.png

    Preview map of nyc_roads