Configuring Geometry Types.
Table of Contents
- 1 Examples of Setting Geometry Types
- 1.1 1. Spatial table allows nil geometry, but you wish to enforce geometry creation.
- 1.2 2. Spatial table allows multi part geometry, but you wish to enforce creation of single part geometry.
- 1.3 3. The spatial engine supports multiple geometry types in a single table, for example Oracle Spatial, and you wish to limit the geometry.
- 1.4 4. You want the user to specify 2 geometries, including 1 polygon and either a point or a line.
- 1.5 5. You want the user to specify 2 geometries, including 1 polygon and either a point, line or polygon.
- 1.6 6. You want the user to specify 1 or 2 geometries, including 1 polygon and optionally a point or line.
- 1.7 7. You want the user to specify between 2 and four points.
Unless explicitly set, the types of geometry that a user can create for an entity, and also whether the user can create an entity with no geometry, is defined by the underlying spatial table. For example, the public.graffiti
table is defined with a generic geometry column as follows:
CREATE TABLE public.graffiti (
...
/* Geometry not restricted to a specific type but SRID is limited to 4326 */
GEOM geometry(Geometry,4326)
);
Note that the public.graffiti
table’s geom column allows any geometry type and is nullable (i.e., a row can be written to public.graffiti
without a geometry object written to the geom column). If you wish to write a specific geometry type to the geometry column, you can do so with the <geometry>
settings. <geometry>
settings should normally be configured to match the underlying spatial column: if the geom column was defined as geometry(Point,4326), then the associated <geometry>
setting should indicate that a single point geometry object is required.
<geometry>
settings determine three things:
The geometry types that are supported: point, linestring, and polygon.
The minimum and maximum number of each geometry type that the user can create.
The total number of geometry items (of any type) that the user can create.
Defining geometry types is done by specifying point
, linestring
, polygon
and/or geometry
items, and for each item specify the minimum
and maximum
value for each. If no point
, linestring
or polygon
setting is specified then the user will not be able to create those geometry types. If geometry
is specified as the type, the user will be able to create all geometry types.
If minimum is not specified it defaults to 0.
If maximum is not specified there will be no upper limit.
For simple geometry types, the maximum
value cannot be greater than 1. If a multi-point geometry is allowed, setting the maximum
value determines how many points per multi-point geometry. So, if maximum=2
then only multi-point geometries with 1 or 2 points can be created.
As already indicated the current public.graffiti
table allows any type of geometry to be created. The following edit configuration allows a user to create only single point geometries. (Because the underlying table’s geom column allows any geometry type, points will be able to be created.)
<edit:config id="custom.edit">
<entity>graffiti</entity>
<label>Grafitti (custom)</label>
<publish>true</publish>
<description>Report graffiti for removal</description>
<geometry>
<point maximum="1"/>
</geometry>
<parameter id="description">
<label>Description</label>
<controlType>textarea</controlType>
<column>description</column>
<hidden>false</hidden> <!-- this is not needed but is included for completeness -->
</parameter>
</edit:config>
Examples of Setting Geometry Types
What follows are some examples of how to customise geometry requirements (these should align with the underlying spatial table i.e., if a table’s geometry column can only store single points, the geometry config should align with those storage requirements):
1. Spatial table allows nil geometry, but you wish to enforce geometry creation.
<geometry minimum="1"/>
or
2. Spatial table allows multi part geometry, but you wish to enforce creation of single part geometry.
or
3. The spatial engine supports multiple geometry types in a single table, for example Oracle Spatial, and you wish to limit the geometry.
4. You want the user to specify 2 geometries, including 1 polygon and either a point or a line.
5. You want the user to specify 2 geometries, including 1 polygon and either a point, line or polygon.
6. You want the user to specify 1 or 2 geometries, including 1 polygon and optionally a point or line.
7. You want the user to specify between 2 and four points.
It's possible to specify that multiple geometry types are supported, but only one should be used at a time. That is if the user creates a polygon, then they can only create more polygons, even if the edit supports lines. This is done by setting the value for exclusive
to true
in the main geometry
tag: