Skip to content

Commit

Permalink
Merge pull request #219 from DFE-Digital/2165-update-local-authoritie…
Browse files Browse the repository at this point in the history
…s-data

Update local authorities data
  • Loading branch information
slawosz authored Nov 13, 2024
2 parents 2d73d9f + e739112 commit cedc4ab
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 15 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ This project depends on:

When updating the `db/data/hubs.csv` file, please make sure to run `rails r 'Hub::Importer.new.reload!'` locally first to make sure all changes were applied.

### Updating Authorities File

Geojson file can be find here: https://geoportal.statistics.gov.uk/datasets/f23beaa3769a4488b6a5f0cfb7980f51_0/explore?location=52.427623%2C-1.470139%2C8.26
Due to size of the file, it is split into several files. Individual files should be smaller than 100 MB due to git limitations.
See `lib/tasks/split_authorities_file.rake` for details.

## Testing

### Mocking with VCR for feature specs
Expand Down
23 changes: 13 additions & 10 deletions app/lib/local_authority/importer.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
class LocalAuthority::Importer
DEFAULT_SOURCE = Rails.root.join("db/data/authorities.json").freeze
DEFAULT_SOURCES = (1..LOCAL_AUTHORITIES_FILES_COUNT).map { |num|
Rails.root.join("db/data/authorities_#{num}.json") }.freeze
attr_reader :path

def initialize(path = DEFAULT_SOURCE)
@path = path
def initialize(paths = DEFAULT_SOURCES)
@paths= paths
end

def reload!
Expand All @@ -29,15 +30,17 @@ def read_file(geojson_path)
end

def load
Rails.logger.debug("Loading #{@path}")
@paths.each do |path|
Rails.logger.debug("Loading #{path}")

features = read_file(@path)
features = read_file(path)

features.each do |feature|
LocalAuthority.create!(
name: feature.properties["LAD22NM"],
geometry: feature.geometry
)
features.each do |feature|
LocalAuthority.create!(
name: feature.properties["LAD24NM"],
geometry: feature.geometry
)
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/lib/local_authority/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def search_polygon

def transform(geo)
RGeo::CoordSys::Proj4.transform(
RGeo::CoordSys::Proj4.new("EPSG:4326"),
RGeo::CoordSys::Proj4.new("EPSG:27700"),
geo,
RGeo::CoordSys::Proj4.new("EPSG:27700"),
RGeo::Cartesian.preferred_factory
Expand Down
1 change: 1 addition & 0 deletions config/initializers/constants.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
LOCAL_AUTHORITIES_FILES_COUNT = 5
1 change: 0 additions & 1 deletion db/data/authorities.json

This file was deleted.

1 change: 1 addition & 0 deletions db/data/authorities_1.json

Large diffs are not rendered by default.

Loading

0 comments on commit cedc4ab

Please sign in to comment.