Hello,
FYI: I've updated the worlddb tool [1] and models [2] gems. What's news?
The state and city models got split up into separate models and
tables e.g. the worlddb now includes for administrative divisions new
models and tabels:
state (ADM1) -- Land/State/Province/etc.
part (ADM2 - optional) -- Regierungskreis/etc.
county (ADM2/ADM3) -- Landkreis/Bezirk/County/etc.
muni (ADM3/ADM4) -- Gemeinde/Municipality/etc.
And for cities:
metro -- e.g. Ruhrgebiet/Köln-Bonn/etc.
city -- e.g. München/Wien/etc.
district -- e.g. Innere Stadt/Ottakring, 2. Bezirk/etc.
Example:
de = Country.create!( key: 'de',
name: 'Deutschland',
code: 'DEU',
pop: 1,
area: 1 )
by = State.create!( key: 'by',
name: 'Bayern',
country_id: de.id,
pop: 1,
area: 1 )
ob = Part.create!( key: 'ob',
name: 'Oberbayern',
state_id: by.id,
pop: 1,
area: 1 )
fs = County.create!( key: 'fs',
name: 'Freising',
state_id: by.id,
part_id: ob.id,
pop: 1,
area: 1,
level: 3 )
au = Muni.create!( key: 'auidhallertau',
name: 'Au i.d. Hallertau',
state_id: by.id,
county_id: fs.id,
pop: 1,
area: 1,
level: 4 )
## test assocs
assert_equal 'Freising', by.counties.first.name
assert_equal 'Au i.d. Hallertau', by.munis.first.name
assert_equal 'Au i.d. Hallertau', fs.munis.first.name
assert_equal 'Bayern', au.county.state.name
assert_equal 'Oberbayern', au.county.part.name
and so on
To read in state/part/county/muni datasets you can use the new tree
format and StateTreeReader. For example, to read in all admins for
Oberfranken (in Bavaria) [3]. Use:
2 Bayern
24 .. Oberfranken
241 .... Bamberg (Stadt) ## Kreisfreie Stadt
...... Bamberg
........ Bamberg
245 .... Bamberg (Land) ## Landkreis
...... Baunach ## (4013, 30,9 km²)
........ Baunach
...... Hallstadt ## (8364, 14,5 km²)
........ Hallstadt ## (7588)
........ Dörfleins ## (1380)
...... Scheßlitz ## (7184, 94,9 km²)
........ Scheßlitz
........ Köttensdorf
........ Würgau
To see it all in action try, for example:
$ worlddb new de # build a copy using the deutschland.db dataset or
$ worlddb new at # build a copy using the austria.db dataset
That's it. Questions, comments as always welcome. Cheers.
[1] https://github.com/worlddb/world.db.tools
[2] https://github.com/worlddb/world.db.models
[3] https://github.com/openmundi/deutschland.db/blob/master/3--by-bayern/4--oberfranken/orte.txt