From 5396ef5a18f6c503067497cb5aaf875631b11522 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Tue, 14 May 2024 18:36:54 +0100 Subject: [PATCH] [UK] May 2024 Boundary-Line import. --- mapit_gb/controls/2024-05.py | 25 +++++++++++++++++++ .../commands/mapit_UK_import_boundary_line.py | 5 +++- 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 mapit_gb/controls/2024-05.py diff --git a/mapit_gb/controls/2024-05.py b/mapit_gb/controls/2024-05.py new file mode 100644 index 00000000..1cd57117 --- /dev/null +++ b/mapit_gb/controls/2024-05.py @@ -0,0 +1,25 @@ +# A control file for importing May 2024 Boundary-Line. + +from mapit.models import Area, Generation + + +def check(name, type, country, geometry, ons_code, commit, **args): + """Should return True if this area is NEW, False if we should match against + an ONS code, or an Area to be used as an override instead.""" + + if type != 'CED': + return False + + current = Generation.objects.current() + if not current: # Fresh import + return False + + # All the unit IDs have changed in this release. CEDs don't have ONS codes + # to match on, so instead we have to match on name (they should all be the same) + area = Area.objects.get( + type__code='CED', + names__type__code='O', names__name=name, + generation_low__lte=current, generation_high__gte=current, + polygons__polygon__contains=geometry.geos.point_on_surface + ) + return area diff --git a/mapit_gb/management/commands/mapit_UK_import_boundary_line.py b/mapit_gb/management/commands/mapit_UK_import_boundary_line.py index c1487887..a98f9353 100644 --- a/mapit_gb/management/commands/mapit_UK_import_boundary_line.py +++ b/mapit_gb/management/commands/mapit_UK_import_boundary_line.py @@ -118,7 +118,7 @@ def handle_label(self, filename, **options): except Code.DoesNotExist: ons_code = None elif ons_code: - m = Area.objects.get(codes__type=code_version, codes__code=ons_code) + m = Area.objects.exclude(type__code='WMCF').get(codes__type=code_version, codes__code=ons_code) elif unit_id: m = Area.objects.get( codes__type=code_type_os, codes__code=unit_id, generation_high=current_generation) @@ -217,4 +217,7 @@ def patch_boundary_line(self, name, ons_code, unit_id, area_code): if area_code == 'UTW' and name == 'An Taobh Siar agus Nis Ward' and ons_code == 'S13003134': return {'ons-code': 'S13002608'} + if area_code == 'DIW' and name == 'Loughton Fairmead Ward' and ons_code == 'E05015731': + return {'ons-code': 'E05015730'} + return {}