This page gives an overview of the exercise of loading a file that is vectors based in a PostgreSQL/PostGIS database on November 1th, 2013 by Gerrit Hendriksen and Frank Keppel. The exercise also describes the dissemination of vector data through the internet as WMS/WFS by geoserver.
Every kind of data format that is not raster based (see for this working with netCDF's of the same workshop) is suitable. For this moment we focus on adding data to the PostGIS database using the GDAL utility OGR2OGR as well as psql (executable that comes with PostgreSQL (can be found in the bin directory of the installation directory, if the path has not been set for some reason you can navigate to C:\Program Files\PostgreSQL\9.2\bin).
As an example a dataset from pangea.de is used, for example Geographical, temperature and chemical features of sites on Bear Island and Spitsbergen. A very small data set.
The examples assume the exercise is done with a PostgreSQL/PostGIS database that is installed locally. This is done for savety issues. So the PostgreSQL/PostGIS database is installed on localhost.
host = localhost
port = 5432
username = yourusername (during installation you have entered a username)
pwd = yourpassword (during installation you have entered a password)
Furthermore the assumption is that you have a csv file with a header of exactly 1 header.
In this tutorial the following software is used:
- PostgreSQL/PostGIS (locally installed, including psql.exe)
- geoserver (locally installed)
To be done:
- convert the data into a csv file with exactly 1 header
- load the csv into a table in the postGIS database
- add geometry column
- view the data in QuantumGIS
- create a geoserver WFS from the data
- get rid of commas where they should not be (within text strings like in "Area" column in the example below)
- also get rid of special characters, like ö, ë etc.)
Eventually the csv should look like this, so you should alter this file using excel for instance.
With OGR2OGR (part of the GDAL library which is installed with QuantumGIS) you can load the csv via
Note: all notations between <> have to be changed in your names (including the <>). The advantage of ogr2ogr (which can also installed by installing GDAL) it that it creates a table in an existing database. If you don't have an existing one please follow the steps for psql.exe (click here).
Right now the data is in the table <tablename>, let's say this is temperatures.
If you start pgAdmin, you should see something like the figure below.
Open a Query window by pressing the magnifier glass with SQL in it or by pressing Ctrl + E.
press Ctrl + E to execute the query. Delete the line above and type:
press Ctrl + E to execute again. The line above converts the longitude and latitude into the geometry point (st_point) and gives it the spatial reference id (st_setsrid(makepoint statement),4326) of WGS84 (EPSG Code 4326, see http://spatialreference.org).
As you may have noticed, all columns appear as character varying in the temperatures table (see picture above). So the values have to be casted to double, this is done by ::double precision after the longitude and latitude.
Now you data is ready to be viewed in QuantumGIS and to be disseminated via geoserver. For QuantumGIS press the Add PostGIS layer button
Fill all credentials in the PostGIS connection dialog (see figure) and test the connection.
If ok then you can add the above example to QuantumGIS and you should see something like the image below.
The following steps have to be carried out to create a WFS from the data in the PostGIS database.
If everything is well, you should see the picture below if you select KML (plain) in the layer preview window.