Skip to content

Commit

Permalink
Create a layer with trams. acteng/atip#463
Browse files Browse the repository at this point in the history
  • Loading branch information
dabreegster committed Feb 9, 2024
1 parent c423779 commit 0c8b41d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ ATIP can display extra contextual layers:
- Cycle parking
- Existing cycle paths
- Crossings
- Tram lines
- the [Major Road Network](https://www.data.gov.uk/dataset/95f58bfa-13d6-4657-9d6f-020589498cfd/major-road-network)
- Boundaries
- Parliament constituency boundaries, from [OS Boundary-Line](https://www.ordnancesurvey.co.uk/products/boundary-line)
Expand All @@ -107,7 +108,7 @@ is a single GeoJSON file if it's small enough, or
To run this:

1. Get `england-latest.osm.pbf` from Geofabrik. The `split_uk_osm.sh` script above does this.
2. Run `cd layers; ./generate_layers.py --osm_input=../england-latest.osm.pbf --schools --hospitals --mrn --parliamentary_constituencies --combined_authorities --local_authority_districts --local_planning_authorities --sports_spaces --railway_stations --bus_routes --crossings --cycle_parking --cycle_paths --ncn --wards --vehicle_counts --pct --local_authorities_for_sketcher --transport_authorities_for_sketcher`
2. Run `cd layers; ./generate_layers.py --osm_input=../england-latest.osm.pbf --schools --hospitals --mrn --parliamentary_constituencies --combined_authorities --local_authority_districts --local_planning_authorities --sports_spaces --railway_stations --bus_routes --crossings --cycle_parking --cycle_paths --ncn --wards --vehicle_counts --pct --local_authorities_for_sketcher --transport_authorities_for_sketcher --trams`
3. Pick an arbitrary version number, and upload the files: `for x in output/*; do aws s3 cp --dry $x s3://atip.uk/layers/v1/; done`

If you're rerunning the script for the same output, you may need to manually delete the output files from the previous run.
Expand Down
5 changes: 5 additions & 0 deletions layers/generate_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def main():
parser.add_argument("--parliamentary_constituencies", action="store_true")
parser.add_argument("--railway_stations", action="store_true")
parser.add_argument("--crossings", action="store_true")
parser.add_argument("--trams", action="store_true")
parser.add_argument("--sports_spaces", action="store_true")
parser.add_argument("--wards", action="store_true")
parser.add_argument("--combined_authorities", action="store_true")
Expand Down Expand Up @@ -122,6 +123,10 @@ def main():
made_any = True
osm.makeCrossings(args.osm_input)

if args.trams:
made_any = True
osm.makeTrams(args.osm_input)

if args.imd:
made_any = True
census.makeIMD(args.imd)
Expand Down
37 changes: 35 additions & 2 deletions layers/osm.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,40 @@ def fixProps(inputProps):
return outputProps

cleanUpGeojson(tmpGeojsonFilepath, fixProps)
convertGeoJsonToPmtiles(
tmpGeojsonFilepath, outputFilepath, autoZoom=True
convertGeoJsonToPmtiles(tmpGeojsonFilepath, outputFilepath, autoZoom=True)


def makeTrams(osm_input):
if not osm_input:
raise Exception("You must specify --osm_input")

filename = "trams"
tmp = f"tmp_{filename}"
ensureEmptyTempDirectoryExists(tmp)

run(
[
"osmium",
"tags-filter",
osm_input,
# Manchester's trams are tagged as light_rail
"nwr/railway=tram,light_rail",
"-o",
f"{tmp}/extract.osm.pbf",
]
)
convertPbfToGeoJson(
f"{tmp}/extract.osm.pbf",
f"{tmp}/{filename}.geojson",
"linestring",
includeOsmID=True,
)

def fixProps(inputProps):
return {
"osm_id": inputProps["@id"],
}

cleanUpGeojson(f"{tmp}/{filename}.geojson", fixProps)

convertGeoJsonToPmtiles(f"{tmp}/{filename}.geojson", f"output/{filename}.pmtiles")

0 comments on commit 0c8b41d

Please sign in to comment.