Automatic default column values
Automatic default column values allow Gismatrix to automatically populate selected attribute fields whenever a new map object is created (or when an existing object is moved while the field is still empty), using a fixed value, a spatial lookup from another map layer, or a custom SQL calculation. All evaluations run locally on your device, working instantly and reliably both online and completely offline in the field.
The purpose of this feature is to eliminate repetitive manual typing and prevent data entry errors. Whenever you draw a new hydrant, manhole, utility pole, building, or land parcel, Gismatrix can automatically pull the cadastral district code, municipality name, road segment ID, or maintenance zone from underlying or nearby layers, generate the next sequential number, or record the exact area or length of the drawn shape.
Where to configure default values and mode selection
Open Layer control, open Layer properties for your vector layer, and navigate to the Column options section. For any editable column, use the Default value mode selector to choose one of three modes:
- Static value: Enter a fixed text string, number, boolean (Yes/No) value, or the keyword
now()to automatically record the exact current date or date and time when a new record is created. - Layer lookup (Simple): A no-code visual wizard that pulls an attribute value from another open map layer or reference table based on a spatial relationship (such as largest overlap or nearest object) and an optional filter.
- Custom (SQL): A full-featured, resizable SQL editor supporting PostGIS-compatible spatial functions and
NEW.geom/NEW.pseudo-record variables.
When Layer lookup (Simple) or Custom (SQL) is selected, the text input is replaced by a rule configuration button (
Layer lookup – Simple mode
The Default value (Simple) dialog lets you set up spatial and tabular lookups in seconds without writing SQL code. Behind the scenes, Gismatrix automatically queries the local R-Tree spatial index so lookups remain instantaneous even against reference layers containing hundreds of thousands of parcels or buildings.
Configuration fields in Simple mode
- Layer / Table: Choose any open spatial vector layer or non-spatial attribute lookup table. If the source layer uses a different coordinate reference system (CRS) than the edited layer, Gismatrix automatically reprojects the geometry on the fly.
- Value column: Lists all data columns from the selected table whose data types are compatible with the target column (for example, numeric columns for numeric targets, and any non-binary column for text targets).
- Spatial relation: Defines how the matching record in the source layer is found relative to the newly drawn geometry (see the detailed table below). If either the edited layer or the selected lookup table has no geometry, Gismatrix automatically uses attribute matching (First matching record).
- Search radius (m): Displayed when Closest feature (within distance) is selected. Enter the maximum search distance in meters (e.g.,
25to snap to the nearest road centerline within 25 m). Leave it empty or set to0to find the closest feature without a distance limit. - Additional filter (SQL WHERE – optional): An optional SQL filter condition applied to the lookup table (written without the
WHEREkeyword), such asstatus = 'ACTIVE'orroad_class = 1. - Also update when geometry is modified (if empty): When checked, moving or reshaping an existing feature on the map re-evaluates the rule — strictly when the target column on that feature is still empty. Existing user-entered values are never overwritten.
Available spatial relations
| Spatial relation | Behavior and typical use case |
|---|---|
| Intersects (largest overlap) | Recommended default. Evaluates all intersecting features on the lookup layer and picks the one sharing the largest overlapping area (or longest overlapping length for lines). If a new building or parcel crosses the border between two zones or municipalities, it automatically receives the code of the zone containing its largest portion. |
| Intersects (first match) | Returns the value from the first lookup feature that touches or intersects the new geometry. Ideal for point features or non-overlapping reference polygons. |
| Is within | Returns a value only when the entire new geometry lies completely inside the lookup feature's boundary. |
| Contains | Returns the value of a lookup feature that lies completely inside the newly drawn polygon (e.g., drawing a service boundary around an existing address point). |
| Closest feature (within distance) | Finds the geometrically nearest object on the lookup layer by real-world distance (optionally bounded by Search radius (m)). Ideal for linking new service connections, streetlights, or signs to the nearest road or pipeline segment without requiring exact snapping. |
| No spatial filter / First matching record | Ignores map location and returns the first value from the lookup table matching the optional Additional filter (useful for pulling an active project code, year, or default status from a reference table). |
Testing your rule and switching to Advanced SQL
- Verify button: Validates your configuration and optional filter and evaluates a live sample value right at the current map center, allowing you to test the lookup immediately.
- Open in Advanced (SQL) button: Converts your current Simple rule into a clean, readable PostGIS-style SQL query with a single click and opens it inside the Advanced SQL editor so you can customize it further (for example, concatenating multiple columns or rounding numbers).
Custom (SQL) – Advanced mode
The Advanced — SELECT statements. Powered by Gismatrix's built-in spatial query optimizer, you can write clean, natural PostGIS-style queries using 70+ spatial functions without manual R-Tree joins — spatial index acceleration is injected automatically at execution time.
New feature variables (NEW.geom and NEW.)
Modeled after PostgreSQL/PostGIS trigger syntax, your SQL query can reference the geometry and attributes of the feature currently being created or modified via the NEW. prefix:
NEW.geom(or the layer's actual geometry column name, such asNEW.sp_geometry): Represents the geometry of the new or modified feature. Whenever the target table in yourFROMclause uses a different coordinate system than the edited layer, Gismatrix automatically transformsNEW.geominto the target table's projection before running the query.NEW.(e.g.,NEW.categoryorNEW."asset code"): References another attribute value on the same new record. Because static defaults run in Pass 1 and SQL rules run sequentially in column order during Pass 2, a later column's SQL formula can directly use values computed by earlier columns!
Editor toolbar, bottom controls, and validation
- Tables: When the editor is empty, picking a spatial table from the Tables menu inserts a complete
SELECT ... FROM ... WHERE ST_Intersects(geom, NEW.geom) ORDER BY ST_Area(ST_Intersection(geom, NEW.geom)) DESC LIMIT 1starter template pre-filled with a type-compatible column. When the editor already contains code, it inserts the table name at the cursor. - Columns, Operators, Aggregates, Functions: Searchable dropdown menus for inserting column names, SQL operators, aggregates (
MAX,COALESCE,COUNT, etc.), and spatial functions (ST_Area,ST_Length,ST_Distance,ST_DWithin, etc.). NEW.menu: ListsNEW.geomalongside all non-binary attribute columns of the edited layer (with data type icons) for one-click insertion at the cursor.- Format SQL (Beautify) & Verify: Beautify formats multi-line SQL (preserving
--and/* ... */comments). Verify checks read-only safety, validates that the returned column type is compatible with the target column (blocking raw geometryBLOBoutputs or text-into-number mismatches), and displays a live sample result evaluated at the current map center. - Value column (
t2k1): Leave set to Automatic (first column) when yourSELECTprojects a single value, or pick a specific output column/alias when your query returns multiple columns. - Also update when geometry is modified (if empty): Re-evaluates the SQL query when an existing object's geometry is moved or reshaped, filling in the column only if it is currently empty.
Practical SQL examples
1. Cadastral district with the largest overlap area:
SELECT district_code FROM cadastral_districts WHERE ST_Intersects(geom, NEW.geom) ORDER BY ST_Area(ST_Intersection(geom, NEW.geom)) DESC LIMIT 1
2. Automatically calculate the drawn polygon's area in m² (rounded to 2 decimals) without querying another table:
SELECT ROUND(ST_Area(NEW.geom), 2)
3. Next sequential record number in the table:
SELECT COALESCE(MAX(seq_no), 0) + 1 FROM service_connections
4. Combined label from the nearest road within 30 m and an earlier column NEW.type:
SELECT r.road_code || '-' || COALESCE(NEW.type, 'STD') FROM road_segments r WHERE ST_DWithin(r.geom, NEW.geom, 30) ORDER BY ST_Distance(r.geom, NEW.geom) ASC LIMIT 1
When and in what order default rules run
Automatic default values integrate seamlessly with thematic maps, map labels, the Info window, SplitView tables, and cloud synchronization across all feature creation and modification workflows:
- Drawing new objects on the map: Static defaults and
now()are evaluated first (Pass 1), followed sequentially by Simple lookups and Custom SQL queries (Pass 2). Computed values immediately update thematic map colors and labels and appear pre-filled if the attribute form opens after drawing. - Cross-Layer Copy & Paste, Append Rows, and Create Buffer: Existing mapped attribute values from the source always take priority, while default rules on the target layer automatically compute any remaining empty columns for each pasted, appended, or buffered geometry.
- Adding a blank row in Browser (Add Row): Because a newly inserted spreadsheet row has no geometry yet, static defaults and non-spatial lookup/SQL rules run immediately while geometry-based rules wait until a shape is assigned.
- Moving or reshaping existing objects (Modify / Transform): Only dynamic rules with Also update when geometry is modified (if empty) enabled are evaluated, and strictly for columns that are currently empty (
NULLor''). Both the geometry edit and the populated attribute are recorded together in a single atomic Undo step.