databasemetadata
— Database Accessible Metadata¶
The databasemetadata
file contains a generic metadata parser for data stored within a database
New in version 0.2.0.
- class amg.databasemetadata.DbMetadata(dbname, uri, sql='SELECT geom FROM images LIMIT 1;')[source]¶
This class connects to a database using SQLAlchemy, uses the sql kwarg to execute a query that returns a geometry, loads the geometry into a shapely geometry, and finally returns a number of metadata properties.
- Parameters
dbname (str) – The name of the database to connect to
uri (str) – The connection string in the form {databasetype}://{username}:{password}@{host}:{port}
sql (str) – The sql query to execute. This query should return a WKT Geometry
- footprint¶
shapely Polygon or MultiPolygon
- Type
obj
- bbox¶
Containing the four elements of the bounding box in the form (xmin, ymin, xmax, ymax)
- Type
- centroid¶
a shapely Point object defining the centroid of the footprint
- Type
obj
Examples
>>> sql = ''' WITH cte_geoms AS ( SELECT id, geom FROM ctx WHERE ctx.name LIKE ANY (array ['B17_016091_2064_XN_26N031W%%', 'P17_007718_2022_XN_22N031W%%']) ) SELECT ST_AsText(ST_Extent(ST_Intersection(A.geom, B.geom))) FROM cte_geoms as A, cte_geoms as B WHERE A.id > B.id AND A.id != B.id''' >>> db = DbMetadata('dbname', 'postgresql://uname:pw@mydbrui.gov:port', sql=sql) >>> db.footprint
- class amg.databasemetadata.GenericSQLite(datafile, sql, column_remapper={})[source]¶
A generic interface to a SQLite database. This class expects to be passed an SQL query that returns a single row. The columns on the rows are named using introspection and the class data attribute is a dict where the keys are the column names and the rows are the column values. The column_remapper is used to homogenize the column names to the standard amg names.