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:
-
In the Object Explorer, expand the kartoza_postgis database.
-
Navigate to Schemas → public.
-
Right-click the Tables folder.
-
Select Create → Table.
Step 2: Define Table Properties¶
Before adding any columns, you’ll first configure the basic details of your new table.
-
The Create Table dialog opens with the General tab already selected.
-
Fill in the following configuration:
| Property | Value |
|---|---|
| Name | places |
| Owner | kartoza_postgis |
| Schema | public |
| Tablespace | pg_default |
Step 3: Add Columns¶
Next, define the table’s attributes (fields) that will store your data.
-
At the top of the Create Table dialog, click the Columns tab.
-
Use the Add Row (+) button to add attributes.
-
Add the following fields:
Name Data Type Length Not Null? Primary Key? id integer — x x name character 256 x geometry geometry — x -
Click Save.
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.
-
With the places table selected, click the Query Tool from the toolbar.
Image credit: pgAdmin -
Paste the following command into the SQL Editor:
ALTER TABLE places ALTER COLUMN geometry TYPE geometry(Point, 4326) USING ST_SetSRID(geometry, 4326); -
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.
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.