Setup Link to heading
Prerequisites Link to heading
Ubuntu OS. Install Postgres, Geoserver (independent binary), PGAdmin (optional).
Create PostGIS extension Link to heading
Download the necessary tools:
sudo apt install postgis postgresql-postgis
Run the following query with in PGAdmin or psql(command line):
CREATE EXTENSION postgis;
Import GeoJson file: Link to heading
Download the geojson file to import: https://data.gov.ie/dataset/pra-state-assets . If link is down, use this.
Install geojson to postGIS conversion tool:
sudo apt install gdal
Run the following command to import (PRA_State_Assets.geojson is the geojson filename, destination_table is the table name):
ogr2ogr -f "PostgreSQL" PG:"dbname=postgres user=postgres" "PRA_State_Assets.geojson" -nln destination_table -append
Configure Geoserver Link to heading
Filepath: /usr/share/geoserver/webapps/geoserver/WEB-INF/web.xml
- Fix CORS issues. Reference.
Uncomment these block of code:
<filter>
<filter-name>cross-origin</filter-name>
<filter-class>org.eclipse.jetty.servlets.CrossOriginFilter</filter-class>
<init-param>
<param-name>chainPreflight</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>allowedOrigins</param-name>
<param-value>*</param-value>
</init-param>
<init-param>
<param-name>allowedMethods</param-name>
<param-value>GET,POST,PUT,DELETE,HEAD,OPTIONS</param-value>
</init-param>
<init-param>
<param-name>allowedHeaders</param-name>
<param-value>*</param-value>
</init-param>
</filter>
and these:
<filter-mapping>
<filter-name>Set Character Encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
- Enable JSONP. Uncomment the following lines.
<context-param>
<param-name>ENABLE_JSONP</param-name>
<param-value>true</param-value>
</context-param>
- Update port number:
Edit /usr/share/geoserver/start.ini
file: jetty.http.port=8090
- Run Geoserver:
./usr/share/geoserver/bin/startup.sh
Link Geoserver to PostGIS Link to heading
Login with default username:
admin
password:geoserver
On the left menu, go to store > Add new store > PostGIS
Enter database details.
On the left menu, go to Layers > Add a new layer
Select the store created.
Enter the details, click compute from native bounds for the bounding boxes.
On the left menu, go to Layer Preview. Verify the layer created is there. Click on openlayers to verify it’s working.
Troubleshoot Link to heading
Peer authentication failed for user “postgres” Link to heading
Login to postgresql with psql
. For e.g. psql -h localhost -U postgres
SHOW hba_file;
The command will reveal a path to a file, edit that file with sudo (sudo -i
or sudoedit
)
In the file, replace all the peer/md5 column with trust
. Reference
Run in PGAdmin or command line, run this query before importing any data:
Compute bounding box not working in Geoserver / In Layer Preview, clicking openlayers downloads WMS file instead of opening in separate tab. Link to heading
Ensure you run CREATE EXTENSION postgis;
before importing the any data.
Try restarting postgresql too: sudo systemctl restart postgresql