FiasParser
This gem grabs FIAS database from official site (http://fias.nalog.ru/Public/DownloadPage.aspx) and parses data to usable format.
Installation
-
Install system dependecies:
$ sudo apt-get install unar wget
-
Add this line to your application's Gemfile:
gem 'fias_parser'
And then execute:
$ bundle
Or install it yourself as:
$ gem install fias_parser
Usage
Example rake-task (Mongoid):
# app/models/street.rb
class Street
include Mongoid::Document
field :name
field :prefix
field :guid
field :okato
end
# lib/tasks/fias.rake
namespace :fias do
desc "Stores streets to database"
task install: :environment do
parser = FiasParser::Parser.new( base_dir: Rails.root.join( 'tmp' ) )
parser.get_latest
parser.process( 'as_addrobj', batch_size: 100 ) do |batch|
batch.each do |item|
# only active items
next if item[:ACTSTATUS].to_i != 1
# streets
next if item[:AOLEVEL].to_i != 7
# just Moscow
next unless /^45/ =~ item[:OKATO]
Street.create!(
name: item[:OFFNAME],
prefix: item[:SHORTNAME],
okato: item[:OKATO],
guid: item[:AOGUID]
)
end
end
end
end
Available xmls: AS_ACTSTAT AS_ADDROBJ AS_CENTERST AS_CURENTST AS_ESTSTAT AS_HOUSE AS_HSTSTAT AS_INTVSTAT AS_LANDMARK AS_NDOCTYPE AS_NORMDOC AS_OPERSTAT AS_SOCRBASE AS_STRSTAT
XSD schemas look on official site (http://fias.nalog.ru/Public/DownloadPage.aspx)
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request