geoalchemy.dialect

class geoalchemy.dialect.DialectManager

This class is responsible for finding a spatial dialect (e.g. PGSpatialDialect or MySQLSpatialDialect) for a SQLAlchemy database dialect.

It can be used by calling “DialectManager.get_spatial_dialect(dialect)”, which returns the corresponding spatial dialect. The spatial dialect has to be listed in __initialize_dialects().

static get_spatial_dialect(dialect)

This method returns a spatial dialect instance for a given SQLAlchemy dialect. The instances are cached, so that for every spatial dialect exists only one instance.

class geoalchemy.dialect.SpatialDialect

This class bundles all required classes and methods to support a database dialect. It is supposed to be subclassed. The child classes must be added to DialectManager.__initialize_dialects(), so that they can be used.

bind_wkb_value(wkb_element)

This method is called from base.__compile_wkbspatialelement() to insert the value of base.WKBSpatialElement into a query.

get_function(function_class)

This method is called to translate a generic function into a database dialect specific function.

It either returns a string, a list or a method that returns a Function object.

  • String: A function name, e.g.:

    functions.wkb: 'SDO_UTIL.TO_WKBGEOMETRY'
  • List: A list of function names that are called cascaded, e.g.:

    functions.wkt: ['TO_CHAR', 'SDO_UTIL.TO_WKTGEOMETRY'] is compiled as:
    TO_CHAR(SDO_UTIL.TO_WKTGEOMETRY(..))
  • Method: A method that accepts a list/set of arguments and returns a Function object, e.g.:

    functions.equals : lambda params, within_column_clause : (func.SDO_EQUAL(*params) == 'TRUE')
handle_ddl_after_create(bind, table, column)

This method is called after the mapped table was created in the database by SQLAlchemy. It is used to create a geometry column for the created table.

handle_ddl_before_drop(bind, table, column)

This method is called after the mapped table was deleted from the database by SQLAlchemy. It can be used to delete the geometry column.

is_member_function(function_class)

Returns True if the passed-in function should be called as member function, e.g.:

Point.the_geom.dims is compiled as:
points.the_geom.Get_Dims()
is_property(function_class)

Returns True if the passed-in function should be called as property, e.g.:

Point.the_geom.x is compiled as (for MS Server):
points.the_geom.x
process_result(value, type)

This method is called when a geometry value from the database is transformed into a SpatialElement object. It receives an WKB binary sequence, either as Buffer (for PostGIS and Spatialite), a String (for MySQL) or a cx_Oracle.LOB (for Oracle), and is supposed to return a subclass of SpatialElement, e.g. PGSpatialElement or MySQLSpatialElement.

process_wkb(value)

This method is called from functions._WKBType.process_result_value() to convert the result of functions.wkb() into a usable format.

Previous topic

geoalchemy.functions

Next topic

geoalchemy.utils

This Page