Skip to content

Working with Spatial Layers

Once you’ve accessed your hosted database in pgAdmin, you can start creating spatial tables, often referred to as layers. Layers are the building blocks of geospatial analysis, allowing you to store geographic features (points, lines, or polygons) along with their attributes.

These layers can then be visualized, edited, and analyzed in QGIS or other GIS tools connected to your hosted PostGIS database.


Step 1: Create a New Table

To begin, create a new table within your default database:

  1. In the Object Explorer, expand the kartoza_postgis database.

  2. Navigate to Schemas → public.

  3. Right-click the Tables folder.

  4. Select Create → Table.


Expanded Tree
Image credit: pgAdmin


Step 2: Define Table Properties

Before adding any columns, you’ll first configure the basic details of your new table.

  1. The Create Table dialog opens with the General tab already selected.

  2. Fill in the following configuration:

Property Value
Name places
Owner kartoza_postgis
Schema public
Tablespace pg_default


Table General Tab
Image credit: pgAdmin


Step 3: Add Columns

Next, define the table’s attributes (fields) that will store your data.

  1. At the top of the Create Table dialog, click the Columns tab.

  2. Use the Add Row (+) button to add attributes.

  3. Add the following fields:


    Name Data Type Length Not Null? Primary Key?
    id integer x x
    name character 256 x
    geometry geometry x


  4. Click Save.


Table Column Tab
Image credit: pgAdmin


Step 4: Define Geometry Type & SRID

By default, the geometry column does not yet have a defined geometry type or spatial reference system (SRID). You’ll use an SQL query to configure this.

  1. With the places table selected, click the Query Tool from the toolbar.


    Query Tool
    Image credit: pgAdmin


  2. Paste the following command into the SQL Editor:

    ALTER TABLE places
    ALTER COLUMN geometry TYPE geometry(Point, 4326)
    USING ST_SetSRID(geometry, 4326);
    


  3. Click Execute Query in the top toolbar, then Continue.


This command converts the geometry column to a Point geometry type using the EPSG:4326 (WGS 84) coordinate reference system.


SQL Editor
Image credit: pgAdmin


You’ve now created a spatial table in your hosted PostGIS database that can store point-based geographic features.



Next up: Learn how to connect your PostGIS database to QGIS and visualize the spatial layer you’ve just created.