Skip to content

Commit

Permalink
Merge pull request #48 from rcpch:lsoas
Browse files Browse the repository at this point in the history
LSOA-LAD-addition
  • Loading branch information
eatyourpeas authored Dec 8, 2024
2 parents c85002b + 9bed498 commit e84bd90
Show file tree
Hide file tree
Showing 39 changed files with 1,195 additions and 10 deletions.
42 changes: 42 additions & 0 deletions documentation/docs/developer/boundaries.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
title: Ordnance Survey and Boundaries
author: Dr Simon Chapman
---

## Boundaries

Healthcare often reports outcomes according to health geographies - for example at the level of Integrated Care Boards (ICBs) in England, but many like to have their data in administrative contexts also. Deprivation index, for example, which has a large impact on health, is not measured across health geographies, but across administrative ones.

### Lower Layer Super Output Areas (LSOA)

The index of multiple deprivation [for which RCPCH has another repository](https://github.com/rcpch/rcpch-census-platform) relies on census data to summarize different societal and population features to rank geographical units in order of most deprived to least deprived - the higher the score, the better off the region is. IMD uses Lower Layer Super Output Areas (LSOA) whose boundaries were last defined in 2011. These boundaries don't change much, but were updated last in 2021. They are not meant to change to allow longitudinal data to be gathered and be meaningful. LSOAs are chosen to be the way they are as they have population numbers as their common feature (1500 individuals or 650 households) - geographically distributed LSOAs cover a larger area, but in cities they are small as population numbers per unit area are larger.

The last index of multiple of deprivation data for England was published in 2019 and used the 2011 LSOAs, since those were the latest boundaries. Since then, there has been the census of 2021, with the LSOA boundaries updated the same year. The decision on which boundaries will be included in the next iteration of IMD will be decided bythe Office for National Statistics (ONS) and the Ministry of Housing, Communities & Local Government (MHCLG) (now the Department for Levelling Up, Housing and Communities).

### Local Authorities

These are administrative geography boundaries. LSOAs conveniently fit neatly inside LAs but the LA boundaries change more frequently.

**Local Authority Districts (LADs)** are a unit of local administration and statistical geography, and their structure varies across the country. Depending on the region, LADs can take different forms:

#### Two-Tier Systems

In some areas, LADs correspond to district councils, which operate alongside a county council that provides upper-tier services (e.g., Hertfordshire has multiple district councils, such as Watford Borough Council, each of which is an LAD).

#### Unitary Authorities

In other areas, LADs correspond to unitary authorities, which combine the responsibilities of both district and county councils into a single authority.

#### Metropolitan Boroughs

In metropolitan areas, LADs correspond to metropolitan boroughs (e.g., Manchester Metropolitan Borough), which provide local services. These boroughs are part of a wider metropolitan county (e.g., Greater Manchester) that handles strategic functions like transport and policing.

##### London

London is unique, with 32 London Boroughs serving as LADs, plus the City of London, which is its own LAD. The Greater London Authority (GLA) oversees strategic citywide functions but is not an LAD

LAD boundaries change quite frequently. Each LAD has its own unique identifier and the boundaries and membership of LADs, which LSOAs they comprise, are updated by the ONS and published in the form of [look up tables](https://geoportal.statistics.gov.uk/documents/ons::local-authority-districts-counties-and-unitary-authorities-april-2023-map-in-the-uk/about?path=)

## Implications for RCPCH NHS Organisations

Although local authorities are not health geographies, local government has an interest in the health of the local population, and a responsibility for all functions of government that influence health (from housing, to green space, to transport etc), so RCPCH stores the relationship between the organisations that care for children and their local authority district.
116 changes: 115 additions & 1 deletion documentation/docs/developer/shapes.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,118 @@ RCPCH in the main uses the most generalised views - this is because more detail

### Boundary to IMD

2011 LSOAs mapped to 2019 IMD data is a service fortunately already provided by [Consumer Data Research Centre](https://data.cdrc.ac.uk/dataset/index-multiple-deprivation-imd)
2011 LSOAs mapped to 2019 IMD data is a service fortunately already provided by [Consumer Data Research Centre](https://data.cdrc.ac.uk/dataset/index-multiple-deprivation-imd)

## Importing a .shp file

1. Download the file from whichever source (using the LocalAuthorityDistrict model as an example)
2. On the command line:
`python manage.py ogrinspect rcpch_nhs_organisations/hospitals/shape_files/Local_Authority_Districts_May_2024_Boundaries_UK_BUC/LAD_MAY_2024_UK_BUC.shp LocalAuthorityDistrict --srid 27700 --mapping --multi`
This will generate the code for the model (don't forget to import in `__init__.py` and add to admin):

```python
class LocalAuthorityDistrict(models.Model):
lad24cd = models.CharField(max_length=9)
lad24nm = models.CharField(max_length=36)
lad24nmw = models.CharField(max_length=24)
bng_e = models.BigIntegerField()
bng_n = models.BigIntegerField()
long = models.FloatField()
lat = models.FloatField()
globalid = models.CharField(max_length=38)
geom = models.MultiPolygonField(srid=27700)


# Auto-generated `LayerMapping` dictionary for LocalAuthorityDistrict model
localauthoritydistrict_mapping = {
'lad24cd': 'LAD24CD',
'lad24nm': 'LAD24NM',
'lad24nmw': 'LAD24NMW',
'bng_e': 'BNG_E',
'bng_n': 'BNG_N',
'long': 'LONG',
'lat': 'LAT',
'globalid': 'GlobalID',
'geom': 'MULTIPOLYGON',
}
```

3. Create a migration for the new model (check previous examples, as RCPCH tend to add this as an abstract model, so this example diverges from actual practice for simplicity)
`python manage.py makemigrations`

4. Create an empty migration
`python manage.py makemigrations hospitals --name seed_local_authority_districts_boundaries --empty`

5. Create a custom function in the empty migration to import the .shp file geometry data using the layer map created earlier.

```python
from django.db import migrations
from django.apps import apps as django_apps

import os
from django.contrib.gis.utils import LayerMapping

"""
Local Authority Districts May 2024 Boundaries UK BUC
https://geoportal.statistics.gov.uk/search?q=BDY_LAD%202024&sort=Title%7Ctitle%7Casc
"""

# Auto-generated `LayerMapping` dictionary for LocalAuthorityDistrict model
localauthoritydistrict_mapping = {
"lad24cd": "LAD24CD",
"lad24nm": "LAD24NM",
"lad24nmw": "LAD24NMW",
"bng_e": "BNG_E",
"bng_n": "BNG_N",
"long": "LONG",
"lat": "LAT",
"globalid": "GlobalID",
"geom": "MULTIPOLYGON",
}


# Boundary files

app_config = django_apps.get_app_config("hospitals")
app_path = app_config.path

Local_Authority_Districts_May_2024_Boundaries_UK_BUC = os.path.join(
app_path,
"shape_files",
"Local_Authority_Districts_May_2024_Boundaries_UK_BUC",
"LAD_MAY_2024_UK_BUC.shp",
)


def load(apps, schema_editor, verbose=True):
LocalAuthorityDistrict = apps.get_model("hospitals", "LocalAuthorityDistrict")
lm = LayerMapping(
LocalAuthorityDistrict,
Local_Authority_Districts_May_2024_Boundaries_UK_BUC,
localauthoritydistrict_mapping,
transform=False,
encoding="utf-8",
)
lm.save(strict=True, verbose=verbose)


class Migration(migrations.Migration):
dependencies = [
("hospitals", "0012_localauthoritydistrict"),
]

operations = [migrations.RunPython(load)]
```

6. Migrate the changes
`python manage.py migrate`
7. If successful you should see:

```console
....
Saved: LocalAuthorityDistrict object (360)
Saved: LocalAuthorityDistrict object (361)
OK
```

8. This populates the model with the geometry files for mapping all the local authority boundaries, the names and codes. The next step is to hook this up to the other models.
2 changes: 2 additions & 0 deletions documentation/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ nav:
- 'developer/models.md'
- 'developer/seeding.md'
- 'developer/database_maintenance.md'
- 'developer/shapes.md'
- 'developer/boundaries.md'
- Contact:
- 'contact/contact-rcpch.md'
- Legal:
Expand Down
File renamed without changes.
Loading

0 comments on commit e84bd90

Please sign in to comment.