.. _geoserver.basics.shapefile_add:

Adding a Shapefile
------------------

The task of adding a Shapefile is one that is core to any GIS tool. This section covers the task of adding and publishing a Shapefile with GeoServer.

#. Navigate to the workshop :file:`data/bayarea` directory and find the following files shapefiles::

     bay_area_coastline.shp
     bay_area_coastline.shx
     bay_area_coastline.dbf
     bay_area_coastline.prj

   Copy the files to the following directory::

     C:\Program Files\GeoServer 1.7.6\data_dir\data

   .. note:: Ensure that all four parts of the shapefile are copied.  This includes the ``shp``, ``shx``, ``dbf``, and ``prj`` extensions.

   .. figure:: shapefile_add1.png
      :width: 650  

      Copying the bay_area_coastline Shapefile

#. Navigate to the GeoServer `Welcome Page <http://localhost:8080/geoserver/>`_.

#. From the Welcome page click on the :guilabel:`Config` link located on the left hand side.

   .. figure:: shapefile_add2.jpg

      Configuring GeoServer

#. On the :guilabel:`Login` page, enter the username "admin" and password "geoserver".

   .. figure:: shapefile_add3.jpg

      Logging in

#. Click the :guilabel:`Data` link.

   .. figure:: shapefile_add4.jpg

      Configure data link

#. Select the :guilabel:`Data Stores` link and click :guilabel:`New`.

   .. figure:: shapefile_add5.jpg

      Configure data store link

   .. figure:: shapefile_add6.jpg

      Add a new data store

#. Select :guilabel:`Shapefile` from the drop down list, enter "bay_area_coastline_shp" in the text box, and click :guilabel:`New`.

   .. figure:: shapefile_add7.jpg

      Creating a new Shapefile data store

   .. note:: The drop down list contains a list of all the spatial formats supported by GeoServer. When creating a new data store one of these formats must be chosen. Formats like Shapefile and PostGIS are supported by default, and many other formats are available as extensions.

#. On the :guilabel:`Feature Data Set Editor` page enter "file:data/bay_area_coastline.shp" in the :guilabel:`url` field, and click :guilabel:`Submit`.

   .. figure:: shapefile_add8.jpg

      Specifying Shapefile parameters

#. On the :guilabel:`Feature Type Editor` page set the *default style* by selecting :guilabel:`polygon` from the :guilabel:`Style` drop down list.

   .. note:: It is possible to attach any number of styles to a feature type or layer. Choosing one from the Style drop down sets the server default, which will be chosen when a client does not specify a style.

   .. figure:: shapefile_add9.jpg

      Setting the layer style

   .. warning:: A common mistake for new users is to set the default style for the feature type in the **Additional Styles** list, and not in the **Style** drop down.
      
      .. figure:: shapefile_add10.jpg
         :align: center

         Mistakingly setting the default style

#. Scroll down the page and generate the bounds for the layer by clicking the :guilabel:`Generate` button.

   .. figure:: shapefile_add11.jpg

      Generating the layer bounding box

#. Scroll to the bottom of the page and click :guilabel:`Submit`.

   .. figure:: shapefile_add12.jpg

      Submitting the layer configuration

#. Finalize the changes by clicking :guilabel:`Apply` located in the top left corner of the page.

   .. figure:: shapefile_add13.jpg

      Applying configuration changes

#. Persist changes by clicking :guilabel:`Save`.

   .. note:: The GeoServer user interface follows a **Submit-Apply** workflow. When a change is made it will **not** take effect until it is Applied.

At this point a shapefile has been added and is ready to be served by GeoServer. In the :ref:`next <geoserver.basics.map_preview>` section the configuration will be verified with the Map Preview tool.
