# Types

This module defines the Column types.

The `geoalchemy2.types.Geometry`, `geoalchemy2.types.Geography`, and `geoalchemy2.types.Raster` classes are used when defining geometry, geography and raster columns/properties in models.

class geoalchemy2.types.CompositeType

  Bases: `UserDefinedType`

  A composite type used by some spatial functions.

  A wrapper for `geoalchemy2.elements.CompositeElement`, that can be used as the return type in PostgreSQL functions that return composite values.

  This is used as the base class of `geoalchemy2.types.GeometryDump`.

  class comparator_factory(expr: ColumnElement[_CT])

    Bases: `Comparator`

  typemap: dict[str, Type[TypeEngine[_T]] | TypeEngine[_T]] = {}

    Dictionary used for defining the content types and their corresponding keys. Set in subclasses.

class geoalchemy2.types.Geography(geometry_type: str | None = 'GEOMETRY', srid: int = -1, dimension: int | None = None, spatial_index: bool = True, use_N_D_index: bool = False, use_typmod: bool | None = None, from_text: str | None = None, name: str | None = None, nullable: bool = True, _spatial_index_reflected=None)

  Bases: `_GISType`

  The Geography type.

  Creating a geography column is done like this:

      Column(Geography(geometry_type='POINT', srid=4326))

  See `geoalchemy2.types._GISType` for the list of arguments that can be passed to the constructor.

  ElementType

    The element class to use. Used by the parent class’ `result_processor` method.

    alias of `WKBElement`

  as_binary: str | None = 'ST_AsBinary'

    The “as binary” function to use. Used by the parent class’ `column_expression` method.

  cache_ok: bool | None = True

    Enable cache for this type.

  from_text: str | None = 'ST_GeogFromText'

    The `FromText` geography constructor. Used by the parent class’ `bind_expression` method.

  name: str | None = 'geography'

    Type name used for defining geography columns in `CREATE TABLE`.

class geoalchemy2.types.Geometry(geometry_type: str | None = 'GEOMETRY', srid: int = -1, dimension: int | None = None, spatial_index: bool = True, use_N_D_index: bool = False, use_typmod: bool | None = None, from_text: str | None = None, name: str | None = None, nullable: bool = True, _spatial_index_reflected=None)

  Bases: `_GISType`

  The Geometry type.

  Creating a geometry column is done like this:

      Column(Geometry(geometry_type='POINT', srid=4326))

  See `geoalchemy2.types._GISType` for the list of arguments that can be passed to the constructor.

  If `srid` is set then the `WKBElement` objects resulting from queries will have that SRID, and, when constructing the `WKBElement` objects, the SRID won’t be read from the data returned by the database. If `srid` is not set (meaning it’s `-1`) then the SRID set in `WKBElement` objects will be read from the data returned by the database.

  ElementType

    The element class to use. Used by the parent class’ `result_processor` method.

    alias of `WKBElement`

  as_binary: str | None = 'ST_AsEWKB'

    The “as binary” function to use. Used by the parent class’ `column_expression` method.

  cache_ok: bool | None = True

    Enable cache for this type.

  from_text: str | None = 'ST_GeomFromEWKT'

    The “from text” geometry constructor. Used by the parent class’ `bind_expression` method.

  name: str | None = 'geometry'

    Type name used for defining geometry columns in `CREATE TABLE`.

class geoalchemy2.types.GeometryDump

  Bases: `CompositeType`

  The return type for functions like `ST_Dump`.

  The type consists in a path and a geom field. You should normally never use this class directly.

  cache_ok: bool | None = True

    Enable cache for this type.

  typemap: dict[str, _TypeEngineArgument] = {'geom': <class 'geoalchemy2.types.Geometry'>, 'path': ARRAY(Integer())}

    Dictionary defining the contents of a `geometry_dump`.

class geoalchemy2.types.Raster(spatial_index=True, from_text=None, name=None, nullable=True, _spatial_index_reflected=None)

  Bases: `_GISType`

  The Raster column type.

  Creating a raster column is done like this:

      Column(Raster)

  This class defines the `result_processor` method, so that raster values received from the database are converted to `geoalchemy2.elements.RasterElement` objects.

  Parameters:

    spatial_index – Indicate if a spatial index should be created. Default is `True`.

  ElementType

    The element class to use. Used by the parent class’ `result_processor` method.

    alias of `RasterElement`

  as_binary: str | None = 'raster'

    The “as binary” function to use. Used by the parent class’ `column_expression` method.

  cache_ok: bool | None = True

    Enable cache for this type.

  comparator_factory

    This is the way by which spatial operators and functions are defined for raster columns.

    alias of `BaseComparator`

  from_text: str | None = 'raster'

    The “from text” raster constructor. Used by the parent class’ `bind_expression` method.

  name: str | None = 'raster'

    Type name used for defining raster columns in `CREATE TABLE`.

class geoalchemy2.types.SummaryStats

  Bases: `CompositeType`

  Define the composite type returned by the function ST_SummaryStatsAgg.

  cache_ok: bool | None = True

    Enable cache for this type.

  typemap: dict[str, _TypeEngineArgument] = {'count': <class 'sqlalchemy.sql.sqltypes.Integer'>, 'max': <class 'sqlalchemy.sql.sqltypes.Float'>, 'mean': <class 'sqlalchemy.sql.sqltypes.Float'>, 'min': <class 'sqlalchemy.sql.sqltypes.Float'>, 'stddev': <class 'sqlalchemy.sql.sqltypes.Float'>, 'sum': <class 'sqlalchemy.sql.sqltypes.Float'>}

    Dictionary used for defining the content types and their corresponding keys. Set in subclasses.

class geoalchemy2.types._GISType(geometry_type: str | None = 'GEOMETRY', srid: int = -1, dimension: int | None = None, spatial_index: bool = True, use_N_D_index: bool = False, use_typmod: bool | None = None, from_text: str | None = None, name: str | None = None, nullable: bool = True, _spatial_index_reflected=None)

  Bases: `UserDefinedType`

  The base class for spatial types.

  This class defines `bind_expression` and `column_expression` methods that wrap column expressions in `ST_GeomFromEWKT`, `ST_GeogFromText`, or `ST_AsEWKB` calls.

  This class also defines `result_processor` and `bind_processor` methods. The function returned by `result_processor` converts WKB values received from the database to `geoalchemy2.elements.WKBElement` objects. The function returned by `bind_processor` converts `geoalchemy2.elements.WKTElement` objects to EWKT strings.

  Parameters:

    - geometry_type –

      The geometry type.

      > Possible values are:

      > > - `"GEOMETRY"`,

      > > - `"POINT"`,

      > > - `"LINESTRING"`,

      > > - `"POLYGON"`,

      > > - `"MULTIPOINT"`,

      > > - `"MULTILINESTRING"`,

      > > - `"MULTIPOLYGON"`,

      > > - `"GEOMETRYCOLLECTION"`,

      > > - `"CURVE"`,

      > > - `None`.

      The latter is actually not supported with `geoalchemy2.types.Geography`.

      When set to `None` then no “geometry type” constraints will be attached to the geometry type declaration.

      Default is `"GEOMETRY"`.

    - srid – The SRID for this column. E.g. 4326. Default is `-1`.

    - dimension – The dimension of the geometry. Default is `2`.

    - spatial_index – Indicate if a spatial index should be created. Default is `True`.

    - use_N_D_index – Use the N-D index instead of the standard 2-D index.

    - use_typmod – By default PostgreSQL type modifiers are used to create the geometry column. To use check constraints instead set `use_typmod` to `False`. By default this option is not included in the call to `AddGeometryColumn`. Note that this option is only available for PostGIS 2.x.

  _compiler_dispatch(**kw)

    Look for an attribute named “visit_<visit_name>” on the visitor, and call it with the same kw params.

  as_binary: str | None = None

    The name of the “as binary” function for this type. Set in subclasses.

  bind_expression(bindvalue)

    Specific bind_expression that automatically adds a conversion function.

  bind_processor(dialect)

    Specific bind_processor that automatically process spatial elements.

  cache_ok: bool | None = False

    Disable cache for this type.

  column_expression(col)

    Specific column_expression that automatically adds a conversion function.

  comparator_factory

    This is the way by which spatial operators are defined for geometry/geography columns.

    alias of `Comparator`

  from_text: str | None = None

    The name of “from text” function for this type. Set in subclasses.

  name: str | None = None

    Name used for defining the main geo type (geometry or geography) in CREATE TABLE statements. Set in subclasses.

  result_processor(dialect, coltype)

    Specific result_processor that automatically process spatial elements.

geoalchemy2.types.select_dialect(dialect_name)

  Select the dialect from its name.