Osmer
Tool to manage local OSM database
Install / Use
/learn @alno/OsmerREADME
= Osmer
Osmer is a tool to manage local OSM database: import data, transform it to convenient scheme and update it.
== Features
- Importing and updating data in osm2pgsql schema (osm2pgsql required)
- Custom derived schemas for analysis or rendering convenience
- BBox restriction of imported data
- Data reprojection between schemas
- Geometry simplification
- (planned) Native database schema support
- (planned) Rails-like config/database.yml support for seamless integration with webapps
- (planned) Importing and updating data in pgsnapshot schema (osmosis required)
== Configuration
Database schemas definition goes to Osmfile which contains basic flags and schema definitions:
prefix 'osmer' # Prefix for all tables
schema :source, :type => :osm2pgsql do # Osm2pgsql schema named 'source'
bbox 35.859375, 54.367759, 36.562495, 54.775345 # It has bounding box restriction as minlon, minlat, maxlon, maxlat
updates :daily do # It may be updated on daily basis
dump 'http://data.gis-lab.info/osm_dump/dump/RU-KLU/RU-KLU-{today}.osm.pbf' # Where initial dump should be downloaded from here
diff 'http://data.gis-lab.info/osm_dump/diff/RU/RU-{yesterday}-{today}.osc.gz' # And diff should be downloaded from here
end
end
schema :rendering, :projection => 900913 do # Rendering schema containing only necessary data
multipolygons :places do # Table of place boundaries
map :place => [:city, :town, :village, :hamlet] # It contains features which have place tag with one of values: city, town, village, hamlet
with :area # And also polygon area
end
lines :roads do # Table of roads
map :highway # It contains features with highway tag
with :length, :ref => :string # And also road length and ref tag to additional table column
end
end
== Usage
Osmer may be used as command-line executable with following commands:
-
<tt>osmer schema create [SCHEMA]</tt> # Create given osm schema in database (create all if none specified)
-
<tt>osmer schema drop [SCHEMA]</tt> # Drop given osm schema in database (drop all if none specified)
-
<tt>osmer schema recreate [SCHEMA]</tt> # Recreate given osm schema in database (recreate all if none specified)
-
<tt>osmer data import [SCHEMA] [FILE]</tt> # Import data to given schema from file
-
<tt>osmer data update [SCHEMA] [FILE]</tt> # Update data in schema from given change file
Supported options:
- -c, [--config=CONFIG] Config file location, default value <tt>Osmfile</tt>
- -h, [--dbhost=DBHOST] Database host, default value <tt>localhost</tt>
- -p, [--dbport=DBPORT] Database port, default value <tt>5432</tt>
- -U, [--dbuser=DBUSER] Database user
- -P, [--dbpass=DBPASS] Database password
- -d, [--dbname=DBNAME] Database name
== Details
=== Schema
Schema is a set of tables representing osm data in a common way. Examples of schemas may be:
- Osm2Pgsql schema
- PgSnapshot schema populated with Osmosis
- Custom set of tables, representing data in convenient way
All tables in schema share common projection. In database schemas are represented with table prefixes (native schemas will be supported later)
=== Table
=== Mapper
Special mappers:
- [geometry] Feature geometry - present by default, configured with <tt>simplify</tt>
- [name] Feature name - present by default
- [type] Feature type - present by default, configured with <tt>map</tt>
- [z_order] Order of feature in rendering - specified with <tt>z_order</tt>
Available mappers (specified with <tt>with</tt>):
- [string] Simple string column
- [address] Address columns
- [area] Polygon (or multipolygon) area
- [length] Line (or multiline) length
== Internals
=== Schema
In code, schema is representd by an object, which have following methods:
- create! - to create schema in database
- drop! - to drop schema in database
- attach_listener! - (optional) - to add listener to schema data, which may be used to have autoupdate functionality
listener with name <name> is a stored procedure set:
<name>_insert(id,*args) <name>_update(id,*args) <name>_delete(id)
=== Mapper
Mapper is represented by Ruby class which have methods:
- [fields] hash in form of field-type to add to table
- [assignments] hash in form of field-expression
- [conditions] list of conditions on source data
- [indexes] hash of indexes in form name-specification to be added
==== Advanced mapper usage
with do int :layer, :null => false, :default => 0 end
== Contributors
See https://github.com/alno/osmer/graphs/contributors
Copyright © 2012 Alexey Noskov, released under the MIT license
