Types¶
This module defines the geoalchemy2.types.Geometry,
geoalchemy2.types.Geography, and geoalchemy2.types.Raster
classes, that are used when defining geometry, geography and raster
columns/properties in models.
Reference¶
- class geoalchemy2.types.CompositeType[source]¶
Bases:
sqlalchemy.sql.type_api.UserDefinedTypeA 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.- typemap = {}¶
Dictionary used for defining the content types and their corresponding keys. Set in subclasses.
- class geoalchemy2.types.Geography(geometry_type='GEOMETRY', srid=- 1, dimension=2, spatial_index=True, use_N_D_index=False, management=False, use_typmod=None, from_text=None, name=None, nullable=True)[source]¶
Bases:
geoalchemy2.types._GISTypeThe Geography type.
Creating a geography column is done like this:
Column(Geography(geometry_type='POINT', srid=4326))
See
geoalchemy2.types._GISTypefor the list of arguments that can be passed to the constructor.- ElementType¶
alias of
geoalchemy2.elements.WKBElement
- as_binary = 'ST_AsBinary'¶
The “as binary” function to use. Used by the parent class’
column_expressionmethod.
- cache_ok = False¶
Disable cache for this type.
- from_text = 'ST_GeogFromText'¶
The
FromTextgeography constructor. Used by the parent class’bind_expressionmethod.
- name = 'geography'¶
Type name used for defining geography columns in
CREATE TABLE.
- class geoalchemy2.types.Geometry(geometry_type='GEOMETRY', srid=- 1, dimension=2, spatial_index=True, use_N_D_index=False, management=False, use_typmod=None, from_text=None, name=None, nullable=True)[source]¶
Bases:
geoalchemy2.types._GISTypeThe Geometry type.
Creating a geometry column is done like this:
Column(Geometry(geometry_type='POINT', srid=4326))
See
geoalchemy2.types._GISTypefor the list of arguments that can be passed to the constructor.If
sridis set then theWKBElementobjects resulting from queries will have that SRID, and, when constructing theWKBElementobjects, the SRID won’t be read from the data returned by the database. Ifsridis not set (meaning it’s-1) then the SRID set inWKBElementobjects will be read from the data returned by the database.- ElementType¶
alias of
geoalchemy2.elements.WKBElement
- as_binary = 'ST_AsEWKB'¶
The “as binary” function to use. Used by the parent class’
column_expressionmethod.
- cache_ok = False¶
Disable cache for this type.
- from_text = 'ST_GeomFromEWKT'¶
The “from text” geometry constructor. Used by the parent class’
bind_expressionmethod.
- name = 'geometry'¶
Type name used for defining geometry columns in
CREATE TABLE.
- class geoalchemy2.types.GeometryDump[source]¶
Bases:
geoalchemy2.types.CompositeTypeThe return type for functions like
ST_Dump, consisting of a path and a geom field. You should normally never use this class directly.- cache_ok = True¶
Enable cache for this type.
- typemap = {'geom': <class 'geoalchemy2.types.Geometry'>, 'path': ARRAY(Integer())}¶
Dictionary defining the contents of a
geometry_dump.
- class geoalchemy2.types.Raster(*args, **kwargs)[source]¶
Bases:
geoalchemy2.types._GISTypeThe Raster column type.
Creating a raster column is done like this:
Column(Raster)
This class defines the
result_processormethod, so that raster values received from the database are converted togeoalchemy2.elements.RasterElementobjects.Constructor arguments:
spatial_indexIndicate if a spatial index should be created. Default is
True.- ElementType¶
alias of
geoalchemy2.elements.RasterElement
- as_binary = 'raster'¶
The “as binary” function to use. Used by the parent class’
column_expressionmethod.
- cache_ok = False¶
Disable cache for this type.
- comparator_factory¶
- from_text = 'raster'¶
The “from text” raster constructor. Used by the parent class’
bind_expressionmethod.
- name = 'raster'¶
Type name used for defining raster columns in
CREATE TABLE.
- class geoalchemy2.types.SummaryStats[source]¶
Bases:
geoalchemy2.types.CompositeTypeDefine the composite type returned by the function ST_SummaryStatsAgg
- cache_ok = True¶
Enable cache for this type.
- class geoalchemy2.types._GISType(geometry_type='GEOMETRY', srid=- 1, dimension=2, spatial_index=True, use_N_D_index=False, management=False, use_typmod=None, from_text=None, name=None, nullable=True)[source]¶
Bases:
sqlalchemy.sql.type_api.UserDefinedTypeThe base class for
geoalchemy2.types.Geometryandgeoalchemy2.types.Geography.This class defines
bind_expressionandcolumn_expressionmethods that wrap column expressions inST_GeomFromEWKT,ST_GeogFromText, orST_AsEWKBcalls.This class also defines
result_processorandbind_processormethods. The function returned byresult_processorconverts WKB values received from the database togeoalchemy2.elements.WKBElementobjects. The function returned bybind_processorconvertsgeoalchemy2.elements.WKTElementobjects to EWKT strings.Constructor arguments:
geometry_typeThe 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
Nonethen no “geometry type” constraints will be attached to the geometry type declaration. UsingNonehere is not compatible with settingmanagementtoTrue.Default is
"GEOMETRY".sridThe SRID for this column. E.g. 4326. Default is
-1.dimensionThe dimension of the geometry. Default is
2.With
managementset toTrue, that is whenAddGeometryColumnis used to add the geometry column, there are two constraints:The
geometry_typemust not end with"ZM". This is due to PostGIS’AddGeometryColumnfailing with ZM geometry types. Instead the “simple” geometry type (e.g. POINT rather POINTZM) should be used withdimensionset to4.When the
geometry_typeends with"Z"or"M"thendimensionmust be set to3.
With
managementset toFalse(the default)dimensionis not taken into account, and the actual dimension is fully defined with thegeometry_type.spatial_indexIndicate if a spatial index should be created. Default is
True.use_N_D_indexUse the N-D index instead of the standard 2-D index.
managementIndicate if the
AddGeometryColumnandDropGeometryColumnmanagements functions should be called when adding and dropping the geometry column. Should be set toTruefor PostGIS 1.x. Default isFalse. Note that this option has no effect forgeoalchemy2.types.Geography.use_typmodBy default PostgreSQL type modifiers are used to create the geometry column. To use check constraints instead set
use_typmodtoFalse. By default this option is not included in the call toAddGeometryColumn. Note that this option is only taken into account ifmanagementis set toTrueand is only available for PostGIS 2.x.- as_binary = None¶
The name of the “as binary” function for this type. Set in subclasses.
- bind_expression(bindvalue)[source]¶
Specific bind_expression that automatically adds a conversion function
- bind_processor(dialect)[source]¶
Return a conversion function for processing bind values.
Returns a callable which will receive a bind parameter value as the sole positional argument and will return a value to send to the DB-API.
If processing is not necessary, the method should return
None.- Parameters
dialect – Dialect instance in use.
- cache_ok = False¶
Disable cache for this type.
- column_expression(col)[source]¶
Specific column_expression that automatically adds a conversion function
- comparator_factory¶
alias of
geoalchemy2.comparator.Comparator
- from_text = None¶
The name of “from text” function for this type. Set in subclasses.
- name = None¶
Name used for defining the main geo type (geometry or geography) in CREATE TABLE statements. Set in subclasses.
- result_processor(dialect, coltype)[source]¶
Return a conversion function for processing result row values.
Returns a callable which will receive a result row column value as the sole positional argument and will return a value to return to the user.
If processing is not necessary, the method should return
None.- Parameters
dialect – Dialect instance in use.
coltype – DBAPI coltype argument received in cursor.description.