GeoServer: Difference between revisions

From Wildsong
Jump to navigationJump to search
Brian Wilson (talk | contribs)
Brian Wilson (talk | contribs)
 
(39 intermediate revisions by the same user not shown)
Line 7: Line 7:
"GeoServer is a Java-based software server that allows users to view and '''edit geospatial data'''. Using open standards set forth by the Open Geospatial Consortium (OGC), GeoServer allows for great flexibility in map creation and data sharing."
"GeoServer is a Java-based software server that allows users to view and '''edit geospatial data'''. Using open standards set forth by the Open Geospatial Consortium (OGC), GeoServer allows for great flexibility in map creation and data sharing."


The crucial feature for me is that it allows edits via WFS-T. That means I can hook up OpenLayers web clients to a database and allow them to create and edit data.
The crucial feature for me is that it allows edits via [[#WFS-T]]. That means I can hook up OpenLayers web clients to a database and allow them to create and edit data.
 
WFS-T comments: http://weblogs.java.net/blog/2006/01/09/geoserver-wfs-t


== History ==
== History ==


* 2019 Feb -- Finishing the migration to Docker Compose.
* 2019 Mar -- Migrated to Docker Compose.
* 2017 Sep -- Setting up Docker Compose version
* 2016 Sep -- updated Dart with 2.9.1 (latest stable release)
* 2016 Sep -- updated Dart with 2.9.1 (latest stable release)
* 2012 Sep -- 2.2 installed on Kilchis and Dart.<br>
* 2012 Sep -- 2.2 installed on Kilchis and Dart.<br>
Line 60: Line 57:
TMS reference implementation: see http://TileCache.org/
TMS reference implementation: see http://TileCache.org/


== Building the Geo-CEG Geoserver Docker images ==
== Geoserver in Docker ==


There will be 4 Docker containers in the finished project, pulled together with Compose.
The docker-compose set up includes geoserver, geowebcache, postgis, and pgadmin4.
See the full project on github, https://github.com/Wildsong/docker-geoserver


# mdillon/postgis@latest
I had a reverse proxy built into the compose setup but realized I needed a proxy for the other services running on [[Bellman]]
# geoceg/postgres will contain PostgreSQL with the ESRI SDE additions to make it compatible with ArcGIS
so now I have a generic proxy running in its own container.
# geoceg/geoserver which contains geoserver and geowebcache
Because GeoServer is tucked behind a proxy, it is accessible "everywhere" (currently it's behind my [[Firewall]] settings but that's a different story).
# dpage/pgadmin4


Outside of Docker I will use Debian nginx to proxy these services and hide behind its TLS encryption with proper certificates for https://maps.wildsong.biz and https://bellman.wildsong.biz
=== PostGIS ===


=== Geoserver ===
I keep more PostGIS notes here: [[PostGIS]].


I created a docker image and put it on github, https://github.com/Geo-CEG/docker-geoserver
See https://hub.docker.com/r/mdillon/postgis
and it autobuilds an image at https://hub.docker.com/r/geoceg/geoserver/
I will probably stop using this container, because I want the bleeding edge in my development server. (I live for pain)
and I continue to refine and update that image as needed in this project.
I can probably even go to PostGIS 3.0 now!!


Test it independently with  
From Postgis.org today: ''Although this release will work for PostgreSQL 9.4 and above, to take full advantage of what PostGIS 2.5 offers, you should be running PostgreSQL 11beta4+ and GEOS 3.7.0 which were released recently.
Best served with PostgreSQL 11 beta4 and pgRouting 2.6.1.''


docker run -t -p 8888:8080 --name=geoserver -v geoserver_files:/geoserver geoceg/geoserver:latest
In my current Docker, I can see using "docker inspect geoserver-db" that PostgreSQL is at 11.2 and from psql I can see GEOS is at 3.7.


I proxy port 8888 through nginx on Bellman so that it shows up as
postgres=# '''SELECT postgis_full_version();'''
https://maps.wildsong.biz/geoserver/web/
POSTGIS="2.5.1 r17027" [EXTENSION] PGSQL="110" GEOS="3.5.1-CAPI-1.9.1 r4246" PROJ="Rel. 4.9.3, 15 August 2016" GDAL="GDAL 2.1.2, released 2016/10/24" LIBXML="2.9.4" LIBJSON="0.12.1" LIBPROTOBUF="1.2.1" RASTER
 
  (1 row)
Because it's tucked behind this proxy, it should be accessible everywhere (based on my [[Firewall]] settings but that's a different story).
 
==== Upgrade ====
 
I just updated the Github project from 2.13.2 to 2.14.2 and want to upgrade my installed image.
  docker stop geoserver
docker rm geoserver
docker pull geoceg/geoserver:latest
Then issue the same Docker run (or compose) used before.
 
=== PostGIS ===
 
See https://hub.docker.com/r/mdillon/postgis


See also its parent https://hub.docker.com/_/postgres/
See also its parent https://hub.docker.com/_/postgres/


These commands put the data and config files outside of the container.
You can run the database independent of the compose configuration to test it.
These commands put the data and config files outside of the container, but still in a docker volume.


  docker pull mdillon/postgis:11
  docker pull mdillon/postgis:11
  docker volume create postgis_files
  docker volume create postgis_files
  docker run -d --name postgis -v postgis_files:/var/lib/postgresql/data \
  docker run -d --name postgis -v postgis_files:/var/lib/postgresql/data \
   -e PGDATA=/var/lib/postgresql/data -e POSTGRES_PASSWORD='''secret''' mdillon/postgis:11
   -e PGDATA=/var/lib/postgresql/data -e POSTGRES_PASSWORD='''secret''' mdillon/postgis:11


Run psql to talk to the database;  
Run psql to talk to the database;  
I generally have psql installed on the host and run it directly but you might not want to do that.


  docker exec -it postgis /usr/bin/psql -U postgres
  docker exec -it postgis /usr/bin/psql -U postgres


This command actually starts a second container and links to the first one to do the same thing - give you psql.
Docker makes setting up PostGIS shockingly easy. You'll want pgadmin to maintain it.


docker run -it --link postgis:postgres --rm postgres \
==== ArcGIS and PostGIS ====
    sh -c 'exec psql -h "$POSTGRES_PORT_5432_TCP_ADDR" -p "$POSTGRES_PORT_5432_TCP_PORT" -U postgres -W'


Either way once you get a prompt, you can do the quick test to see what's installed,
After completing the PostGIS setup, I can now add PostGIS layers directly into ArcMap '''for read-only access'''.
postgres=# '''SELECT postgis_full_version();'''
I do this by creating a "Database Connection" in ArcCatalog; then I can see the layers in PostGIS and just drag them straight into ArcMap.  
I cannot '''EDIT''' them though, ArcMap does not support that directly. It might if you use the Data Interop extension but I don't have that.
POSTGIS="2.5.1 r17027" [EXTENSION] PGSQL="110" GEOS="3.5.1-CAPI-1.9.1 r4246" PROJ="Rel. 4.9.3, 15 August 2016"
GDAL="GDAL 2.1.2, released 2016/10/24" LIBXML="2.9.4" LIBJSON="0.12.1" LIBPROTOBUF="1.2.1" TOPOLOGY RASTER
(1 row)


Docker makes setting up PostGIS shockingly easy. You'll want pgadmin to maintain it.
If you have an ArcGIS Server license you can enable access to PostGIS in the PostgreSQL server. I can't afford the license fees.


=== ArcGIS SDE in PostgreSQL ===
=== pgadmin ===


Requirements: https://desktop.arcgis.com/en/system-requirements/latest/database-requirements-postgresql.htm
Until version 4, pgadmin was a desktop app. Now it's a javascript app that can run still from desktop but I have it installed as a '''docker''' on [[Bellman]].
It wants Ubuntu 16.04.3
PostgreSQL 10.3 and PostGIS 2.4


That's correct, it REQUIRES PostGIS. This hurts my brain.
I use this container: https://hub.docker.com/r/dpage/pgadmin4


This tells me to install a DLL which is stupid since I am running on Linux
=== WFS-T ===
https://desktop.arcgis.com/en/arcmap/latest/manage-data/gdbs-in-postgresql/get-started-gdb-in-postgresql.htm


I think I need this
Goal: Set up an example to allow storing dots from ol-react to a [[PostGIS]] instance and to an [[ArcGIS Enterprise instance]].
https://desktop.arcgis.com/en/arcmap/latest/manage-data/databases/add-the-st-geometry-type-to-a-postgresql-database.htm
I don't care if they are WFS-T services or not as long as my web map works correctly. For PostGIS it looks easiest to use GeoServer and WFS-T.
That's what set me on this whole docker-compose path; I can now set up the server infrastructure in 10 minutes.


=== pgadmin ===
# QGIS
* Create an empty "web_markers" point layer in temp memory in QGIS, then use the QGIS database tool to export it to PostGIS.
* Remove the PostGIS based layer from QGIS.
# GeoServer
* Create a Workspace. Enable WFS on the workspace.
* Create a Store. Connect it to PostGIS using the gis_owner role and password, so that it has full read/write access on PostGIS.
* Make sure WFS is enabled and Service Level is set to Transactional or Complete, (Services->WFS)
* Publish sure web_markers in Layers.
* Created a role "PUBLIC_ACCESS" and give it READ and WRITE access to the web_markers layer.
* Create a "markers" user with password and assign the PUBLIC_ACCESS role to it.
# In a browser,
* test with this URL: https://maps.wildsong.biz/geoserver/wfs?service=wfs&version=1.2.0&request=GetCapabilities which gives results for every layer
* and https://maps.wildsong.biz/geoserver/wfs?service=wfs&request=DescribeFeatureType&version=1.1.0&typeName=clatsop-wfs:web_markers with results only for that layer


pgadmin used to be a desktop app, now it's a javascript app that can run still from desktop but I have it installed as a '''docker''' on [[Bellman]].
In the GetCapabilities request there should be an operation name = "Transaction" section when transactions are enabled.


sudo mkdir /var/lib/docker/pgadmin
[[File:geoserver_data_security.png]]


docker pull dpage/pgadmin4
In '''QGIS'''
docker volume create pgadmin_files
# I did "Layer->Add Layer->Add WFS Layer"
# For "connection details" I used the URL https://maps.wildsong.biz/geoserver/wfs and left the authentication section alone.
# then I just selected the web_markers layer and clicked "Add" and "Closed".


docker run -d -p 8889:80 --name=pgadmin4 -v pgadmin_files:/var/lib/pgadmin \
The parts of OpenLayers 3 that we need to support feature editing through WFS-T are:
  -e "[email protected]" -e "PGADMIN_DEFAULT_PASSWORD=''secretpassword''" \
  dpage/pgadmin4


== Using Docker Compose ==
ol.interaction.Draw
ol.interaction.Modify
ol.format.WFS


=== Installing Docker Compose ===
==== References that I found last night: ====


'''Compose''' is not part of '''Docker engine''', it's installed separately.
Geoserver docs https://docs.geoserver.org/latest/en/user/services/wfs/reference.html


''Side note, on Bellman I installed Docker engine using the Docker repository for the ''latest stable'' version.'' Currently I have 18.09.02.
An article on Medium https://medium.com/@goldrydigital/wfs-t-with-openlayers-3-16-6fb6a820ac58


To install Docker Compose on Debian, see https://docs.docker.com/compose/install/#install-compose
Discussion re an example https://github.com/openlayers/openlayers/issues/8854
for example,
curl -L https://github.com/docker/compose/releases/download/1.24.0-rc1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
docker-compose --version
'''docker-compose version 1.24.0-rc1, build 0f3d4dda'''


=== Compose file ===
Boundless https://boundlessgeo.com/2014/06/openlayers-editing-wfs-t/
and http://suite.opengeo.org/opengeo-docs/sysadmin/wfst/index.html


Now that I have tested Geoserver, PostGIS, PostgreSQL, and pgadmin separately I am ready to roll them together with one Docker Compose file. Here is my file "docker-compose.yml", so far.
Stack Exchange https://gis.stackexchange.com/questions/141031/getting-transaction-support-enabled-in-wfs-on-geoserver-boundless-opengeosuite


<pre>
=== Serving MVT Vector Tiles ===
# Match this to your docker engine, I am at 18.09.02 in Debian 9
version: '3.7'


services:
MVT = Mapbox Vector Tiles
  db:
    image: mdillion/postgis:11
    environment:
      PGDATA: /var/lib/postgresql/data
      POSTGRES_PASSWORD: ''your_secret_here''
      #POSTGRES_USER:
      #POSTGRES_DB:
      #POSTGRES_INITDB_ARGS:
      #POSTGRES_INITDB_XLOGDIR:
    ports:
    - "5432:5432"
    volumes:
    - "postgis_files:/var/lib/postgresql/data"
  # I will want this behind an nginx reverse proxy instead of exposing the port
  geoserver:
    image: geoceg/geoserver:latest
    ports:
    - "8888:8080"


  dpage/pgadmin4
You need to add a plugin to GeoServer for this to work.
I had to create a new set up for GeoServer so that I could add plugins to the Docker image.


  pgadmin4:
https://docs.geoserver.org/latest/en/user/extensions/vectortiles/install.html
    image: dpage/pgadmin4
    environment:
      PGADMIN_DEFAULT_EMAIL: ''your_login@somewhere''
      PGADMIN_DEFAULT_PASSWORD=''your_password''
    ports:
    - "8889:80"
    volumes:
    - pgadmin_files:/var/lib/pgadmin
</pre>


==== Fire it up ====
Once it's installed you can go look under Tile Layers at layers you have published
and pull up the "Tile Caching" tab. Then you should see Tile Image Formats as a list
that now includes "application/vnd.mapbox-vector-tile", turn that one one (and any
others you wish to use of course).


docker-compose up -d
If you do a preview of the layer you can select the PBF entries to test it and to find the correct URL to use in OpenLayers (or whereever...).


In this case I have mapped the standard postgres port to the same port on the host,
My (currently firewalled) test of Clatsop county is here: https://geoserver.wildsong.biz/geoserver/gwc/demo/clatsop_wm:taxlots?gridSet=EPSG:900913&format=application/vnd.mapbox-vector-tile
There is no instance of Postgres already running here.
Then I can connect to it as if it were running locally with the psql command.


From the psql prompt, I can check out how the postgis set up went with
Internally it looks like it's using this: https://geoserver.wildsong.biz/geoserver/gwc/service/wmts?REQUEST=GetTile&SERVICE=WMTS&VERSION=1.0.0&LAYER=clatsop_wm:taxlots&STYLE=&TILEMATRIX=EPSG:900913:10&TILEMATRIXSET=EPSG:900913&FORMAT=application/vnd.mapbox-vector-tile&TILECOL=161&TILEROW=366


\c geonode_imports
What's WMTS? https://en.wikipedia.org/wiki/Web_Map_Tile_Service
select postgis_full_version();
  POSTGIS="2.5.1 r17027" [EXTENSION] PGSQL="110" GEOS="3.5.1-CAPI-1.9.1 r4246" PROJ="Rel. 4.9.3, 15 August 2016"
GDAL="GDAL 2.1.2, released 2016/10/24" LIBXML="2.9.4" LIBJSON="0.12.1" LIBPROTOBUF="1.2.1" TOPOLOGY RASTER
(1 row)


This looks reasonably complete and reasonably up to date.
== Using Docker Compose ==


You can run an interactive shell and look around.
Using Compose is AWESOME, it allows me to group services together and hook them up.
I have successfully started and stopped the whole thing several times now. It tears down
(basically throws everything away) your containers when you say "docker-compose down"
but since I have persisted the data in volumes, everything comes right back online with
"docker-compose up"! Did I say "awesome" already?


docker exec -it postgis /bin/bash
=== Installing Docker Compose ===


This works too.
'''Compose''' is not part of '''Docker engine''', it's installed separately.


docker exec -it postgis psql -U postgres
''Side note, on Bellman I installed Docker engine using the Docker repository for the ''latest stable'' version.'' Currently I have 18.09.02.


=== Dealing with passwords ===
To install Docker Compose on Debian, see https://docs.docker.com/compose/install/#install-compose
for example,
curl -L https://github.com/docker/compose/releases/download/1.24.0-rc1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
docker-compose --version
'''docker-compose version 1.24.0-rc1, build 0f3d4dda'''


I don't want passwords to be coded into my Docker images, so how do I get them out of there?
=== Configure everything ===
I know I am supposed to put them into environment settings but then how do I load the environment?


== Setting up GeoServer on Linux ==
My compose file includes all services to run GeoServer, including GeoServer itself, [[GeoWebCache]], PostGIS/PostgreSQL, PGAdmin4, and nginx.


The downloadable binary for Linux includes jetty; this precludes the need for Tomcat.
Refer to its github repo at https://github.com/Geo-CEG/geoserver-compose for more information.
Indeed this is great for testing on a desktop but for any server application, I find that
geoserver/java will eat ram and crash after a few days.  


So I install Tomcat and expand the settings to give it lots of space.
git clone https://github.com/Geo-CEG/geoserver-compose.git geoserver
cd geoserver
# Read the README.md file.
# Copy files into the right places. dotenv.sample -> .env
# Edit .env


=== Tomcat 8 ===
==== Fire it up ====


I used to install Oracle manually (direct tarball download) and then was forced to install Tomcat
docker-compose up -d
from source, too. Otherwise doing "apt-get install tomcat7" got me an apt packaged outdated java.


Now I first set up the Oracle repo for Java and install it first so that everything can load from apt.
I have mapped the standard postgres port to the same port on the host,
based on the assumption there is no instance of PostgreSQL already running on the host.
I can connect to PostgreSQL as if it were running locally with the psql command; like this: psql -U postgres -h localhost


Fix for Debian 8.5, to get the add-apt-repository command (which is an Ubuntu thing)
From the psql prompt, I can check out how the postgis set up went with
cd /tmp
wget http://blog.anantshri.info/content/uploads/2010/09/add-apt-repository.sh.txt
mv add-apt-repository.sh.txt /usr/local/sbin
chmod 755 /usr/local/sbin/add-apt-repository


Now I can install Oracle version 8 JDK as an apt package.
select postgis_full_version();
POSTGIS="2.5.1 r17027" [EXTENSION] PGSQL="110" GEOS="3.5.1-CAPI-1.9.1 r4246" PROJ="Rel. 4.9.3, 15 August 2016"
GDAL="GDAL 2.1.2, released 2016/10/24" LIBXML="2.9.4" LIBJSON="0.12.1" LIBPROTOBUF="1.2.1" TOPOLOGY RASTER
(1 row)


apt-get install python-software-properties
This looks good.
add-apt-repository ppa:webupd8team/java
I can test the [https://maps.wildsong.biz/ nginx home page] and geoserver and geowebcache and pgadmin4 at this point and they all work, too.
apt-get update
apt-get install oracle-java8-installer


Now since I have Oracle java installed as a package, I can install the tomcat8 package
You can also use "docker inspect" for example
and it won't try to install whatever open sourced java it ordinarily installs. It will
be happy to use Oracle's version.


Startup of tomcat fails at this point because JAVA_HOME is not set.
docker inspect geoserver-db | grep VERSION
They still use the old /etc/init.d /etc/default startup files, so I put my custom settings at the end of
      "GOSU_VERSION=1.11",
/etc/default/tomcat8:
      "PG_VERSION=11.2-1.pgdg90+1",
      "POSTGIS_VERSION=2.5.1+dfsg-1.pgdg90+1"


JAVA_HOME="/usr/lib/jvm/java-8-oracle"
=== Dealing with passwords ===
GEOCEG_HOME="/home/geoceg"
GEOSERVER_HOME="$GEOCEG_HOME/geoserver"


JAVA_OPTS="-Djava.awt.headless=true -Xmx768m -Xrs -XX:PerfDataSamplingInterval=500 \         
I keep the initial passwords (for example, for Postgres user) in the .env file; again, see the README.md
  -XX:MaxPermSize=256m -Dorg.geotools.referencing.forceXY=true \                                     
  -DGEOSERVER_DATA_DIR=$GEOCEG_HOME/geoserver/data \                                                 
  -DGEOWEBCACHE_DATA_DIR=$GEOCEG_HOME/geowebcache \                                                   
  -DGEOEXPLORER_DATA=$GEOCEG_HOME/geoexplorer \                                                       
  "


Then start it up, fix any problems, try try again
== Accessing GeoServer WFS from ArcGIS Pro ==
systemctl start tomcat8


At this point there should be a servlet container running at http://dart.wildsong.biz:8080/
There is probably an expensive extension (Interop?) for ArcMap to use WFS but I don't have it.
AGS appears to have support; I am trying it out.


'''How big is my heap now?'''
As is traditional for Esri I had to loosen security settings on GeoServer. Now anyone can see the services.
Write access is still restricted.


java -XX:+PrintFlagsFinal -version 2>&1 | grep -i MaxHeapSize
I followed instructions to [https://pro.arcgis.com/en/pro-app/help/data/services/add-wfs-services.htm#GUID-FC7E9995-1105-4E11-85E3-910C81F8517B create a WFS server connection] then I [https://pro.arcgis.com/en/pro-app/help/data/services/use-wfs-services.htm#ESRI_SECTION2_0167C63B86F9484D9619953D6A2D8723 viewed WFS layers in the Contents Pane]. See View->Catalog Pane->Servers


=== Geoserver 2.9.1 ===
== Setting up GeoServer on Linux ==


Download stable release of the WAR file from http://geoserver.org/ -- Today that would be here:
I used to have some instructions in this page to help me set up GeoServer directly in Linux but now that I know how to use Docker, I deleted them. If you really feel the need to do it the hard way, use View History up there in the tabs and check for the version older than Feb 19 2019.


cd ~/Downloads
== Getting data into GeoServer ==
wget http://downloads.sourceforge.net/project/geoserver/GeoServer/2.9.1/geoserver-2.9.1-war.zip?r=http%3A%2F%2Fgeoserver.org%2Frelease%2F2.9.1%2F&ts=1473614756&use_mirror=superb-sea2
unzip geoserver*


Based on the settings I used in /etc/default/tomcat8 above
=== Adding raster files ===
I need to install the WAR file at /var/lib/tomcat8/webapps/ and the rest of the files go in
/home/geoceg
Create the folders first, when you move the WAR file it will be deployed automatically and start searching
for the folders.


mkdir /home/geoceg
https://0-proquest.safaribooksonline.com.marinet.lib.ca.us/book/gis/9781788297370/adding-your-data/a96658aa_e2d4_4f15_a2c6_9edfa3a47e81_xhtml?query=((geoserver)+AND+(raster))#snippet
chdir /home/geoceg
mkdir -p geoexplorer geowebcache geoserver/data
chown -R tomcat8.wildsong /home/geoceg/*


mv geoserver.war /var/lib/tomcat8/webapps
[https://www.e-education.psu.edu/geog585/node/710 Walkthrough: Creating tiles with GeoServer] at Penn State.
chown root.root /var/lib/tomcat8/webapps/geoserver.war
systemctl restart tomcat8


If deployment succeeds then some files will be created in /home/geoceg/geoserver for you,
I want to do this so I can test WPS geoprocessing, not because I think it's the best way to distribute raster data, okay?
and you should be able to see an empty geoserver at http://dart.wildsong.biz:8080/geoserver/


As you work on getting everything correct, the log file /var/lib/tomcat8/logging/catalina.out will be most helpful.
# I downloaded some data from DOGAMI months ago, a portion of LiDAR for Astoria. So I have a georeferenced TIFF file.
# Copy the .tif and .tfw files up onto GeoServer, to the Docker volume; on my server /home/docker/volumes/geoserver_data/_data/clatsop/
# Data (in left bar) -> Stores -> Add new store
# Raster Data Sources -> GeoTIFF
# I chose the clatsop workspace
# I used "Browse" to create the URL: file:clatsop/irving.tif
# Save
# This takes me to a New Layer page showing the layer name "irving" and I click on "Publish".


I accepted the rest of the defaults that GeoServer filled in for me.


'''Change admin password now.'''
I did a preview of the layer and it came up blank. Then I found the new layer in "Tile Layers" under "Tile Caching" and told it to build tiles for zoom levels 4-19 and waited for it to complete (5 minutes or so). ''NOW''... I still get a blank preview map! "Scale 1:NaN" is wrong. '''WRONG place'''!


You have to look up the one that was created for you when geoserver.war ran the first time. It is in geoserver/data/security/masterpw.info Login as root in the browser and change it now.
To preview, Tile Caching -> Tile Layers -> select the layer -> Select a preview mode (PNG for example) then a previewer pops up.


Next I have to set up my own workspace to serve my PostGIS data.
[[Image:Geoserver_tile_preview.png]]


== Connecting GeoServer to PostGIS ==
== Using GeoServer with PostGIS ==


Some notes on using WFS-T http://blogs.law.harvard.edu/jreyes/2007/08/03/geotools-wfs-t-update-request/
Some notes on using WFS-T http://blogs.law.harvard.edu/jreyes/2007/08/03/geotools-wfs-t-update-request/
Line 350: Line 304:
So for example, you can create a workspace for Oregon and then put all your state-level data into stores that are in the Oregon workspace.
So for example, you can create a workspace for Oregon and then put all your state-level data into stores that are in the Oregon workspace.


=== OpenStreetMap ===
== Queries in GeoServer ==


I have already set up the [[OpenStreetMap]] data for western US in PostGIS. There is a nice page to get started here: http://blog.geoserver.org/2009/01/30/geoserver-and-openstreetmap/
=== CQL ===


You will need SLD files, this one is uselessly outdated github.com/mitchelljj/openstreetmap-sld.git
You can add CQL filters to a REST URL to filter on attributes in a WFS service, you can use spatial operators too.
Trying https://github.com/ROGUE-JCTD/geoserver-osm-styles.git


Here is what I have so far,
http://geoserver.wildsong.biz/geoserver/wfs?service=WFS&version=1.0.0&request=GetFeature&typeName=clatsop_wm:county_boundary&maxFeatures=50&outputFormat=application/json&CQL_FILTER=INTERSECTS(geom,collectGeometries(queryCollection('clatsop_wm:parks','geom','IN(''parks.1'')')))
http://dart.wildsong.biz:8080/geoserver/osm/wms?service=WMS&version=1.1.0&request=GetMap&layers=osm:planet_osm_roads&styles=&bbox=-1.4011076E7,3631139.0,-1.1346024E7,6468468.0&width=721&height=768&srs=EPSG:3857&format=application/openlayers


=== Other PostGIS data ===


To create a connection to data in your PostGIS server you have to know what's in there. You can poke around with psql if you are text kind of guy or you can use pgAdmin III, like so:
See the docs [https://docs.geoserver.org/stable/en/user/filter/ecql_reference.html#filter-ecql-reference]


[[Image:pgAdmin_III.png|thumb]]
https://github.com/mappingmashups/simple-things-on-maps


[[Category:GIS]]
[[Category:GIS]]
[[Category:OpenLayers]]
[[Category:OpenLayers]]

Latest revision as of 21:56, 4 December 2019

Overview

GeoServer is what I used with PostgreSQL and PostGIS for the Mapping Vietnam project.

Home page: http://geoserver.org/ where they say "GeoServer is a Java-based software server that allows users to view and edit geospatial data. Using open standards set forth by the Open Geospatial Consortium (OGC), GeoServer allows for great flexibility in map creation and data sharing."

The crucial feature for me is that it allows edits via #WFS-T. That means I can hook up OpenLayers web clients to a database and allow them to create and edit data.

History

  • 2019 Mar -- Migrated to Docker Compose.
  • 2016 Sep -- updated Dart with 2.9.1 (latest stable release)
  • 2012 Sep -- 2.2 installed on Kilchis and Dart.
  • 2011 Oct -- I am working with 2.1.2 now on HuPI
  • 2009 Feb 06 -- I decided to take a crack at installing GeoServer 1.7.2 today.

Example GeoServer site (not mine!)

The Portland TriMet system map is on GeoServer via the OpenGeo stack.

This is from the Portland Trimet site... GeoServer, OpenLayers, TileCache, PostgreSQL, PostGIS, GDAL, Extjs, Freemarker, Solr, Antlr, Balance Ant, Http Client, Tomcat, Apache, and CentOS are the underlying technologies used on this application. We're indebted to the contributors of these (and many other: eclipse, firefox and firebug to name a few) open source projects for sharing their efforts and expertise.

Some GeoServer Capabilities

  • WCS = Web Coverage Service = queryable feature data (OGC)
  • WFS = Web Feature Service = vector data (OGC)
  • WMS = Web Map Service = delivers rasters (not tiles) (OGC)
  • TMS = Tile map service = delivers raster tiles (OSGEO)
  • WMS-C = Web Map Service - Cached = WMS with tile caching (OSGEO draft)
  • WMTS = Web Map Tile service (OGC)

I think WCS can return features that are related from several feature classes whereas WFS returns features from one class only??

Map vs feature services

What if you want features to overlay a map but want symbology defined by the server? You define styles and then pick the correct encoding.

With WFS there are several GML flavours, GeoJSON, shapefiles and CSV. None of these work for me because they only encode the geography and not the visual properties. I probably want to use a WMS encoded with KML.

Lew's approach is to convert the KML into a custom JSON format on the server for transfer. There must be a better way than that. But it has to be compatible with the Google Maps Android API too.

The official way to put markers and shapes onto a Google map is via their API. I don't want to go the route of putting shapes onto the screen ignoring the API because I hate having to do all the projection and transformation stuff on my own.

Being able to directly read GPX files would be a good thing.

Tiles

If you are implementing a tile-based client you should probably use TMS or maybe WMTS. WMS-C was a OSGEO draft. WMTS is more complex so use TMS unless you really need WMTS features.

On the server side for performance and the best cartography you'd probably be better off pre-rendering and caching all the tiles. What's the best way to do that? Tilemill or gdal2tiles ? What's the best way to serve the prerendered tiles? TileCache? Or just use a web server (Apache)?

TMS reference implementation: see http://TileCache.org/

Geoserver in Docker

The docker-compose set up includes geoserver, geowebcache, postgis, and pgadmin4. See the full project on github, https://github.com/Wildsong/docker-geoserver

I had a reverse proxy built into the compose setup but realized I needed a proxy for the other services running on Bellman so now I have a generic proxy running in its own container. Because GeoServer is tucked behind a proxy, it is accessible "everywhere" (currently it's behind my Firewall settings but that's a different story).

PostGIS

I keep more PostGIS notes here: PostGIS.

See https://hub.docker.com/r/mdillon/postgis I will probably stop using this container, because I want the bleeding edge in my development server. (I live for pain) I can probably even go to PostGIS 3.0 now!!

From Postgis.org today: Although this release will work for PostgreSQL 9.4 and above, to take full advantage of what PostGIS 2.5 offers, you should be running PostgreSQL 11beta4+ and GEOS 3.7.0 which were released recently. Best served with PostgreSQL 11 beta4 and pgRouting 2.6.1.

In my current Docker, I can see using "docker inspect geoserver-db" that PostgreSQL is at 11.2 and from psql I can see GEOS is at 3.7.

postgres=# SELECT postgis_full_version();
POSTGIS="2.5.1 r17027" [EXTENSION] PGSQL="110" GEOS="3.5.1-CAPI-1.9.1 r4246" PROJ="Rel. 4.9.3, 15 August 2016" GDAL="GDAL 2.1.2, released 2016/10/24" LIBXML="2.9.4" LIBJSON="0.12.1" LIBPROTOBUF="1.2.1" RASTER
(1 row)

See also its parent https://hub.docker.com/_/postgres/

You can run the database independent of the compose configuration to test it. These commands put the data and config files outside of the container, but still in a docker volume.

docker pull mdillon/postgis:11
docker volume create postgis_files
docker run -d --name postgis -v postgis_files:/var/lib/postgresql/data \
  -e PGDATA=/var/lib/postgresql/data -e POSTGRES_PASSWORD=secret mdillon/postgis:11

Run psql to talk to the database; I generally have psql installed on the host and run it directly but you might not want to do that.

docker exec -it postgis /usr/bin/psql -U postgres

Docker makes setting up PostGIS shockingly easy. You'll want pgadmin to maintain it.

ArcGIS and PostGIS

After completing the PostGIS setup, I can now add PostGIS layers directly into ArcMap for read-only access. I do this by creating a "Database Connection" in ArcCatalog; then I can see the layers in PostGIS and just drag them straight into ArcMap. I cannot EDIT them though, ArcMap does not support that directly. It might if you use the Data Interop extension but I don't have that.

If you have an ArcGIS Server license you can enable access to PostGIS in the PostgreSQL server. I can't afford the license fees.

pgadmin

Until version 4, pgadmin was a desktop app. Now it's a javascript app that can run still from desktop but I have it installed as a docker on Bellman.

I use this container: https://hub.docker.com/r/dpage/pgadmin4

WFS-T

Goal: Set up an example to allow storing dots from ol-react to a PostGIS instance and to an ArcGIS Enterprise instance. I don't care if they are WFS-T services or not as long as my web map works correctly. For PostGIS it looks easiest to use GeoServer and WFS-T. That's what set me on this whole docker-compose path; I can now set up the server infrastructure in 10 minutes.

  1. QGIS
  • Create an empty "web_markers" point layer in temp memory in QGIS, then use the QGIS database tool to export it to PostGIS.
  • Remove the PostGIS based layer from QGIS.
  1. GeoServer
  • Create a Workspace. Enable WFS on the workspace.
  • Create a Store. Connect it to PostGIS using the gis_owner role and password, so that it has full read/write access on PostGIS.
  • Make sure WFS is enabled and Service Level is set to Transactional or Complete, (Services->WFS)
  • Publish sure web_markers in Layers.
  • Created a role "PUBLIC_ACCESS" and give it READ and WRITE access to the web_markers layer.
  • Create a "markers" user with password and assign the PUBLIC_ACCESS role to it.
  1. In a browser,

In the GetCapabilities request there should be an operation name = "Transaction" section when transactions are enabled.

In QGIS

  1. I did "Layer->Add Layer->Add WFS Layer"
  2. For "connection details" I used the URL https://maps.wildsong.biz/geoserver/wfs and left the authentication section alone.
  3. then I just selected the web_markers layer and clicked "Add" and "Closed".

The parts of OpenLayers 3 that we need to support feature editing through WFS-T are:

ol.interaction.Draw ol.interaction.Modify ol.format.WFS

References that I found last night:

Geoserver docs https://docs.geoserver.org/latest/en/user/services/wfs/reference.html

An article on Medium https://medium.com/@goldrydigital/wfs-t-with-openlayers-3-16-6fb6a820ac58

Discussion re an example https://github.com/openlayers/openlayers/issues/8854

Boundless https://boundlessgeo.com/2014/06/openlayers-editing-wfs-t/ and http://suite.opengeo.org/opengeo-docs/sysadmin/wfst/index.html

Stack Exchange https://gis.stackexchange.com/questions/141031/getting-transaction-support-enabled-in-wfs-on-geoserver-boundless-opengeosuite

Serving MVT Vector Tiles

MVT = Mapbox Vector Tiles

You need to add a plugin to GeoServer for this to work. I had to create a new set up for GeoServer so that I could add plugins to the Docker image.

https://docs.geoserver.org/latest/en/user/extensions/vectortiles/install.html

Once it's installed you can go look under Tile Layers at layers you have published and pull up the "Tile Caching" tab. Then you should see Tile Image Formats as a list that now includes "application/vnd.mapbox-vector-tile", turn that one one (and any others you wish to use of course).

If you do a preview of the layer you can select the PBF entries to test it and to find the correct URL to use in OpenLayers (or whereever...).

My (currently firewalled) test of Clatsop county is here: https://geoserver.wildsong.biz/geoserver/gwc/demo/clatsop_wm:taxlots?gridSet=EPSG:900913&format=application/vnd.mapbox-vector-tile

Internally it looks like it's using this: https://geoserver.wildsong.biz/geoserver/gwc/service/wmts?REQUEST=GetTile&SERVICE=WMTS&VERSION=1.0.0&LAYER=clatsop_wm:taxlots&STYLE=&TILEMATRIX=EPSG:900913:10&TILEMATRIXSET=EPSG:900913&FORMAT=application/vnd.mapbox-vector-tile&TILECOL=161&TILEROW=366

What's WMTS? https://en.wikipedia.org/wiki/Web_Map_Tile_Service

Using Docker Compose

Using Compose is AWESOME, it allows me to group services together and hook them up. I have successfully started and stopped the whole thing several times now. It tears down (basically throws everything away) your containers when you say "docker-compose down" but since I have persisted the data in volumes, everything comes right back online with "docker-compose up"! Did I say "awesome" already?

Installing Docker Compose

Compose is not part of Docker engine, it's installed separately.

Side note, on Bellman I installed Docker engine using the Docker repository for the latest stable version. Currently I have 18.09.02.

To install Docker Compose on Debian, see https://docs.docker.com/compose/install/#install-compose for example,

curl -L https://github.com/docker/compose/releases/download/1.24.0-rc1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
docker-compose --version
docker-compose version 1.24.0-rc1, build 0f3d4dda

Configure everything

My compose file includes all services to run GeoServer, including GeoServer itself, GeoWebCache, PostGIS/PostgreSQL, PGAdmin4, and nginx.

Refer to its github repo at https://github.com/Geo-CEG/geoserver-compose for more information.

git clone https://github.com/Geo-CEG/geoserver-compose.git geoserver
cd geoserver
# Read the README.md file.
# Copy files into the right places. dotenv.sample -> .env
# Edit .env

Fire it up

docker-compose up -d

I have mapped the standard postgres port to the same port on the host, based on the assumption there is no instance of PostgreSQL already running on the host. I can connect to PostgreSQL as if it were running locally with the psql command; like this: psql -U postgres -h localhost

From the psql prompt, I can check out how the postgis set up went with

select postgis_full_version();
POSTGIS="2.5.1 r17027" [EXTENSION] PGSQL="110" GEOS="3.5.1-CAPI-1.9.1 r4246" PROJ="Rel. 4.9.3, 15 August 2016"
GDAL="GDAL 2.1.2, released 2016/10/24" LIBXML="2.9.4" LIBJSON="0.12.1" LIBPROTOBUF="1.2.1" TOPOLOGY RASTER
(1 row)

This looks good. I can test the nginx home page and geoserver and geowebcache and pgadmin4 at this point and they all work, too.

You can also use "docker inspect" for example

docker inspect geoserver-db | grep VERSION
     "GOSU_VERSION=1.11",
     "PG_VERSION=11.2-1.pgdg90+1",
     "POSTGIS_VERSION=2.5.1+dfsg-1.pgdg90+1"

Dealing with passwords

I keep the initial passwords (for example, for Postgres user) in the .env file; again, see the README.md

Accessing GeoServer WFS from ArcGIS Pro

There is probably an expensive extension (Interop?) for ArcMap to use WFS but I don't have it. AGS appears to have support; I am trying it out.

As is traditional for Esri I had to loosen security settings on GeoServer. Now anyone can see the services. Write access is still restricted.

I followed instructions to create a WFS server connection then I viewed WFS layers in the Contents Pane. See View->Catalog Pane->Servers

Setting up GeoServer on Linux

I used to have some instructions in this page to help me set up GeoServer directly in Linux but now that I know how to use Docker, I deleted them. If you really feel the need to do it the hard way, use View History up there in the tabs and check for the version older than Feb 19 2019.

Getting data into GeoServer

Adding raster files

https://0-proquest.safaribooksonline.com.marinet.lib.ca.us/book/gis/9781788297370/adding-your-data/a96658aa_e2d4_4f15_a2c6_9edfa3a47e81_xhtml?query=((geoserver)+AND+(raster))#snippet

Walkthrough: Creating tiles with GeoServer at Penn State.

I want to do this so I can test WPS geoprocessing, not because I think it's the best way to distribute raster data, okay?

  1. I downloaded some data from DOGAMI months ago, a portion of LiDAR for Astoria. So I have a georeferenced TIFF file.
  2. Copy the .tif and .tfw files up onto GeoServer, to the Docker volume; on my server /home/docker/volumes/geoserver_data/_data/clatsop/
  3. Data (in left bar) -> Stores -> Add new store
  4. Raster Data Sources -> GeoTIFF
  5. I chose the clatsop workspace
  6. I used "Browse" to create the URL: file:clatsop/irving.tif
  7. Save
  8. This takes me to a New Layer page showing the layer name "irving" and I click on "Publish".

I accepted the rest of the defaults that GeoServer filled in for me.

I did a preview of the layer and it came up blank. Then I found the new layer in "Tile Layers" under "Tile Caching" and told it to build tiles for zoom levels 4-19 and waited for it to complete (5 minutes or so). NOW... I still get a blank preview map! "Scale 1:NaN" is wrong. WRONG place!

To preview, Tile Caching -> Tile Layers -> select the layer -> Select a preview mode (PNG for example) then a previewer pops up.

Using GeoServer with PostGIS

Some notes on using WFS-T http://blogs.law.harvard.edu/jreyes/2007/08/03/geotools-wfs-t-update-request/

GeoServer has

  • workspaces aka namespaces
  • stores aka datastores
  • layers

These are about organizing the data accessible to GeoServer.

You store data in stores and a store has to be in a workspace. A PostGIS store connects to a database, and the tables therein become accessible as layers (once you publish them)

So for example, you can create a workspace for Oregon and then put all your state-level data into stores that are in the Oregon workspace.

Queries in GeoServer

CQL

You can add CQL filters to a REST URL to filter on attributes in a WFS service, you can use spatial operators too.

http://geoserver.wildsong.biz/geoserver/wfs?service=WFS&version=1.0.0&request=GetFeature&typeName=clatsop_wm:county_boundary&maxFeatures=50&outputFormat=application/json&CQL_FILTER=INTERSECTS(geom,collectGeometries(queryCollection('clatsop_wm:parks','geom','IN(parks.1)')))


See the docs [1]

https://github.com/mappingmashups/simple-things-on-maps