Elements

class geoalchemy2.elements.HasFunction[source]

Bases: object

Base class used as a marker to know if a given element has a ‘geom_from’ function.

class geoalchemy2.elements._SpatialElement(data, srid=-1, extended=False)[source]

Bases: geoalchemy2.elements.HasFunction

The base class for public spatial elements.

Parameters:
  • data – The first argument passed to the constructor is the data wrapped by the _SpatialElement object being constructed.
  • srid – An integer representing the spatial reference system. E.g. 4326. Default value is -1, which means no/unknown reference system.
  • extended – A boolean indicating whether the extended format (EWKT or EWKB) is used. Default is False.
class geoalchemy2.elements.WKTElement(data, srid=-1, extended=False)[source]

Bases: geoalchemy2.elements._SpatialElement

Instances of this class wrap a WKT or EWKT value.

Usage examples:

wkt_element_1 = WKTElement('POINT(5 45)')
wkt_element_2 = WKTElement('POINT(5 45)', srid=4326)
wkt_element_3 = WKTElement('SRID=4326;POINT(5 45)', extended=True)
desc

This element’s description string.

geom_from = 'ST_GeomFromText'
geom_from_extended_version = 'ST_GeomFromEWKT'
class geoalchemy2.elements.WKBElement(data, srid=-1, extended=False)[source]

Bases: geoalchemy2.elements._SpatialElement

Instances of this class wrap a WKB or EWKB value.

Geometry values read from the database are converted to instances of this type. In most cases you won’t need to create WKBElement instances yourself.

If extended is True and srid is -1 at construction time then the SRID will be read from the EWKB data.

Note: you can create WKBElement objects from Shapely geometries using the geoalchemy2.shape.from_shape() function.

desc

This element’s description string.

geom_from = 'ST_GeomFromWKB'
geom_from_extended_version = 'ST_GeomFromEWKB'
class geoalchemy2.elements.RasterElement(data)[source]

Bases: geoalchemy2.elements._SpatialElement

Instances of this class wrap a raster value. Raster values read from the database are converted to instances of this type. In most cases you won’t need to create RasterElement instances yourself.

desc

This element’s description string.

class geoalchemy2.elements.CompositeElement(base, field, type_)[source]

Bases: sqlalchemy.sql.functions.FunctionElement

Instances of this class wrap a Postgres composite type.