Working with a PostGIS Database (db)

The db module provides an interface to a PostGIS database containing tables relevant to creating an OSM Changefile from geometry data.

The primary interface exposed here is OGRDBReader.

changegen.db.hstore_as_dict(hstore_str)

Converts a string representation of a Postgres hstore into a Python dictionary. hstore strings should be of the form “‘key1’=>’value1’, “key2”=>”value2”, …”

Parameters

hstore_str (str) – hstore string

Return type

dict

class changegen.db.OGRDBReader(dbname, dbport, dbuser, dbpass=None, dbhost='localhost')

Bases: object

Read features and other metadata from PostGIS database via OGR.

Parameters
  • dbname (str) – Name of the database to connect to.

  • dbport (str) – Port that the database is accessible on.

  • dbuser (str) – Username to connect to database with.

  • dbpass (str) – Password to connect to database with.

  • dbhost (str) – Hostname where the database is accessible.

This class provides a variety of functionality. See method documentation for more details.

get_layers()

Return available layers from db connection.

get_layer_epsg(layer)
get_num_features(layer)
get_feature_by_id(layer, id, id_field)
get_all_ids_for_layer(layer, id_fieldname='osm_id')

Retrieves all unique values of id_fieldname within layer.

intersections(new_layer, intersecting_layer, new_geometry_field='geometry', intersecting_geometry_field='geometry', intersecting_id_field='osm_id', ids=False, distance_buffer=5)

Retrieves intersections between new_layer and intersecting_layer.

Actually returns the nearest points on new_layer features that are within <distance_buffer> from features in intersecting_geometry_field

if ids = True, optionally returns a list of feature IDs from the intersecting layer` that represent the intersecting features in intersecting_layer with intersections to features in new_layer.

returns ogr.Layer

get_layer_fields(layer)

Get field names from layer

get_layer_iter(layer)

Return generator over features in layer