Quickstart tutorial

This tutorial will guide you through some of the most basic tasks that can be performed using the OpenGeo Suite QGIS plugin.

Prerequisites

This tutorial assumes that QGIS and the OpenGeo Suite QGIS plugin has been already installed. It also assumes a local GeoServer instance and a PostGIS database installed with the parameters set by a standard OpenGeo Suite installation:

  • GeoServer running on port 8080 and responding on http://localhost:8080/geoserver/
  • PostGIS running on port 5432

You may need to adapt the examples as needed to fit your specific installation.

Data

Download the example data to be used in this tutorial. Extract this archive to a convenient directory.

Connecting to GeoServer

  1. To start, open the OpenGeo Explorer by clicking the OpenGeo menu and selecting OpenGeo Explorer. The panel will appear on the right side of your QGIS window.

    _images/explorer1.png

    OpenGeo Explorer

  2. You will see that the GeoServer catalogs entry is empty. Click to select it and then click New catalog.

    Note

    The buttons on the toolbar will change depending on the type of element selected in the tree.

  3. The catalog creation dialog contains the default parameters for a local GeoServer instance.

    _images/create_catalog.png

    Default parameters

  4. There is no need to modify the default values, so just click OK. The new catalog will appear in the GeoServer catalogs branch.

    _images/catalog_entry.png

    GeoServer catalog

Publishing a QGIS project

  1. In order to publish data into that catalog (to GeoServer), the first thing to do is to create a workspace where we can put our data. Select the GeoServer Workspaces entry and then click New workspace in the toolbar.

  2. Fill out the form in the dialog boxes with the inputs as shown above and click OK.

    • Name: quickstart
    • URI: http://quickstart
    _images/create_workspace.png
  3. The new workspace should now appear in the list. It is not the default workspace, though, so to make it the default, select the workspace item, right-click and then select Set as default workspace. While not necessary, this will make the next few tasks a bit easier to perform.

    _images/default_workspace.png
  4. Open the QGIS project that is included in the example data (quickstart.qgs). There should be five layers in your project in two groups.

    This is what the project will look like in the QGIS Layers panel:

    _images/project.png

    Quickstart sample project

  5. We will publish this project to GeoServer as it is, with those layers, groups, and the symbology associated with each layer.

    To publish the project as it is, just select the QGIS project entry in the OpenGeo Explorer tree, and then click Publish.... You will see the following dialog:

    _images/publish_project1.png
  6. Select the quickstart workspace as the destination workspace. Make sure the Global group name box is left blank. Click OK to start the publishing process.

  7. Once finished, your catalog should look like this.

    _images/catalog_after_publish.png

    As you can see, a store has been created for each QGIS layer, and also the corresponding GeoServer layers and styles. Layers have been configured to use the corresponding styles.

Publishing a shapefile

The sample data contains a shapefile named pt4.shp that was not included in the QGIS project. We will add it to the already-published content. It is not necessary to open/view the layer in QGIS to publish it to GeoServer.

  1. Open the QGIS Browser (View ‣ Panels ‣ Browser if it is not already open) and locate the shapefile.

    _images/file_in_browser.png
  2. Select the file and drag it onto the GeoServer Workspaces catalog item in the tree.

    _images/drag_file.png

    Since the quickstart workspace was set as the default, the layer will be added to that workspace. If you want to publish into another one, just drop it on the corresponding workspace item instead of the catalog one.

  3. In this case, we want the layer to have the same style as the other layers we uploaded (which themselves all share the same styling), so we can reuse one of the uploaded styles. To change the style, select the layer in the GeoServer Layers (not GeoServer Workspaces) and then click the Add style to layer button. You will see the following dialog:

    _images/add_style1.png
  4. Select the pt1 style in the list. Make sure to check the Add as default style option as well.

    Note

    You can also accomplish the same action by dragging the pt1 style onto the layer item. That will not make it the default style, but you can then select it and click the Set as default style button.

  5. Having switched the style for our pt4 layer to use the one from pt1, we can now remove the original pt4 style. This can be done by right-clicking the style and selecting Remove style from layer. You can also delete it from the catalog itself (as it is not used by any other layer) by clicking the pt4 element in the Styles branch and then selecting the Delete action.

Editing a style

One of the most interesting features of the OpenGeo Suite QGIS plugin is that you can use QGIS to create your styles, without having to edit SLD code manually.

The sample project already has a style for each one of its layers, which was uploaded when we published the project to the GeoServer catalog. You can modify the style and then reimport it into the catalog, but you can also directly edit any GeoServer style without it being part of a QGIS project.

To edit the style of the landuse layer in GeoServer, locate the layer in the GeoServer Layers tree. Under it, you should see the list of styles associated with the layer. Right-click the style (also called landuse) and select the Edit option.

Note

There is also an Edit SLD option to edit the actual raw SLD, but that is a different task from this.

_images/edit_style.png

This will open the QGIS symbology dialog, where you can make the changes you want to your style. When you close it, the style in your GeoServer catalog will be updated.

To see this in action, let’s make some small edits to this style:

  1. Double click one of the rows (for example, agricultural_areas).
  2. In the Style properties dialog, click the Color button and change the color.
  3. Click OK.
  4. Delete the bottom rule that contains (no filter). Click to select it and click the Delete button (the red minus).

The style has been changed in GeoServer. This can be verified by right-clicking the same style and selecting Edit SLD and looking at the RGB value for the Polygon Fill of the agricultural_areas rule. It can also be viewed in GeoServer’s Layer Preview.

Note

The style change will not be reflected in the QGIS viewing window, because it is reading from the local project and not from GeoServer.

_images/landuse_before.png

Original landuse style

_images/landuse_after.png

Changed landuse style

Publishing from PostGIS

There are other ways to publish data. Instead of creating GeoServer layers based on shapefiles, we can create layers based on database tables.

We will see this by first importing those shapefiles into a PostGIS database, and then creating layers.

  1. First create a database named quickstart. Make sure this database is spatially enabled.

    Note

    The details of this step are beyond the scope of this tutorial, as it must be done outside of QGIS using PostgreSQL command-line utilities like psql or the pgAdmin utility. An example using the command line would look like this:

    createdb -U postgres quickstart
    psql -U postgres -d quickstart -c "create extension postgis;"
    
  2. Connect to the database using the OpenGeo Explorer by right-clicking the PostGIS connections item in the tree and selecting New connection.

    _images/new_pg_connection1.png
  3. Set the parameters of the connection and click OK. The database should appear in the tree.

    _images/connection.png
  4. Now click the schema where you want to import your data (default for a newly-created database is called public, and select Import files. The following dialog will appear:

    _images/import_to_postgis.png
  5. Click the button in the upper part of the dialog to select the files to import. Select the pt1.shp, pt2.shp, and pt3.shp files. Set the name of the destination table to elevation, and check the Add to table (do not overwrite) box. This will cause all files to be imported to a single table named elevation and not as three separate tables. The dialog should look like this.

    _images/import_to_postgis2.png
  6. Click OK and the data will be imported.

    Todo

    This doesn’t work currently.

  7. To create a GeoServer layer from that table, drag and drop the table onto GeoServer Workspaces, just like when importing the shapefile.

  8. The resulting GeoServer layer will have no style associated. You can solve that by dropping a style onto the layer.

Publishing a TIF file

Raster layers are published in a similar way to vector layers. The example data includes a raster layer named dem.tif` that can be uploaded to GeoServer in the two ways we’ve seen before:

  1. Drag file name from Browser to GeoServer Workspaces.
  2. Add to the current project, then right-=click on layer in the QGIS Layers list and select Publish.

In either case, a new coverage store will be created in the catalog, and the corresponding layer will be published.

Styling is also uploaded and set as the default style in the published layer. If publishing directly from the file, a default style will be used. Single-band layers will use a black-to-white color ramp, and all other layers are assumed to be 3-band RGB color images.

Caching

Once data is in the GeoServer catalog, we can use the OpenGeo Explorer panel to seed the tile cache of a particular layer.

  1. In the GeoWebCache layers entry, you should see something like this:

    _images/gwc.png
  2. Click the layer that corresponds to the PostGIS-based layer (elevation). Right-click and select Seed. You will see a dialog to define the seeding task to perform, along with all parameters, as shown in the figure below:

    _images/seed_dialog.png

    Todo

    Be explicit about details

  3. Click OK to start the seeding process. The description panel of the layer entry will change to reflect that a seeding operation has been launched.

    _images/seed1.png
  4. The description is not updated automatically, but you can click the Update link to refresh and see how it progresses, or the Kill link to abort the seeding operation.

Preprocessing data

The layers to upload sometimes require preprocessing, for instance if they are not in the optimal format to provide the best performance once they are published. This preprocessing can be performed independently before publishing, but can also be included as part of the publishing operation itself.

The OpenGeo Explorer integrates with the QGIS Processing Framework and allows you to define a process to be run on any layer before uploading it, publishing the resulting processed layer instead.

Processes are defined using the QGIS processing graphical modeler or as python scripts, and the process to use is specified in the Explorer configuration.

The sample data zip file contains an example hook that can be used for vector layers. It will export the selected features to a new layer, so only those features will be later uploaded. If the layer you are uploading is not open in QGIS (such as when you export dragging it directly from the QGIS browser), the hook will have no effect at all (since it is not open, a selection does not exist). If, however, the layer is loaded and a selection exists, only the selected features will be uploaded. If no features are selected, the whole layer will be uploaded.

Follow these steps to enable the upload hook

  1. Open the OpenGeo Explorer configuration dialog from the OpenGeo menu.

    _images/config1.png
  2. Find the Vector preprocessing hook file parameter. The data file that you downloaded contains an example model named vector_hook.py. Locate it and enter the path to it as value of the parameter. This will cause the model to be run before the data is uploaded, and the resulting output to be imported instead of the original layer.

  3. Make a selection in one of the project layers and upload it to GeoServer. The preprocessing hook will be run before the upload and only the selected features will be uploaded. To disable it for future uploads, just go to the configuration and change the value of the corresponding value to an empty string, so it doesn’t point to any valid model or script file.