Skip to main content

Exporting to PostgreSQL

Mapit GIS can export feature layers directly to a PostgreSQL database with the PostGIS extension. The export uses a direct JDBC connection from the device - no intermediate cloud relay or proxy server is required.

This is useful for pushing field-collected data into a central database for analysis, reporting, or integration with enterprise GIS workflows.

Prerequisites

Before exporting, ensure the following:

  1. PostgreSQL server is running and accessible from the device's network (Wi-Fi, mobile data, or VPN).
  2. PostGIS extension is installed on the target database (CREATE EXTENSION IF NOT EXISTS postgis;).
  3. Network access allows the device to connect to the database host and port directly.
  4. Connection details are configured in the app (see below).
tip

Since version 3.0.4, the app connects directly to PostgreSQL via JDBC. There is no need to whitelist a relay server IP address. The connection originates from the device itself.

Configuring the Connection

  1. Open Settings from the main menu.
  2. Navigate to Remote Connections → PostgreSQL Settings.
  3. Enter the connection details:
SettingDescriptionExample
HostDatabase server hostname or IP addressdb.example.com or 192.168.1.50
PortPostgreSQL port5432 (default)
UsernameDatabase usermapit_user
PasswordDatabase password
Database nameTarget databasefield_data
  1. Use the Test Connection button to verify connectivity before going into the field.
caution

Connection credentials are stored locally on the device. Ensure the database user has only the minimum privileges required - typically CREATE, INSERT, SELECT, and DROP on the target schema.

Exporting a Layer

  1. Open the Layers screen.
  2. Long-press the layer you want to export.
  3. Tap Export from the context menu.
  4. In the export destination sheet, tap Export to PostgreSQL.

Choose an Export Mode

A bottom sheet presents two options:

ModeBehaviour
OverwriteDrops the existing table (if any) and creates a new one with the exported data
AppendAdds features to an existing table, or creates the table if it does not exist
danger

Overwrite permanently deletes all existing data in the target table. Use with caution in production environments.

tip

Either option can be hidden in Settings → Export Settings if you want to prevent accidental overwrites or restrict your workflow to append-only.

Export Progress

A progress dialog displays the number of features exported. Features are sent in batches of 500 rows using multi-row INSERT statements for performance.

On completion, a confirmation message shows the table name and the total number of features exported.

Table Structure

The exported PostgreSQL table is structured as follows:

  • The table is created in the public schema with the layer's name.
  • A geometry column is added using PostGIS, with the correct geometry type and SRID.
  • All attribute columns from the GeoPackage layer are mapped to PostgreSQL data types:
GeoPackage TypePostgreSQL Type
TEXTTEXT
INTEGERBIGINT
REAL / DOUBLEDOUBLE PRECISION
BOOLEANBOOLEAN
DATEDATE
DATETIMETIMESTAMP
BLOBBYTEA

Geometry Handling

  • Simple geometries (Point, LineString, Polygon) are automatically promoted to their Multi equivalents (MultiPoint, MultiLineString, MultiPolygon) for consistency.
  • If the source layer has Z coordinates, the geometry is created with ST_Force3DZ.
  • Geometries are inserted using ST_GeomFromWKB with the appropriate SRID.
  • The SRID is derived from the layer's coordinate reference system (defaults to 4326 if unset).

Error Handling

SituationBehaviour
Connection details not configuredExport is rejected with a "configure database connection" message
Network unreachable or connection refusedExport fails with a connection error
Permission denied on databaseExport fails with an authentication or privilege error
Invalid geometry in a featureThe feature is skipped; export continues

Example Workflow

A typical field-to-database workflow:

  1. In the field: Collect features using Mapit GIS with an external GNSS receiver for high accuracy.
  2. Back at the office (or over mobile data): Open the Layers screen, long-press the layer, and export to PostgreSQL in Append mode.
  3. On the server: Query the data in QGIS, pgAdmin, or your reporting tools. The table includes full geometry and all attributes.
-- Example: View exported data in PostgreSQL
SELECT fid, name, ST_AsText(geometry) FROM tree_survey LIMIT 10;

-- Example: Count features by condition
SELECT overall_condition, COUNT(*) FROM tree_survey GROUP BY overall_condition;
tip

For recurring exports from the same layer, use Append mode and add a date column to your layer schema to distinguish between collection sessions.

tip

If you are connecting over the internet, consider using a VPN or SSH tunnel to secure the database connection. The JDBC connection is not encrypted by default unless your PostgreSQL server is configured with SSL.

note

PostgreSQL export requires the Import/Export entitlement, available on Pro and Pro+ tiers.