In [ ]:
#EJERCICIO 1
In [1]:
import os, geopandas as gpd
import pandas as pd
import matplotlib.pyplot as plt
from geopandas import clip
In [ ]:
countries=gpd.read_file(os.path.join("maps","World_Countries","World_Countries.shp"))
In [ ]:
#Datos a importar:
trainsGB=gpd.read_file(os.path.join("maps","trainsUK","hotosm_gbr_railways_lines_shp.shp"))
trainsNI=gpd.read_file(os.path.join("maps","trainsUK","Rail Line NI_polyline.shp"))
cities=gpd.read_file(os.path.join("maps","World_Cities","World_Cities.shp"))
UK_regiones=gpd.read_file(os.path.join("maps","ITL_1","ITL1_JAN_2025_UK_BFC.shp"))
UK_condados=gpd.read_file(os.path.join("maps","ITL_2","ITL2_JAN_2025_UK_BFC.shp"))
UK_distritos=gpd.read_file(os.path.join("maps","ITL_3","International_Territorial_Level_3_(January_2025)_Boundaries_UK_BFC_V2.shp"))
In [79]:
trainsGB = trainsGB.to_crs(27700)
In [78]:
trainsNI = trainsNI.to_crs(27700)
In [ ]:
trainsUK = gpd.GeoDataFrame(
pd.concat([trainsGB, trainsNI], ignore_index=True),
crs=trainsGB.crs)
In [22]:
UK=countries[countries.COUNTRY=='United Kingdom']
In [77]:
UK=UK.to_crs(27700)
In [25]:
UK.centroid
Out[25]:
0 | |
---|---|
227 | POINT (348609.801 461152.22) |
In [65]:
citiesUK=cities[cities.COUNTRY=='UK'].to_crs(27700)
In [ ]:
infoairports=pd.read_csv(os.path.join("data","gb-airports.csv"))
In [ ]:
airports=gpd.GeoDataFrame(data=infoairports.copy(),
geometry=gpd.points_from_xy(infoairports.longitude_deg,
infoairports.latitude_deg),
crs=4326)
In [ ]:
airportsUK=airports.to_crs(27700)
In [ ]:
airportsUK.rename(columns={'type':'kind'},inplace=True)
In [ ]:
#EJERCICIO 1
In [ ]:
print(UK.crs,trainsUK.crs,UK_regiones.crs,airportsUK.crs,citiesUK.crs)
EPSG:27700 EPSG:27700 EPSG:27700 EPSG:27700 EPSG:27700
In [ ]:
#--------------------------------------------------------------
# 1
#--------------------------------------------------------------#
In [ ]:
regiones_norte = UK.cx[:,461155.382:]
# 2. Recortamos los ríos usando clip
train_clipped = clip(trainsUK, regiones_norte)
In [ ]:
base = UK.plot(facecolor="silver", edgecolor='black', linewidth=0.4,figsize=(15,15))
UK_regiones.cx[:,461155.382:].plot(facecolor='lightgrey', edgecolor='black',linewidth=0.3,
ax=base)
train_clipped.plot(ax=base, edgecolor='blue', linewidth=0.3)
airportsUK.cx[:,:461155.382].plot( color='blue', markersize=5,
ax=base)
citiesUK.cx[:,:461155.382].plot(marker='+', color='red', markersize=90,
ax=base)
UK.centroid.plot(color='red',ax=base)
Out[ ]:
<Axes: >
In [ ]:
#--------------------------------------------------------------#
# 2
#--------------------------------------------------------------#
In [ ]:
fig, ax = plt.subplots(figsize=(15, 15))
UK_distritos.plot(ax=ax, facecolor='none', edgecolor='gray', linewidth=0.7)
UK_condados.plot(ax=ax, facecolor='none', edgecolor='black', linewidth=1.5)
Out[ ]:
<Axes: >
In [ ]:
UK_distritos['Condado'] = UK_distritos['ITL325CD'].str[:4]
In [ ]:
UK_distritos.columns
Out[ ]:
Index(['FID', 'ITL325CD', 'ITL325NM', 'BNG_E', 'BNG_N', 'LAT', 'LONG', 'Shape__Are', 'Shape__Len', 'GlobalID', 'geometry', 'Condado'], dtype='object')
In [ ]:
orden_columnas = [
'FID', 'Condado', 'ITL325CD', 'ITL325NM', 'BNG_E', 'BNG_N', 'LAT', 'LONG',
'Shape__Are', 'Shape__Len', 'GlobalID', 'geometry']
UK_distritos = UK_distritos[orden_columnas]
In [ ]:
UK_distritos.columns
Out[ ]:
Index(['FID', 'Condado', 'ITL325CD', 'ITL325NM', 'BNG_E', 'BNG_N', 'LAT', 'LONG', 'Shape__Are', 'Shape__Len', 'GlobalID', 'geometry'], dtype='object')
In [ ]:
len(set(UK_condados))
Out[ ]:
8
In [ ]:
UK_condados.head()
Out[ ]:
ITL225CD | ITL225NM | BNG_E | BNG_N | LAT | LONG | GlobalID | geometry | |
---|---|---|---|---|---|---|---|---|
0 | TLC3 | Tees Valley | 449140 | 521739 | 54.5885 | -1.24112 | 31050e7e-fd0d-4ed4-8ffd-071632345546 | MULTIPOLYGON (((450259.6 525943.8, 450261.4 52... |
1 | TLC4 | Northumberland, Durham and Tyne & Wear | 402627 | 577731 | 55.0940 | -1.96038 | a823ed47-990e-4223-8195-f73348847456 | MULTIPOLYGON (((439170.69 557624.82, 439170.1 ... |
2 | TLD1 | Cumbria | 341842 | 525692 | 54.6230 | -2.90224 | e8182039-7db8-47da-b31b-39c7c470009d | MULTIPOLYGON (((321485.903 463795.299, 321473.... |
3 | TLD3 | Greater Manchester | 377929 | 401095 | 53.5061 | -2.33424 | ddc987f4-441e-4d53-9556-638d4d42f2f9 | POLYGON ((406087.197 404640.102, 406041.099 40... |
4 | TLD4 | Lancashire | 362812 | 444720 | 53.8973 | -2.56741 | 919d2406-9090-48eb-9aab-428eda32ab07 | MULTIPOLYGON (((337136.5 422474, 337133.067 42... |
In [ ]:
UK_distritos[UK_distritos.Condado=='TLG3'].plot(facecolor='lightgrey', edgecolor='black',linewidth=0.2)
Out[ ]:
<Axes: >
In [ ]:
UK_distritos[UK_distritos.Condado=='TLG3'].union_all()
Out[ ]:
In [ ]:
West_Midlands_union=UK_distritos[UK_distritos.Condado=='TLG3'].union_all()
In [ ]:
gdf_union = gpd.GeoDataFrame(
index=[0],
data={'Condado': 'West_Midland'},
crs=UK_distritos.crs,
geometry=[West_Midlands_union])
In [ ]:
gdf_union
Out[ ]:
Condado | geometry | |
---|---|---|
0 | West_Midland | POLYGON ((427600.697 284299.999, 427608.604 28... |
In [ ]:
df_co2=pd.read_csv(os.path.join("data","2005-2022-local-authority-ghg-emissions-csv-dataset.csv"))
df_code=pd.read_csv(os.path.join("data","LAD_(December_2024)_to_LAU1_to_ITL3_to_ITL2_to_ITL1_(January_2025)_Lookup_in_the_UK.csv"))
In [ ]:
df_merged = df_co2.merge(
df_code[['LAD24CD', 'ITL325CD']],
left_on='Local Authority Code',
right_on='LAD24CD',
how='left'
)
In [ ]:
co2_total_ITL3 = df_merged.groupby('ITL325CD')[
'CO2 emissions within the scope of influence of LAs (kt CO2)'
].sum().reset_index()
co2_mean_ITL3 = df_merged.groupby('ITL325CD')[
'CO2 emissions within the scope of influence of LAs (kt CO2)'
].mean().reset_index()
In [ ]:
co2_total_ITL3 = co2_total_ITL3.merge(
UK_distritos[['ITL325CD', 'ITL325NM']],
on='ITL325CD',
how='left'
)
co2_total_ITL3 = co2_total_ITL3[['ITL325CD',
'ITL325NM',
'CO2 emissions within the scope of influence of LAs (kt CO2)']]
In [ ]:
co2_total_ITL3
Out[ ]:
ITL325CD | ITL325NM | CO2 emissions within the scope of influence of LAs (kt CO2) | |
---|---|---|---|
0 | TLC31 | Hartlepool and Stockton-on-Tees | 34159.566304 |
1 | TLC32 | South Teesside | 31781.439689 |
2 | TLC33 | Darlington | 11104.755815 |
3 | TLC41 | Durham | 49527.654375 |
4 | TLC42 | Northumberland | 39641.088942 |
... | ... | ... | ... |
177 | TLN0C | Causeway Coast and Glens | 17689.240685 |
178 | TLN0D | Antrim and Newtownabbey | 15235.628095 |
179 | TLN0E | Lisburn and Castlereagh | 14989.135261 |
180 | TLN0F | Mid and East Antrim | 17991.940009 |
181 | TLN0G | Fermanagh and Omagh | 17715.401263 |
182 rows × 3 columns
In [ ]:
co2_total_ITL3 = co2_total_ITL3.drop(columns=['ITL325NM'])
UK_distritos = UK_distritos.merge(co2_total_ITL3, on='ITL325CD', how='left')
UK_distritos = UK_distritos.rename(columns={'ITL325NM_x': 'ITL325NM'})
In [ ]:
UK_distritos.head()
Out[ ]:
FID | Condado | ITL325CD | ITL325NM | BNG_E | BNG_N | LAT | LONG | Shape__Are | Shape__Len | GlobalID | geometry | CO2 emissions within the scope of influence of LAs (kt CO2) | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 1 | TLC3 | TLC31 | Hartlepool and Stockton-on-Tees | 444955 | 522013 | 54.59133 | -1.30583 | 2.988302e+08 | 170566.054415 | 84c38a7b-d2d5-40c3-8318-03b9e802688e | MULTIPOLYGON (((447177.704 517811.797, 447176.... | 34159.566304 |
1 | 2 | TLC3 | TLC32 | South Teesside | 461690 | 519596 | 54.56785 | -1.04739 | 2.989886e+08 | 113668.576367 | 389163d9-2470-49b2-9711-c6721b4bbc1a | MULTIPOLYGON (((446854.7 517192.7, 446854.281 ... | 31781.439689 |
2 | 3 | TLC3 | TLC33 | Darlington | 428029 | 515648 | 54.53534 | -1.56836 | 1.974895e+08 | 107285.227956 | 4d1c9dc6-ea76-417c-b42f-a4ebc0af353b | POLYGON ((436388.002 522354.197, 436392.298 52... | 11104.755815 |
3 | 4 | TLC4 | TLC41 | Durham | 410383 | 532242 | 54.68513 | -1.84048 | 2.230843e+09 | 315818.035374 | 83db22e9-8b52-4968-9671-5ae6fbf40374 | POLYGON ((428366.003 554230.403, 428358.203 55... | 49527.654375 |
4 | 5 | TLC4 | TLC42 | Northumberland | 395323 | 600700 | 55.30038 | -2.07522 | 5.032309e+09 | 605682.922003 | da42f065-4f21-4705-a9b8-ac77b762a4e4 | MULTIPOLYGON (((429380.896 604848.303, 429384.... | 39641.088942 |
In [ ]:
condados_disueltos = UK_distritos.dissolve(
by='Condado',
aggfunc={
'CO2 emissions within the scope of influence of LAs (kt CO2)': 'sum'
}
).reset_index()
In [ ]:
fig, ax = plt.subplots(figsize=(12, 12))
condados_disueltos.plot(
column='CO2 emissions within the scope of influence of LAs (kt CO2)',
cmap='OrRd',
legend=True,
edgecolor='black',
linewidth=0.5,
ax=ax
)
Out[ ]:
<Axes: >
In [ ]:
#ejercicio 4
In [74]:
countries=gpd.read_file(os.path.join("https://github.com/Enrique867/Tarea5/raw/refs/heads/main/maps/World_Countries/World_Countries.shp"))
In [75]:
trainsGB=gpd.read_file(os.path.join("https://github.com/Enrique867/Tarea5/raw/refs/heads/main/trainsUK/hotosm_gbr_railways_lines_shp.shp"))
trainsNI=gpd.read_file(os.path.join("https://github.com/Enrique867/Tarea5/raw/refs/heads/main/trainsUK/Rail%20Line%20NI_polyline.shp"))
cities=gpd.read_file(os.path.join("https://github.com/Enrique867/Tarea5/raw/refs/heads/main/maps/World_Cities/World_Cities.shp"))
UK_condados=gpd.read_file(os.path.join("https://github.com/Enrique867/Tarea5/raw/refs/heads/main/ITL_2.zip/ITL2_JAN_2025_UK_BFC.shp"))
In [86]:
trainsUK = gpd.GeoDataFrame(
pd.concat([trainsGB, trainsNI], ignore_index=True),
crs=trainsGB.crs)
In [81]:
centroidX,centroidY=UK.centroid.x.values[0],UK.centroid.y.values[0]
In [55]:
CondadosN_UK=UK_condados.cx[:,centroidY:]
CondadosS_UK=UK_condados.cx[:,:centroidY]
CondadosW_UK=UK_condados.cx[:centroidX,:]
CondadosE_UK=UK_condados.cx[centroidX:,:]
In [29]:
base=CondadosN_UK.plot(facecolor='yellow', edgecolor='black',linewidth=0.2, alpha=0.6)
CondadosS_UK.plot(facecolor='grey', edgecolor='black',linewidth=0.2,ax=base, alpha=0.4)
Out[29]:
<Axes: >
In [30]:
base=CondadosW_UK.plot(facecolor='yellow', edgecolor='black',linewidth=0.2, alpha=0.6)
CondadosE_UK.plot(facecolor='grey', edgecolor='black',linewidth=0.2,ax=base, alpha=0.4)
Out[30]:
<Axes: >
In [31]:
CondadosNS_UK=CondadosN_UK.overlay(CondadosN_UK, how="intersection",keep_geom_type=True)
CondadosNS_UK.plot()
Out[31]:
<Axes: >
In [32]:
CondadosWE_UK=CondadosW_UK.overlay(CondadosW_UK, how="intersection",keep_geom_type=True)
CondadosWE_UK.plot(edgecolor='white',linewidth=0.1)
Out[32]:
<Axes: >
In [33]:
CondadosWE_UK.info()
<class 'geopandas.geodataframe.GeoDataFrame'> RangeIndex: 20 entries, 0 to 19 Data columns (total 15 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 ITL225CD_1 20 non-null object 1 ITL225NM_1 20 non-null object 2 BNG_E_1 20 non-null int64 3 BNG_N_1 20 non-null int64 4 LAT_1 20 non-null float64 5 LONG_1 20 non-null float64 6 GlobalID_1 20 non-null object 7 ITL225CD_2 20 non-null object 8 ITL225NM_2 20 non-null object 9 BNG_E_2 20 non-null int64 10 BNG_N_2 20 non-null int64 11 LAT_2 20 non-null float64 12 LONG_2 20 non-null float64 13 GlobalID_2 20 non-null object 14 geometry 20 non-null geometry dtypes: float64(4), geometry(1), int64(4), object(6) memory usage: 2.5+ KB
In [34]:
CondadosNS_UK.info()
<class 'geopandas.geodataframe.GeoDataFrame'> RangeIndex: 13 entries, 0 to 12 Data columns (total 15 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 ITL225CD_1 13 non-null object 1 ITL225NM_1 13 non-null object 2 BNG_E_1 13 non-null int64 3 BNG_N_1 13 non-null int64 4 LAT_1 13 non-null float64 5 LONG_1 13 non-null float64 6 GlobalID_1 13 non-null object 7 ITL225CD_2 13 non-null object 8 ITL225NM_2 13 non-null object 9 BNG_E_2 13 non-null int64 10 BNG_N_2 13 non-null int64 11 LAT_2 13 non-null float64 12 LONG_2 13 non-null float64 13 GlobalID_2 13 non-null object 14 geometry 13 non-null geometry dtypes: float64(4), geometry(1), int64(4), object(6) memory usage: 1.7+ KB
In [37]:
keep=['ITL225CD_1','ITL225NM_1','GlobalID_1','geometry']
CondadosNS_UK=CondadosNS_UK.loc[:,keep]
CondadosWE_UK=CondadosWE_UK.loc[:,keep]
In [38]:
CondadosNS_UK.overlay(CondadosWE_UK,how="union",keep_geom_type=True)
Out[38]:
ITL225CD_1_1 | ITL225NM_1_1 | GlobalID_1_1 | ITL225CD_1_2 | ITL225NM_1_2 | GlobalID_1_2 | geometry | |
---|---|---|---|---|---|---|---|
0 | TLD1 | Cumbria | e8182039-7db8-47da-b31b-39c7c470009d | TLD1 | Cumbria | e8182039-7db8-47da-b31b-39c7c470009d | MULTIPOLYGON (((321463.402 463796.099, 321460.... |
1 | TLD4 | Lancashire | 919d2406-9090-48eb-9aab-428eda32ab07 | TLD4 | Lancashire | 919d2406-9090-48eb-9aab-428eda32ab07 | MULTIPOLYGON (((337100.419 422524.789, 337105.... |
2 | TLM0 | Eastern Scotland | 75355100-fe6a-4ad6-81bd-10c99537dfe5 | TLM0 | Eastern Scotland | 75355100-fe6a-4ad6-81bd-10c99537dfe5 | MULTIPOLYGON (((318964.596 682700.398, 318969.... |
3 | TLM1 | East Central Scotland | 070abf73-8f7f-4138-9822-d14300a5da03 | TLM1 | East Central Scotland | 070abf73-8f7f-4138-9822-d14300a5da03 | MULTIPOLYGON (((327052.5 677766.95, 327059.5 6... |
4 | TLM2 | Highlands and Islands | 9deb9c1e-1145-4c42-b6cd-b32d7e32548a | TLM2 | Highlands and Islands | 9deb9c1e-1145-4c42-b6cd-b32d7e32548a | MULTIPOLYGON (((172458 604956, 172466 604952, ... |
5 | TLM3 | West Central Scotland | 91fbc12e-4bb9-47be-968d-102399fdff26 | TLM3 | West Central Scotland | 91fbc12e-4bb9-47be-968d-102399fdff26 | MULTIPOLYGON (((229634.09 675962.78, 229646.7 ... |
6 | TLM5 | North Eastern Scotland | 0f3efe9c-eb6f-4585-98ef-e870a4eb2cae | TLM5 | North Eastern Scotland | 0f3efe9c-eb6f-4585-98ef-e870a4eb2cae | MULTIPOLYGON (((396484.001 802544.804, 396484.... |
7 | TLM9 | Southern Scotland | 5a552fad-2af6-49e3-b9e0-0d7c60adb6f9 | TLM9 | Southern Scotland | 5a552fad-2af6-49e3-b9e0-0d7c60adb6f9 | MULTIPOLYGON (((265946.93 543512.52, 265948.43... |
8 | TLN0 | Northern Ireland | 1c66739f-16e6-4384-b834-757b0529dc2f | TLN0 | Northern Ireland | 1c66739f-16e6-4384-b834-757b0529dc2f | MULTIPOLYGON (((131193.943 468427.764, 131192.... |
9 | TLC3 | Tees Valley | 31050e7e-fd0d-4ed4-8ffd-071632345546 | NaN | NaN | NaN | MULTIPOLYGON (((450261.4 525942.2, 450262.1 52... |
10 | TLC4 | Northumberland, Durham and Tyne & Wear | a823ed47-990e-4223-8195-f73348847456 | NaN | NaN | NaN | MULTIPOLYGON (((439138.97 557651.26, 439138.92... |
11 | TLE1 | East Yorkshire and Northern Lincolnshire | 58211874-34d1-4928-a889-865cb9dc0100 | NaN | NaN | NaN | MULTIPOLYGON (((495629.401 422506.498, 495635.... |
12 | TLE2 | North Yorkshire | 7a7a08d0-8868-419e-8364-68e22a3eb85d | NaN | NaN | NaN | MULTIPOLYGON (((505962.5 486316.35, 505963.05 ... |
13 | NaN | NaN | NaN | TLD6 | Cheshire | 141c514d-0627-4ea9-89db-ed80594c541a | MULTIPOLYGON (((327869.488 373719.637, 327837.... |
14 | NaN | NaN | NaN | TLD7 | Merseyside | 4abb8a9c-eef1-4550-b7a0-4d15cceba614 | MULTIPOLYGON (((325664.303 377912.144, 325671.... |
15 | NaN | NaN | NaN | TLG1 | Herefordshire, Worcestershire and Warwickshire | ecfa81ab-e714-41a0-9e44-98621b8cfe6d | POLYGON ((445782.903 252431.302, 445771.5 2524... |
16 | NaN | NaN | NaN | TLG2 | Shropshire and Staffordshire | adbd0ec9-628b-4aad-a814-d8fc92eaf3ac | POLYGON ((427301.401 311488.097, 427309.901 31... |
17 | NaN | NaN | NaN | TLK3 | Cornwall and Isles of Scilly | 2ee3407f-aa42-4993-b89d-d9a3c9bb50a2 | MULTIPOLYGON (((83970.68 5400.71, 83977.49 540... |
18 | NaN | NaN | NaN | TLK4 | Devon | 050e0c96-4401-42c8-8bc1-73e8854e55c0 | MULTIPOLYGON (((276943.902 35609.726, 276944.9... |
19 | NaN | NaN | NaN | TLK5 | West of England | 3cab465e-39d9-4391-9836-44f68ebfd15b | MULTIPOLYGON (((352432.285 176257.871, 352429.... |
20 | NaN | NaN | NaN | TLK6 | North Somerset, Somerset and Dorset | 58a1f175-cbde-40d0-a912-230fcf8f7bc6 | MULTIPOLYGON (((369548.455 74734.759, 369545.5... |
21 | NaN | NaN | NaN | TLL3 | North Wales | 8331b973-16f4-4c41-a2c3-f82783b98b83 | MULTIPOLYGON (((257275.634 302831.29, 257275.7... |
22 | NaN | NaN | NaN | TLL4 | Mid and South West Wales | 55002d4b-cd76-4f8b-aa74-b2e86952a501 | MULTIPOLYGON (((247096.702 184269.203, 247097.... |
23 | NaN | NaN | NaN | TLL5 | South East Wales | 962c5c58-02a4-4ddd-ae4b-cc6520872eb1 | MULTIPOLYGON (((322082.004 165164.202, 322078.... |
In [39]:
import pandas as pd
pd.concat([CondadosNS_UK,CondadosWE_UK],ignore_index=True)
Out[39]:
ITL225CD_1 | ITL225NM_1 | GlobalID_1 | geometry | |
---|---|---|---|---|
0 | TLC3 | Tees Valley | 31050e7e-fd0d-4ed4-8ffd-071632345546 | MULTIPOLYGON (((450261.4 525942.2, 450262.1 52... |
1 | TLC4 | Northumberland, Durham and Tyne & Wear | a823ed47-990e-4223-8195-f73348847456 | MULTIPOLYGON (((439170.1 557624.08, 439145.89 ... |
2 | TLD1 | Cumbria | e8182039-7db8-47da-b31b-39c7c470009d | MULTIPOLYGON (((321473.197 463792.3, 321463.40... |
3 | TLD4 | Lancashire | 919d2406-9090-48eb-9aab-428eda32ab07 | MULTIPOLYGON (((337133.067 422467.758, 337100.... |
4 | TLE1 | East Yorkshire and Northern Lincolnshire | 58211874-34d1-4928-a889-865cb9dc0100 | MULTIPOLYGON (((495629.401 422506.498, 495635.... |
5 | TLE2 | North Yorkshire | 7a7a08d0-8868-419e-8364-68e22a3eb85d | MULTIPOLYGON (((505960.7 486316.25, 505961.6 4... |
6 | TLM0 | Eastern Scotland | 75355100-fe6a-4ad6-81bd-10c99537dfe5 | MULTIPOLYGON (((318942.301 682697.599, 318964.... |
7 | TLM1 | East Central Scotland | 070abf73-8f7f-4138-9822-d14300a5da03 | MULTIPOLYGON (((327045.25 677764.7, 327052.5 6... |
8 | TLM2 | Highlands and Islands | 9deb9c1e-1145-4c42-b6cd-b32d7e32548a | MULTIPOLYGON (((172449 604956, 172458 604956, ... |
9 | TLM3 | West Central Scotland | 91fbc12e-4bb9-47be-968d-102399fdff26 | MULTIPOLYGON (((229622.65 675961.45, 229634.09... |
10 | TLM5 | North Eastern Scotland | 0f3efe9c-eb6f-4585-98ef-e870a4eb2cae | MULTIPOLYGON (((396491.999 802544.404, 396484.... |
11 | TLM9 | Southern Scotland | 5a552fad-2af6-49e3-b9e0-0d7c60adb6f9 | MULTIPOLYGON (((265945.83 543512.52, 265946.93... |
12 | TLN0 | Northern Ireland | 1c66739f-16e6-4384-b834-757b0529dc2f | MULTIPOLYGON (((131196.032 468425.601, 131193.... |
13 | TLD1 | Cumbria | e8182039-7db8-47da-b31b-39c7c470009d | MULTIPOLYGON (((321473.197 463792.3, 321463.40... |
14 | TLD4 | Lancashire | 919d2406-9090-48eb-9aab-428eda32ab07 | MULTIPOLYGON (((337133.067 422467.758, 337100.... |
15 | TLD6 | Cheshire | 141c514d-0627-4ea9-89db-ed80594c541a | MULTIPOLYGON (((327869.488 373719.637, 327837.... |
16 | TLD7 | Merseyside | 4abb8a9c-eef1-4550-b7a0-4d15cceba614 | MULTIPOLYGON (((325654.061 377911.814, 325664.... |
17 | TLG1 | Herefordshire, Worcestershire and Warwickshire | ecfa81ab-e714-41a0-9e44-98621b8cfe6d | POLYGON ((445782.903 252431.302, 445771.5 2524... |
18 | TLG2 | Shropshire and Staffordshire | adbd0ec9-628b-4aad-a814-d8fc92eaf3ac | POLYGON ((427301.401 311488.097, 427309.901 31... |
19 | TLK3 | Cornwall and Isles of Scilly | 2ee3407f-aa42-4993-b89d-d9a3c9bb50a2 | MULTIPOLYGON (((83970.68 5400.71, 83977.49 540... |
20 | TLK4 | Devon | 050e0c96-4401-42c8-8bc1-73e8854e55c0 | MULTIPOLYGON (((276943.902 35609.726, 276944.9... |
21 | TLK5 | West of England | 3cab465e-39d9-4391-9836-44f68ebfd15b | MULTIPOLYGON (((352432.285 176257.871, 352429.... |
22 | TLK6 | North Somerset, Somerset and Dorset | 58a1f175-cbde-40d0-a912-230fcf8f7bc6 | MULTIPOLYGON (((369548.455 74734.759, 369545.5... |
23 | TLL3 | North Wales | 8331b973-16f4-4c41-a2c3-f82783b98b83 | MULTIPOLYGON (((257275.634 302831.29, 257275.7... |
24 | TLL4 | Mid and South West Wales | 55002d4b-cd76-4f8b-aa74-b2e86952a501 | MULTIPOLYGON (((247096.702 184269.203, 247097.... |
25 | TLL5 | South East Wales | 962c5c58-02a4-4ddd-ae4b-cc6520872eb1 | MULTIPOLYGON (((322082.004 165164.202, 322078.... |
26 | TLM0 | Eastern Scotland | 75355100-fe6a-4ad6-81bd-10c99537dfe5 | MULTIPOLYGON (((318942.301 682697.599, 318964.... |
27 | TLM1 | East Central Scotland | 070abf73-8f7f-4138-9822-d14300a5da03 | MULTIPOLYGON (((327045.25 677764.7, 327052.5 6... |
28 | TLM2 | Highlands and Islands | 9deb9c1e-1145-4c42-b6cd-b32d7e32548a | MULTIPOLYGON (((172449 604956, 172458 604956, ... |
29 | TLM3 | West Central Scotland | 91fbc12e-4bb9-47be-968d-102399fdff26 | MULTIPOLYGON (((229622.65 675961.45, 229634.09... |
30 | TLM5 | North Eastern Scotland | 0f3efe9c-eb6f-4585-98ef-e870a4eb2cae | MULTIPOLYGON (((396491.999 802544.404, 396484.... |
31 | TLM9 | Southern Scotland | 5a552fad-2af6-49e3-b9e0-0d7c60adb6f9 | MULTIPOLYGON (((265945.83 543512.52, 265946.93... |
32 | TLN0 | Northern Ireland | 1c66739f-16e6-4384-b834-757b0529dc2f | MULTIPOLYGON (((131196.032 468425.601, 131193.... |
In [40]:
CondadosNS_UK.overlay(CondadosWE_UK, how="union",keep_geom_type=True).dissolve().plot()
Out[40]:
<Axes: >
In [41]:
CondadosMidUK=CondadosNS_UK.overlay(CondadosWE_UK, how="union",keep_geom_type=True).dissolve()
CondadosMidUK
Out[41]:
geometry | ITL225CD_1_1 | ITL225NM_1_1 | GlobalID_1_1 | ITL225CD_1_2 | ITL225NM_1_2 | GlobalID_1_2 | |
---|---|---|---|---|---|---|---|
0 | MULTIPOLYGON (((55747.501 780589.998, 55749.49... | TLD1 | Cumbria | e8182039-7db8-47da-b31b-39c7c470009d | TLD1 | Cumbria | e8182039-7db8-47da-b31b-39c7c470009d |
In [43]:
CondadosMidUK['zone']='middles'
CondadosMidUK=CondadosMidUK.loc[:,['ITL225CD_1_1','zone','geometry']]
CondadosMidUK
Out[43]:
ITL225CD_1_1 | zone | geometry | |
---|---|---|---|
0 | TLD1 | middles | MULTIPOLYGON (((55747.501 780589.998, 55749.49... |
In [59]:
UK_condados.overlay(CondadosMidUK, how='difference').plot()
Out[59]:
<Axes: >
In [60]:
CondadosN_UK.overlay(CondadosS_UK, how="symmetric_difference",keep_geom_type=True).plot()
Out[60]:
<Axes: >
In [61]:
CondadosW_UK.overlay(CondadosMidUK, how="symmetric_difference",keep_geom_type=False).plot()
Out[61]:
<Axes: >
In [ ]:
#ejercicio 3
In [70]:
UK_regiones=gpd.read_file("https://github.com/Enrique867/Tarea5/raw/refs/heads/main/ITL_1/ITL1_JAN_2025_UK_BFC.shp")
In [92]:
regiones_norte = UK.cx[:,461155.382:]
regiones_norte = UK.cx[:,461155.382:]
# 2. Recortamos los ríos usando clip
train_clipped = clip(trainsUK, regiones_norte)
In [104]:
base = UK.plot(facecolor="silver", edgecolor='black', linewidth=0.4,figsize=(15,15))
UK_regiones.plot(facecolor='lightgrey', edgecolor='black',linewidth=0.3,
ax=base)
# Check if train_clipped is not empty before plotting
if not train_clipped.empty:
train_clipped.plot(ax=base, edgecolor='blue', linewidth=0.3)
else:
print("train_clipped is empty and will not be plotted.") # Optional: print a message
citiesUK.cx[:,:461155.382].plot(marker='+', color='red', markersize=90,
ax=base)
UK.centroid.plot(color='red',ax=base)
Out[104]:
<Axes: >
In [103]:
base = UK.plot(facecolor="silver", edgecolor='black', linewidth=0.4,figsize=(15,15))
UK_regiones.plot(facecolor='lightgrey', edgecolor='black',linewidth=0.3,
ax=base)
citiesUK.cx[:,:461155.382].dissolve().convex_hull.plot(ax=base, color='blue')
Out[103]:
<Axes: >
In [122]:
base = UK.plot(facecolor="silver", edgecolor='black', linewidth=0.4,figsize=(15,15))
UK_regiones.plot(facecolor='lightgrey', edgecolor='black',linewidth=0.3,
ax=base)
train_clipped.cx[:,348609.801:461155.382,].dissolve().convex_hull.plot(ax=base, color='blue')
Out[122]:
<Axes: >
In [ ]: