index.rst 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. .. _postgis_quickstart:
  2. Publishing a PostGIS table
  3. ==========================
  4. This tutorial walks through the steps of publishing a PostGIS table with GeoServer.
  5. .. note:: This tutorial assumes that PostgreSQL/PostGIS has been previously installed on the system and responding on ``localhost`` on port ``5432``, and also 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_buildings.zip`. It contains a PostGIS dump of a dataset of buildings from New York City.
  10. #. Create a PostGIS database called ``nyc``. This can be done with the following commands:
  11. .. code-block:: console
  12. createdb nyc
  13. psql -d nyc -c 'CREATE EXTENSION postgis'
  14. .. note:: You may need to supply a username and password with these commands.
  15. #. Extract :file:`nyc_buildings.sql` from :file:`nyc_buildings.zip`.
  16. #. Import :file:`nyc_buildings.sql` into the ``nyc`` database:
  17. .. code-block:: console
  18. psql -f nyc_buildings.sql nyc
  19. Creating a new workspace
  20. ------------------------
  21. The next step is to create a workspace for the data. A workspace is a container used to group similar layers together.
  22. .. 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.
  23. #. In a web browser, navigate to ``http://localhost:8080/geoserver``.
  24. #. Log into GeoServer as described in the :ref:`logging_in` section.
  25. #. Navigate to :menuselection:`Data --> Workspaces`.
  26. .. figure:: ../../data/webadmin/img/data_workspaces.png
  27. Workspaces page
  28. #. Click the :guilabel:`Add new workspace` button.
  29. #. You will be prompted to enter a workspace :guilabel:`Name` and :guilabel:`Namespace URI`.
  30. .. figure:: ../shapefile-quickstart/new_workspace.png
  31. Configure a new workspace
  32. #. Enter the :guilabel:`Name` as ``nyc`` and the :guilabel:`Namespace URI` as ``http://geoserver.org/nyc``.
  33. .. 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.
  34. #. Click the :guilabel:`Submit` button. The ``nyc`` workspace will be added to the :guilabel:`Workspaces` list.
  35. Creating a store
  36. ----------------
  37. Once the workspace is created, we are ready to add a new store. The store tells GeoServer how to connect to the database.
  38. #. Navigate to :menuselection:`Data-->Stores`.
  39. #. Click on ``Add new Store``.
  40. #. You should see a list of stores, including the type of store and the workspace that the store belongs to.
  41. .. figure:: datastores.png
  42. Adding a new data source
  43. #. Create a new store by clicking the ``PostGIS`` link.
  44. #. Enter the :guilabel:`Basic Store Info`:
  45. * Select the ``nyc`` :guilabel:`Workspace`
  46. * Enter the :guilabel:`Data Source Name` as ``nyc_buildings``
  47. * Add a brief :guilabel:`Description`
  48. .. figure:: basicStore.png
  49. Basic Store Info
  50. #. Specify the PostGIS database :guilabel:`Connection Parameters`:
  51. .. list-table::
  52. :header-rows: 1
  53. * - Option
  54. - Value
  55. * - :guilabel:`dbtype`
  56. - :kbd:`postgis`
  57. * - :guilabel:`host`
  58. - :kbd:`localhost`
  59. * - :guilabel:`port`
  60. - :kbd:`5432`
  61. * - :guilabel:`database`
  62. - :kbd:`nyc`
  63. * - :guilabel:`schema`
  64. - :kbd:`public`
  65. * - :guilabel:`user`
  66. - :kbd:`postgres`
  67. * - :guilabel:`passwd`
  68. - (Password for the ``postgres`` user)
  69. * - :guilabel:`validate connections`
  70. - (Checked)
  71. .. note:: Leave all other fields at their default values.
  72. .. figure:: connectionParameters.png
  73. Connection Parameters
  74. #. Click :guilabel:`Save`.
  75. Creating a layer
  76. ----------------
  77. Now that the store is loaded, we can publish the layer.
  78. #. Navigate to :menuselection:`Data --> Layers`.
  79. #. Click :guilabel:`Add a new resource`.
  80. #. From the :guilabel:`New Layer chooser` menu, select ``nyc:nyc_buidings``.
  81. .. figure:: newlayerchooser.png
  82. Store selection
  83. #. On the resulting layer row, select the layer name ``nyc_buildings``.
  84. .. figure:: layerrow.png
  85. New layer selection
  86. #. 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_buildings`` layer.
  87. .. figure:: basicInfo.png
  88. Basic Resource Info
  89. #. Generate the layer's bounding boxes by clicking the :guilabel:`Compute from data` and then :guilabel:`Compute from native bounds` links.
  90. .. figure:: boundingbox.png
  91. Generating bounding boxes
  92. #. Click the :guilabel:`Publishing` tab at the top of the page.
  93. #. We can set the layer's style here. Under :guilabel:`WMS Settings`, ensure that the :guilabel:`Default Style` is set to :guilabel:`polygon`.
  94. .. figure:: style.png
  95. Select Default Style
  96. #. Finalize the layer configuration by scrolling to the bottom of the page and clicking :guilabel:`Save`.
  97. Previewing the layer
  98. --------------------
  99. In order to verify that the ``nyc_buildings`` layer is published correctly, we can preview the layer.
  100. #. Navigate to the :guilabel:`Layer Preview` screen and find the ``nyc:nyc_buildings`` layer.
  101. #. Click the :guilabel:`OpenLayers` link in the :guilabel:`Common Formats` column.
  102. #. 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.
  103. .. figure:: openlayers.png
  104. Preview map of nyc_buildings