Skip to content

Commit

Permalink
Generalise choropleth
Browse files Browse the repository at this point in the history
  • Loading branch information
mgcth committed May 5, 2024
1 parent e745d2a commit 16828ea
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 45 deletions.
45 changes: 0 additions & 45 deletions scripts/choropleth.py

This file was deleted.

46 changes: 46 additions & 0 deletions src/lantmateriet/choropleth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"""Choropleth module."""

from pathlib import Path

import geopandas as gpd
from shapely import geometry, ops, polygonize


def extract_choropleth(all_files: list[Path]):
"""Extract Choropleth polygons from list of LineStrings."""
all_data = [
geo
for file in all_files
for geo in gpd.read_file(
file, use_arrow=True, engine="pyogrio"
).geometry.to_list()
]

return polygonize(ops.linemerge(geometry.MultiLineString(all_data)).geoms)


def get_municipalities_choropleth(administrative_path: str, scb_path: str):
admin = Path(administrative_path)
scb = Path(scb_path)

all_files = [
admin / "04_riksgrans.geojson",
admin / "05_sjoterritoriets_grans_i_havet.geojson",
admin / "01_kommungrans.geojson",
admin / "02_lansgrans.geojson",
]

return extract_choropleth(all_files)


def get_regions_choropleth(administrative_path: str, scb_path: str):
admin = Path(administrative_path)
scb = Path(scb_path)

all_files = [
admin / "04_riksgrans.geojson",
admin / "05_sjoterritoriets_grans_i_havet.geojson",
admin / "02_lansgrans.geojson",
]

return extract_choropleth(all_files)

0 comments on commit 16828ea

Please sign in to comment.