Skip to content

Doc In Progress: Editing Vectors Using GeoServer with GeoMOOSE

Brent Fraser edited this page Feb 3, 2021 · 6 revisions

Editing Vectors: Using GeoServer with GeoMOOSE

This is a basic walk-through using to use GeoMOOSE with GeoServer and PostGIS. This is not meant to be comprehensive and the reader should have some knowledge of GeoServer and PostGIS. GeoMOOSE comes configured with a WFS-T example, using some of the U.S. Census Bureau's data for Minnesota.

Download the Places Shapefile from the Census Bureau

We will be using a polygon shapefile as the source data for this example. Download tl_2019_27_place.zip This is the "places" file for the state of Minnesota. "Places" are a Census terminology for incorporated cities, townships, and equivalents.

If you want to test point and line geometry types, you can download two additional shapefiles covering Minnesota:

Install PostGIS and Load the Places Shapefile

Install PostGIS. Create a user gis with a password of super_gis, create a database named gis2 and grant all privileges to user gisto the gis2 database.

Now load the Places shapefile. There are a couple of good applications for doing this, GDAL's ogr2ogr and
PostGIS'shp2pgsql. Whichever tool you use, the layer should be named census_cities for the purposes of this example.

A typical ogr2ogr string to load the data will look similar to this:

ogr2ogr -f PostgreSQL "PG:dbname=gis2 user=gis password=super_gis" tl_2019_27_place.shp tl_2019_27_place -nln census_cities -nlt GEOMETRY -lco DIM=2

The commands for the other two point and line shapefiles would be:

ogr2ogr -f PostgreSQL "PG:dbname=gis2 user=gis password=super_gis" tl_2019_27_pointlm.shp tl_2019_27_pointlm -nln census_landmarks -nlt GEOMETRY -lco DIM=2
ogr2ogr -f PostgreSQL "PG:dbname=gis2 user=gis password=super_gis" tl_2019_27_prisecroads.shp tl_2019_27_prisecroads -nln census_roads -nlt GEOMETRY -lco DIM=2

Install and Configure GeoServer

The following instructions are for GeoServer 2.17.2. The best documentation on setting up GeoServer comes from GeoServer itself. Install and startup a GeoServer instance by executing Geoserver\bin\startup.sh/ If you've installed GeoServer on Windows, start GeoServer by executing C:\Program Files\GeoServer\bin\startup.bat. Make sure you run startup.bat as Administrator.

Now open a browser and go to http://localhost:8080/geoserver/web/. Login by using the default credentials: username admin, password geoserver

Create a Geomoose Workspace

  1. In the left control-panel column of GeoServer, under the "Data" header, click on "Workspaces".
  2. Click the green "+" button.
  3. Name the work space "Geomoose" with a Namespace URI of "http://geomoose.demo".

Add a data Store

  1. In the left control-panel column of GeoServer, under the "Data" header, click on "Stores".
  2. Click the green "+" button. Create a new PostGIS Database store.
  3. Use the following settings:
  • Workspace: Geomoose
  • Data Source Name: census_data
  • Description: Census Data for Testing
  • Enabled: Should be checked to indicate "true".
  • The rest of the settings are for PostgreSQL, please fill them out to match the information you used to load the shapefile.

Add the Layer

  1. In the left control-panel column of GeoServer, under the "Data" header, click on "Layers".
  2. Click the green "+" button.
  3. Select "Geomoose:census_data"
  4. A list should appear, next to census_cities click the "Publish" link.
  5. When the Edit Layer screen is shown, most of the information should fill in automatically. In the Bounding Boxes section click "Compute from data" link then the "Compute from native bounds" link.
  6. Click "Save" at the bottom.

Configure Workspace for WFS

  1. In the left control-panel column of GeoServer, under the "Data" header, click on "Workspaces".
  2. You should now see a list showing the "Geomoose" workspace. Click on the workspace name to view the settings.
  3. Click on the Security tab. For ROLE_ANONYMOUS, enable Read and Write. (ToDo: is this required?)
  4. Click "Save" at the bottom.

Configure GeoServer to Enable Transactional WFS (WFS-T) (ToDo: is this required?)

  1. In the left control-panel column of GeoServer, under the "Services" header, click on "WFS".
  2. Scroll to the section labelled "Service Level" and set the "Service Level" radio button to "Complete". 43 Scroll to the bottom and click "Submit".

Configure GeoServer to allow CORS

See https://docs.geoserver.org/latest/en/user/production/container.html#enable-cors

GeoMOOSE Mapbook Setup

The Mapbook includes a fragment which supports the above configuration of GeoServer. Here is that fragment:

   <map-source name="geoserver-wfs" type="wfs" >
        <url>http://localhost:8080/geoserver/wfs</url>
        <param name="typename" value="Geomoose:census_cities" />
        <config name="geometry-name" value="wkb_geometry" />
        <config name="namespace-uri" value="http://geomoose.demo" />
        <!-- specifying by URN will ensure that axis-order is correct -->
        <config name="srs" value="urn:ogc:def:crs:EPSG::4326" />
        <!-- specify the ID column -->
        <config name="id-property" value="ogc_fid" />

        <layer name="census_cities">
            <style><![CDATA[
            {
                "line-color" : "#998ec3",
                "line-width" : 4,
                "fill-color" : "#998ec3",
                "fill-opacity" : 0.1
            }
            ]]></style>

            <template name="identify"><![CDATA[
                <div>
                    <div class="item">
                        <label>{{ properties.name }}</label>
                    </div>
                    <div class="item">
                        ID: {{properties.geoid}}
                    </div>
                </div>
            ]]></template>
        </layer>
    </map-source>

    <map-source
        name="geoserver"
        type="wms"
    >
        <url>http://localhost:8080/geoserver/wms?</url>

        <layer
            name="census_cities"
            query-as="geoserver-wfs/census_cities"
        />
        <layer name="census_landmarks" />
        <layer name="census_roads" />

        <param name="FORMAT" value="image/png"/>
        <param name="TRANSPARENT" value="TRUE"/>
    </map-source>
...
    <catalog>
	
            <group title="Census Layers" expand="true">
                <layer
                    title="Census cities"
                    src="geoserver/census_cities"
                    draw-modify="true"
                    draw-polygon="true"
                />
            </group>

    </catalog>

Once you uncomment the above fragment and save the mapbook.xml, refresh your browser to reload the mapbook.
You will now be able to edit the Census cities boundaries and attributes, and save them to the server using the edit tools.