PostgresOSM
- class pydriosm.ios.PostgresOSM(host=None, port=None, username=None, password=None, database_name=None, data_source='Geofabrik', max_tmpfile_size=None, data_dir=None, **kwargs)
Implement storage I/O of OSM data with PostgreSQL.
- Parameters:
host (str or None) – host name/address of a PostgreSQL server, e.g.
'localhost'
or'127.0.0.1'
(default by installation of PostgreSQL); whenhost=None
(default), it is initialized as'localhost'
port (int or None) – listening port used by PostgreSQL; when
port=None
(default), it is initialized as5432
(default by installation of PostgreSQL)username (str or None) – username of a PostgreSQL server; when
username=None
(default), it is initialized as'postgres'
(default by installation of PostgreSQL)password (str or int or None) – user password; when
password=None
(default), it is required to mannually type in the correct password to connect the PostgreSQL serverdatabase_name (str or None) – name of a database; when
database=None
(default), it is initialized as'postgres'
(default by installation of PostgreSQL)confirm_db_creation – whether to prompt a confirmation before creating a new database (if the specified database does not exist), defaults to
False
data_source (str) – name of data source, defaults to
'Geofabrik'
; options include{'Geofabrik', 'BBBike'}
max_tmpfile_size (int or None) – defaults to
None
, see also the function pyhelpers.settings.gdal_configurations()data_dir (str or None) – directory where the data file is located/saved, defaults to
None
; whendata_dir=None
, it should be the same as the directory specified by the correspondingdownloader
/reader
kwargs – [optional] parameters of the class pyhelpers.sql.PostgreSQL
- Variables:
data_source (str) – name of data sources, options include
{'Geofabrik', 'BBBike'}
Examples:
>>> from pydriosm.ios import PostgresOSM >>> osmdb = PostgresOSM(database_name='osmdb_test') Password (postgres@localhost:5432): *** Creating a database: "osmdb_test" ... Done. Connecting postgres:***@localhost:5432/osmdb_test ... Successfully. >>> osmdb.data_source 'Geofabrik' >>> type(osmdb.downloader) pydriosm.downloader.GeofabrikDownloader >>> type(osmdb.reader) pydriosm.reader.GeofabrikReader >>> # Change the data source >>> osmdb.data_source = 'BBBike' >>> type(osmdb.downloader) pydriosm.downloader.BBBikeDownloader >>> type(osmdb.reader) pydriosm.reader.BBBikeReader >>> # Delete the database 'osmdb_test' >>> osmdb.drop_database(verbose=True) To drop the database "osmdb_test" from postgres:***@localhost:5432 ? [No]|Yes: yes Dropping "osmdb_test" ... Done.
Attributes
list: Names of the data sources.
dict: Specify a data-type dictionary for data or columns in PostgreSQL database and Pandas.
Instance of either the class
GeofabrikDownloader
orBBBikeDownloader
, depending on the specifieddata_source
for creating an instance of the classPostgresOSM
.Name of the current property
downloader
.Instance of either
GeofabrikReader
orBBBikeReader
, depending on the specifieddata_source
for creating an instance of the calssPostgresOSM
.Homepage URL of data resource for current property
downloader
.Methods
decode_pbf_layer
(layer_dat[, decode_geojson])Process raw data of a PBF layer retrieved from database.
drop_subregion_tables
(subregion_names[, ...])Delete all or specific schemas/layers of subregion data from the database being connected.
fetch_osm_data
(subregion_name[, ...])Fetch OSM data (of one or multiple layers) of a geographic (sub)region.
get_table_column_info
(subregion_name, layer_name)Get information about columns of a specific schema and table data of a geographic (sub)region.
get_table_name
(subregion_name[, ...])Get the default table name for a specific geographic (sub)region.
import_osm_data
(osm_data, table_name[, ...])Import OSM data into a database.
import_osm_layer
(layer_data, table_name, ...)Import one layer of OSM data into a table.
import_subregion_osm_pbf
(subregion_names[, ...])Import data of geographic (sub)region(s) that do not have (sub-)subregions into a database.
subregion_table_exists
(subregion_name, ...)Check if a table (for a geographic (sub)region) exists.