-
Notifications
You must be signed in to change notification settings - Fork 60
Doc In Progress: 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.
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:
- Point: Point Landmark
- Line: Primary and Secondary Roads
Install PostGIS. Create a user gis
with a password of super_gis
, create a database
named gis2
and grant all privileges to user gis
to 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
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
- In the left control-panel column of GeoServer, under the "Data" header, click on "Workspaces".
- Click the green "+" button.
- Name the work space "Geomoose" with a Namespace URI of "http://geomoose.demo".
- In the left control-panel column of GeoServer, under the "Data" header, click on "Stores".
- Click the green "+" button. Create a new PostGIS Database store.
- 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.
- In the left control-panel column of GeoServer, under the "Data" header, click on "Layers".
- Click the green "+" button.
- Select "Geomoose:census_data"
- A list should appear, next to
census_cities
click the "Publish" link. - 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.
- Click "Save" at the bottom.
- In the left control-panel column of GeoServer, under the "Data" header, click on "Workspaces".
- You should now see a list showing the "Geomoose" workspace. Click on the workspace name to view the settings.
- Click on the Security tab. For ROLE_ANONYMOUS, enable
Read
andWrite
. (ToDo: is this required?) - Click "Save" at the bottom.
- In the left control-panel column of GeoServer, under the "Services" header, click on "WFS".
- Scroll to the section labelled "Service Level" and set the "Service Level" radio button to "Complete". 43 Scroll to the bottom and click "Submit".
See https://docs.geoserver.org/latest/en/user/production/container.html#enable-cors
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.