TileStache.Goodies.Providers.MirrorOSM module¶
Populate an OSM rendering database using tiled data requests.
This provider is unusual in that requests for tiles have the side effect of running osm2pgsql to populate a PostGIS database of OSM data from a remote API source. Returned tiles are just text confirmations that the process has been successful, while the stored data is expected to be used in other providers to render OSM data. It would be normal to use this provider outside the regular confines of a web server, perhaps with a call to tilestache-seed.py governed by a cron job or some other out-of-band process.
- MirrorOSM is made tenable by MapQuest’s hosting of the XAPI service:
- http://open.mapquestapi.com/xapi/
- Osm2pgsql is an external utility:
- http://wiki.openstreetmap.org/wiki/Osm2pgsql
Example configuration:
“mirror-osm”: {
“provider”: {
“class”: “TileStache.Goodies.Providers.MirrorOSM:Provider”, “kwargs”: {
“username”: “osm”, “database”: “planet”, “api_base”: “http://open.mapquestapi.com/xapi/“}
}
}
Provider parameters:
- database:
- Required Postgres database name.
- username:
- Required Postgres user name.
- password:
- Optional Postgres password.
- hostname:
- Optional Postgres host name.
- table_prefix:
- Optional table prefix for osm2pgsql. Defaults to “mirrorosm” if omitted. Four tables will be created with this prefix: <prefix>_point, <prefix>_line, <prefix>_polygon, and <prefix>_roads. Must result in valid table names!
- api_base:
- Optional OSM API base URL. Because we don’t want to overtax the main OSM API, this defaults to MapQuest’s XAPI, “http://open.mapquestapi.com/xapi/”. The trailing slash must be included, up to but not including the “api/0.6” portion of a URL. If you’re careful to limit your usage, the primary OSM API can be specified with “http://api.openstreetmap.org/”.
- osm2pgsql:
- Optional filesystem path to osm2pgsql, just in case it’s someplace outside /usr/bin or /usr/local/bin. Defaults to “osm2pgsql –utf8-sanitize”. Additional arguments such as “–keep-coastlines” can be added to this string, e.g. “/home/user/bin/osm2pgsql –keep-coastlines –utf8-sanitize”.
-
class
TileStache.Goodies.Providers.MirrorOSM.ConfirmationResponse(coord, content, success)¶ Wrapper class for confirmation responses.
TileStache.getTile() expects to be able to save one of these to a buffer.
-
do_I_have_to_draw_you_a_picture()¶ Return a little thumbs-up / thumbs-down image with text in it.
-
save(out, format)¶
-
-
class
TileStache.Goodies.Providers.MirrorOSM.Provider(layer, database, username, password=None, hostname=None, table_prefix='mirrorosm', api_base='http://open.mapquestapi.com/xapi/', osm2pgsql='osm2pgsql --utf8-sanitize')¶ -
getTypeByExtension(extension)¶ Get mime-type and format by file extension.
This only accepts “txt”.
-
renderTile(width, height, srs, coord)¶ Render a single tile, return a ConfirmationResponse instance.
-
-
TileStache.Goodies.Providers.MirrorOSM.clean_up_tables(db, tmp_prefix)¶ Drop all temporary tables created by prepare_data().
-
TileStache.Goodies.Providers.MirrorOSM.coordinate_latlon_bbox(coord, projection)¶ Return an (xmin, ymin, xmax, ymax) bounding box for a projected tile.
-
TileStache.Goodies.Providers.MirrorOSM.create_tables(db, prefix, tmp_prefix)¶ Create permanent tables for OSM data. No-op if they already exist.
-
TileStache.Goodies.Providers.MirrorOSM.download_api_data(filename, coord, api_base, projection)¶ Download API data for a tile to a named file, return size in kilobytes.
-
TileStache.Goodies.Providers.MirrorOSM.populate_tables(db, prefix, tmp_prefix, bounds)¶ Move prepared OSM data from temporary to permanent tables.
Replace existing data and work within a single transaction.
-
TileStache.Goodies.Providers.MirrorOSM.prepare_data(filename, tmp_prefix, dbargs, osm2pgsql, projection)¶ Stage OSM data into a temporary set of tables using osm2pgsql.