index.rst 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. .. _shapefile_quickstart:
  2. Publishing a shapefile
  3. ======================
  4. This tutorial walks through the steps of publishing a Shapefile with GeoServer.
  5. .. note:: This tutorial assumes that GeoServer is running at ``http://localhost:8080/geoserver``.
  6. Data preparation
  7. ----------------
  8. First let's gather that the data that we'll be publishing.
  9. #. Download the file :download:`nyc_roads.zip`. This archive contains a shapefile of roads from New York City that will be used during in this tutorial.
  10. #. Unzip the :file:`nyc_roads.zip` into a new directory named :file:`nyc_roads`. The archive contains the following four files::
  11. nyc_roads.shp
  12. nyc_roads.shx
  13. nyc_roads.dbf
  14. nyc_roads.prj
  15. #. Move the ``nyc_roads`` directory into ``<GEOSERVER_DATA_DIR>/data``, where ``<GEOSERVER_DATA_DIR>`` is the root of the :ref:`GeoServer data directory <datadir>`. If no changes have been made to the GeoServer file structure, the path is ``geoserver/data_dir/data/nyc_roads``.
  16. Creating a new workspace
  17. ------------------------
  18. The next step is to create a workspace for the shapefile. A workspace is a container used to group similar layers together.
  19. .. note:: This step is optional if you'd like to use an existing workspace. Usually, a workspace is created for each project, which can include stores and layers that are related to each other.
  20. #. In a web browser, navigate to ``http://localhost:8080/geoserver``.
  21. #. Log into GeoServer as described in the :ref:`logging_in` section.
  22. #. Navigate to :menuselection:`Data --> Workspaces`.
  23. .. figure:: ../../data/webadmin/img/data_workspaces.png
  24. Workspaces page
  25. #. Click the :guilabel:`Add new workspace` button.
  26. #. You will be prompted to enter a workspace :guilabel:`Name` and :guilabel:`Namespace URI`.
  27. .. figure:: new_workspace.png
  28. Configure a new workspace
  29. #. Enter the :guilabel:`Name` as ``nyc`` and the :guilabel:`Namespace URI` as ``http://geoserver.org/nyc``.
  30. .. note:: A workspace name is an identifier describing your project. It must not exceed ten characters or contain spaces. A Namespace URI (Uniform Resource Identifier) can usually be a URL associated with your project with an added trailing identifier indicating the workspace. The Namespace URI filed does not need to resolve to an actual valid web address.
  31. .. figure:: workspace_nycroads.png
  32. nyc workspace
  33. #. Click the :guilabel:`Submit` button. The ``nyc`` workspace will be added to the :guilabel:`Workspaces` list.
  34. Create a store
  35. --------------
  36. Once the workspace is created, we are ready to add a new store. The store tells GeoServer how to connect to the shapefile.
  37. #. Navigate to :menuselection:`Data-->Stores`.
  38. #. You should see a list of stores, including the type of store and the workspace that the store belongs to.
  39. #. In order to add the shapefile, you need to create a new store. Click the :guilabel:`Add new Store` button. You will be redirected to a list of the data sources supported by GeoServer. Note that the data sources are extensible, so your list may look slightly different.
  40. .. figure:: stores_nycroads.png
  41. Stores
  42. #. Click :guilabel:`Shapefile`. The :guilabel:`New Vector Data Source` page will display.
  43. #. Begin by configuring the :guilabel:`Basic Store Info`.
  44. * Select the workspace ``nyc`` from the drop down menu.
  45. * Enter the :guilabel:`Data Source Name` as ``NYC Roads``
  46. * Enter a brief :guilabel:`Description` (such as "Roads in New York City").
  47. #. Under :guilabel:`Connection Parameters`, browse to the location :guilabel:`URL` of the shapefile, typically :file:`nyc_roads/nyc_roads.shp`.
  48. .. figure:: new_shapefile.png
  49. Basic Store Info and Connection Parameters
  50. #. Click :guilabel:`Save`. You will be redirected to the :guilabel:`New Layer` page in order to configure the ``nyc_roads`` layer.
  51. Creating a layer
  52. ----------------
  53. Now that the store is loaded, we can publish the layer.
  54. #. On the :guilabel:`New Layer` page, click :guilabel:`Publish` beside the ``nyc_roads`` layer name.
  55. .. figure:: new_layer.png
  56. New layer
  57. #. The :guilabel:`Edit Layer` page defines the data and publishing parameters for a layer. Enter a short :guilabel:`Title` and an :guilabel:`Abstract` for the ``nyc_roads`` layer.
  58. .. figure:: new_data.png
  59. Basic Resource Information
  60. #. Generate the layer's bounding boxes by clicking the :guilabel:`Compute from data` and then :guilabel:`Compute from native bounds` links.
  61. .. figure:: boundingbox.png
  62. Generating bounding boxes
  63. #. Click the :guilabel:`Publishing` tab at the top of the page.
  64. #. We can set the layer's style here. Under :guilabel:`WMS Settings`, ensure that the :guilabel:`Default Style` is set to :guilabel:`line`.
  65. .. figure:: style.png
  66. Select Default Style
  67. #. Finalize the layer configuration by scrolling to the bottom of the page and clicking :guilabel:`Save`.
  68. Previewing the layer
  69. --------------------
  70. In order to verify that the ``nyc_roads`` layer is published correctly, we can preview the layer.
  71. #. Navigate to the :guilabel:`Layer Preview` screen and find the ``nyc:nyc_roads`` layer.
  72. .. figure:: layer_preview.png
  73. Layer Preview
  74. #. Click the :guilabel:`OpenLayers` link in the :guilabel:`Common Formats` column.
  75. #. An OpenLayers map will load in a new tab and display the shapefile data with the default line style. You can use this preview map to zoom and pan around the dataset, as well as display the attributes of features.
  76. .. figure:: openlayers.png
  77. Preview map of nyc_roads