Connect a Local PostGIS Database to GISMap Online
Browse spatial collections from a database on your own computer using pg_featureserv—a lightweight local bridge, with no GeoServer installation or cloud deployment.
How it works
GISMap Online in your browser → local pg_featureserv HTTP API → PostgreSQL/PostGIS. A browser cannot speak the PostgreSQL database protocol directly. pg_featureserv connects to the database and exposes permitted spatial collections through OGC API Features. Database credentials stay with the connector, not in GISMap Online.
Data returned by your local service is read by the browser. External basemap providers may receive map tile requests that reveal the viewed area; consider this when working with sensitive locations.
Before you begin
- A local PostgreSQL database with PostGIS enabled, plus a database user with read access to the spatial data you want to publish.
- A modern browser, GISMap Online, and pg_featureserv. A local service is required; GISMap Online does not install or run it for you.
psqlto verify your connection. Go is needed only if building pg_featureserv from source.
The examples use PostgreSQL on port 5435 and the HTTP connector on port 9000. Your database may use PostgreSQL’s default port, 5432. Replace the names and ports with your own. Commands use macOS/Linux shells; PowerShell alternatives are shown below.
1. Verify PostgreSQL and PostGIS
In a terminal, connect using your own username and database. Enter your database password at the prompt:
psql -h localhost -p 5435 -U YOUR_USERNAME -d YOUR_DATABASE
Check PostGIS, then list geometry columns your account can see:
SELECT PostGIS_Version();
SELECT f_table_schema, f_table_name, f_geometry_column, type, srid
FROM geometry_columns;
\q
If psql is not on your PATH, use the executable installed with PostgreSQL. The geometry list reflects permissions and may differ from collections exposed by pg_featureserv.
2. Install pg_featureserv
Download a build for your operating system and processor from the official pg_featureserv repository or its releases. Extract it, open a terminal in the application directory, and follow the included instructions. Keep accompanying assets and configuration files where the distribution expects them.
Alternatively, with Go installed, build from the extracted source directory:
go build -o pg_featureserv .
./pg_featureserv --version
On Windows, use go build -o pg_featureserv.exe . and .\pg_featureserv.exe --version. See the upstream build instructions if the source layout or dependencies differ.
3. Set database credentials locally
Use a dedicated, least-privilege database account with access only to the tables or views you intend to expose. For a local connection, set the connector’s database connection string in the same terminal where you will start the service:
export DATABASE_URL="host=localhost port=5435 dbname=YOUR_DATABASE user=YOUR_USERNAME sslmode=disable"
PowerShell:
$env:DATABASE_URL = "host=localhost port=5435 dbname=YOUR_DATABASE user=YOUR_USERNAME sslmode=disable"
sslmode=disable is for this local-only example, not an untrusted network. Never put real credentials in a GISMap Online URL, project, shared map, or public example.
Use a password file
On macOS or Linux, add an entry to ~/.pgpass using a text editor, replacing the placeholders:
localhost:5435:YOUR_DATABASE:YOUR_USERNAME:YOUR_PASSWORD
Then restrict access with chmod 600 ~/.pgpass. On Windows, the conventional file is %APPDATA%\postgresql\pgpass.conf; restrict access using Windows file permissions. See the PostgreSQL password-file documentation for escaping special characters and alternate paths. Verify password-file support and paths for your pg_featureserv build if authentication fails.
4. Bind locally and allow GISMap Online’s origin
In the same terminal, configure a loopback-only listener and permit the GISMap Online origin. Use the exact origin of the page you are testing; for a different preview site, adjust it and restart the connector.
export PGFS_SERVER_HTTPHOST="127.0.0.1"
export PGFS_SERVER_HTTPPORT="9000"
export PGFS_SERVER_CORSORIGINS="https://gismap.online"
PowerShell:
$env:PGFS_SERVER_HTTPHOST = "127.0.0.1"
$env:PGFS_SERVER_HTTPPORT = "9000"
$env:PGFS_SERVER_CORSORIGINS = "https://gismap.online"
The upstream configuration reference documents these settings and other options. Browser local-network permissions and CORS requirements vary; allow access only if you trust the site.
5. Start and test the connector
In the application directory, run ./pg_featureserv on macOS/Linux or .\pg_featureserv.exe in PowerShell. Keep the terminal open. Visit http://localhost:9000/collections.json in the same computer’s browser. You should see a JSON list of collections accessible to the connector’s database user.
Use port 9000 in GISMap Online—not the PostgreSQL port 5435. Stop the local service with Ctrl+C in its terminal when you are done.
6. Connect and browse in GISMap Online
- Open GISMap Online on the same computer and choose Data → Connect PostGIS, if available in your version.
- Enter a connection name such as
My Local PostGISand connector endpointhttp://localhost:9000. The workspace label is optional; leave the bearer token empty for this unauthenticated local example. - Choose Test and browse. Search or sort the returned collection list. Use Check spatial to look for geometry in a sample; an empty or null-geometry sample remains unknown.
- Use Save connection to keep the non-secret connection settings in this browser, if desired. A session bearer token, if used, is not saved.
One test database exposed 44 collections, including abc.latest_announced_premises, a point collection in EPSG:4326. These names and counts are specific to that database, not example data included with GISMap Online or pg_featureserv.
7. Preview and map a collection
For a collection from your own database, use Preview records if available. To inspect a small GeoJSON response directly, substitute your collection ID:
http://localhost:9000/collections/YOUR_SCHEMA.YOUR_COLLECTION/items.json?limit=100
If your GISMap Online build offers Add to map, select it on a spatial collection. The experimental implementation requests up to 1,000 features, not the entire dataset; results can be incomplete. It currently does not support authenticated map layers or automatic viewport loading, and behavior on both map engines is not yet fully verified. Previewing or discovering a collection does not itself add a map layer.
As an alternative, a GISMap Online build with a GeoJSON URL/feed tool may be able to load a suitable bounded GeoJSON URL, subject to its engine, CORS, authentication, and URL restrictions. Check the loaded feature count and do not assume a limited response is complete.
8. Reconnect and share carefully
To reconnect later, start PostgreSQL and pg_featureserv again, check permissions and browser access, then choose the saved connection. A localhost address refers to the computer running each viewer’s browser: sharing it does not give someone else access to your local database. Localhost-based map sharing and restoration are not fully supported in the current experimental integration.
Troubleshooting
- Executable not found: Run it from the extracted application directory; check its filename, executable permissions, and platform.
- Database authentication fails: Check the database port, username, database name, password-file permissions, and PostgreSQL access rules. The database password belongs to the connector, not GISMap Online.
- Connector unreachable: Confirm the process is running, check the local HTTP port, and visit
/collections.jsondirectly. Browser local-network permissions may also be required. - CORS error: Set the allowed origin to the exact GISMap Online page origin, restart the service, and review browser developer tools.
- No collections or no geometry: Check PostGIS, table/view permissions and exposed geometry. A sample without geometry does not prove a collection is nonspatial.
- Collection missing from the map: Check your deployed GISMap Online version, engine support, CORS, authentication, and whether the bounded response contains valid geometry.
- Slow or large dataset: Use a bounded query or a suitable tile service; the experimental GISMap Online integration does not yet automatically fetch by viewport.
For connector diagnostics, run ./pg_featureserv --debug (or .\pg_featureserv.exe --debug on Windows). Logs may contain sensitive details; review them before sharing.
For larger datasets
pg_tileserv is a separate local service that can serve vector tiles from PostGIS. It can complement pg_featureserv, but using it requires compatible tile-source support and its own configuration; this tutorial does not configure or verify it.