def load_municipality_geodata() -> GeoDataFrame: data = gpd.read_file( abs_path("src/swissBOUNDARIES3D_1_3_TLM_HOHEITSGEBIET.shp")) # We are only interested in Swiss Municipalities data = data[data["ICC"] == "CH"] data["TYPE"] = data["BFS_NUMMER"].apply(id_to_typology.get) data.loc[data["NAME"].apply(_is_lake), "TYPE"] = "lake" data["COLOR"] = data["TYPE"].apply(type_to_color.get) return data
x, y = list( zip(*data.apply( lambda row: converter.WGS84toLV03(row.latitude, row.longitude)[:2], axis=1))) geodata = geopandas.GeoDataFrame(data, geometry=geopandas.points_from_xy(x=x, y=y)) return geodata if __name__ == '__main__': import matplotlib.pyplot as plt # Load Municipality and City Data municipality_data = load_municipality_geodata() city_data = read_csv(abs_path("src/city_coordinates.csv")) city_geodata = data_to_geodata(data=city_data) # Plot Municipalities ax = municipality_data.plot(color=municipality_data["COLOR"], edgecolor="#999999", linewidth=0.5, figsize=(15, 10)) ax.set_axis_off() plt.legend(handles=municipality_type_legend_handles) # Plot cities city_geodata.plot(ax=ax, color="black") for x_, y_, label in zip(city_geodata.geometry.x, city_geodata.geometry.y,
def load_municipality_geodata() -> GeoDataFrame: data = gpd.read_file( abs_path("src/swissBOUNDARIES3D_1_3_TLM_HOHEITSGEBIET.shp")) # We are only interested in Swiss Municipalities data = data[data["ICC"] == "CH"] data["TYPE"] = data["BFS_NUMMER"].apply(id_to_typology.get) data.loc[data["NAME"].apply(_is_lake), "TYPE"] = "lake" data["COLOR"] = data["TYPE"].apply(type_to_color.get) return data if __name__ == '__main__': import matplotlib.pyplot as plt test_data = load_municipality_geodata() base = test_data.plot(color=test_data["COLOR"], edgecolor="#999999", linewidth=0.5, figsize=(15, 10)) # plt.title("Municipalities of Switzerland", size=25) base.set_axis_off() plt.legend(handles=municipality_type_legend_handles) plt.tight_layout() plt.savefig(abs_path("src/map.png"))
import json from statistics import mode from swiss_municipalities.paths import abs_path with open(abs_path("src/id_to_type.json")) as id_to_type_file: id_to_type_raw = json.load(id_to_type_file) id_to_typology = { int(municipality_id.replace("|", "")): municipality_info["value"] for municipality_id, municipality_info in id_to_type_raw["values"].items() } # Manually rewrote from wikipedia, e.g. # https://en.wikipedia.org/wiki/Villaz,_Switzerland -- copy the SFOS number of the municipalities that resulted in the # merged one _merged_municipalities = { 5399: [5135, 5129, 5102, 5095, 5105], # Verzasca 3544: [3521, 3522], # Bergün Filisur 3714: [3691, 3693, 3694], # Rheinwald 5287: [5286, 5285, 5284, 5283], # Riviera 6417: [6402, 6409, 6410, 6411, 6414, 6415], # La Grande-Béroche 293: [134, 140], # Wädenswil 295: [132], # Horgen 294: [222], # Elgg 292: [44, 36, 42], # Stammheim 2237: [2185, 2213, 2221], # Prez 2117: [2111, 2116], # Villaz 889: [873, 874, 876], # Thurnen # For the following there is just no typology to be found anywhere