Exercise 1¶
Use two maps of points from your country.
Compute the distance matrix for both maps.
Select one row of the distance matrix, and plot the two points with the minimal distance on top of the country of your choosing.
import geopandas as gpd
centrales_electricas=gpd.read_file('https://github.com/valeriacaroe/Parte1/raw/refs/heads/main/maps/puntos_de_energia_AD010/puntos_de_energia_AD010Point.shp')
aeropuertos=gpd.read_file('https://github.com/valeriacaroe/Parte1/raw/refs/heads/main/aeropuertos/aeropuertos/puntos_de_transporte_aereo_GB005Point.shp')
centrales_electricas=centrales_electricas.to_crs(5343)
aeropuertos=aeropuertos.to_crs(5343)
powerplant = centrales_electricas[centrales_electricas['fdc'] == 'IGN01']
powerplant.reset_index(drop=True, inplace=True)
import pandas as pd
portsFileLink="https://github.com/CienciaDeDatosEspacial/GeoDataFrame_Analytics/raw/main/data/UpdatedPub150.csv"
infoseaports=pd.read_csv(portsFileLink)
Let's do some preprocessing:
#rename
infoseaports.rename(columns={'Main Port Name':'portName'},inplace=True)
#keep few columns
infoseaports=infoseaports.loc[:,['portName', 'Country Code','Latitude', 'Longitude']]
# we have now
infoseaports.info()
<class 'pandas.core.frame.DataFrame'> RangeIndex: 3739 entries, 0 to 3738 Data columns (total 4 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 portName 3739 non-null object 1 Country Code 3739 non-null object 2 Latitude 3739 non-null float64 3 Longitude 3739 non-null float64 dtypes: float64(2), object(2) memory usage: 117.0+ KB
Let's turn those points into projected spatial object (GDF of points):
#spatial points (unprojected)
seaports=gpd.GeoDataFrame(data=infoseaports.copy(),
geometry=gpd.points_from_xy(infoseaports.Longitude,
infoseaports.Latitude),
crs=4326)# notice it is unprojected
# keep Brazil
main_port_arg=seaports[seaports['Country Code']=='Argentina'].copy()
# reset indexes
main_port_arg.reset_index(drop=True, inplace=True)
# reprojecting
main_port_arg=main_port_arg.to_crs(5641) # projected crs
Let me plot seaports along with the large airports:
#plotting
base=powerplant.plot(color='red',marker="^")
main_port_arg.plot(ax=base,alpha=0.5,markersize=3)
<Axes: >
powerplant.head()
gid | entidad | objeto | fna | gna | nam | fun | ppc | sag | fdc | geometry | |
---|---|---|---|---|---|---|---|---|---|---|---|
0 | 766 | 0.0 | Central Eléctrica | Estación Hidrológica Piedras Pintadas | Estación Hidrológica | Piedras Pintadas | 6.0 | -2.0 | IGN | IGN01 | POINT (1774703.306 6700135.505) |
1 | 769 | 0.0 | Central Eléctrica | Usina Hidroeléctrica Don Claudio Tinto | Usina Hidroeléctrica | Don Claudio Tinto | -1.0 | 1.0 | IGN | IGN01 | POINT (1733078.976 6527474.731) |
2 | 774 | 0.0 | Central Eléctrica | Central Hidroeléctrica Los Caracoles | Central Hidroeléctrica | Los Caracoles | 6.0 | 1.0 | IGN | IGN01 | POINT (1788058.68 6509679.877) |
3 | 775 | 0.0 | Central Eléctrica | Central Hidroelectrica Albardón | Central Hidroelectrica | Albardón | 6.0 | 1.0 | IGN | IGN01 | POINT (1828570.783 6515681.321) |
4 | 776 | 0.0 | Central Eléctrica | Usina Vitry | Usina | Vitry | 6.0 | 7.0 | IGN | IGN01 | POINT (1823052.017 6510564.832) |
main_port_arg.head()
portName | Country Code | Latitude | Longitude | geometry | |
---|---|---|---|---|---|
0 | Puerto Madryn | Argentina | -42.766667 | -65.033333 | POINT (2548744.739 4755674.117) |
1 | Mar Del Plata | Argentina | -38.033333 | -57.533333 | POINT (3383135.726 5444951.404) |
2 | La Plata | Argentina | -34.833333 | -57.883333 | POINT (3344197.48 5885642.645) |
3 | Buenos Aires | Argentina | -34.600000 | -58.366667 | POINT (3290425.542 5917080.406) |
4 | Puerto Rosales | Argentina | -38.933333 | -62.066667 | POINT (2878792.655 5317564.031) |
What about computing all possible distances between those GDFs?
Let's keep the last one:
distanceMatrixKM_port_powerplant= main_port_arg.set_index('portName').geometry.apply\
(lambda g: powerplant.set_index('fna').geometry.distance(g)/1000).\
sort_index(axis=0).sort_index(axis=1)
distanceMatrixKM_port_powerplant
fna | Central Hidroelectrica Albardón | Central Hidroeléctrica Los Caracoles | Central Térmica El Portón | Central Térmica Piedras Negras | Estación Hidrológica Piedras Pintadas | Usina Hidroeléctrica Don Claudio Tinto | Usina Vitry |
---|---|---|---|---|---|---|---|
portName | |||||||
Bahia Blanca | 1562.537245 | 1585.044408 | 1271.558750 | 1144.136723 | 1738.769098 | 1635.500680 | 1562.332757 |
Buenos Aires | 1579.665278 | 1615.017127 | 1582.433169 | 1469.415479 | 1706.044895 | 1672.695297 | 1582.848327 |
Campana | 1495.324676 | 1531.094405 | 1518.166782 | 1407.788791 | 1619.190134 | 1588.833060 | 1498.647196 |
Colon | 1514.379085 | 1553.119592 | 1645.311094 | 1546.139920 | 1610.820112 | 1610.407070 | 1518.858967 |
Comodoro Rivadavia | 2285.179968 | 2287.629542 | 1707.883878 | 1620.698208 | 2476.681285 | 2317.324343 | 2281.257905 |
Concepcion Del Uruguay | 1510.405525 | 1548.819033 | 1627.354725 | 1526.612454 | 1610.719364 | 1606.266286 | 1514.738580 |
Concordia | 1509.237569 | 1548.810178 | 1681.767138 | 1587.718687 | 1594.096474 | 1605.453251 | 1514.132799 |
Diamante | 1236.087460 | 1274.479719 | 1378.045243 | 1284.199483 | 1338.622373 | 1331.932444 | 1240.407644 |
La Plata | 1641.363158 | 1676.600856 | 1635.883938 | 1521.640938 | 1768.250712 | 1734.258129 | 1644.509428 |
Mar Del Plata | 1887.626741 | 1917.789744 | 1731.717479 | 1606.613831 | 2040.230863 | 1973.459913 | 1889.283768 |
Parana | 1239.971752 | 1278.872843 | 1403.316805 | 1312.033180 | 1336.446470 | 1336.062928 | 1244.523664 |
Puerto Belgrano | 1585.454639 | 1608.055090 | 1294.422413 | 1167.003023 | 1761.450148 | 1658.578598 | 1585.271750 |
Puerto Deseado | 2621.052118 | 2625.180830 | 2054.701445 | 1964.236333 | 2813.038930 | 2656.754635 | 2617.404241 |
Puerto Gallegos | 3221.638624 | 3219.473364 | 2610.012574 | 2540.678468 | 3410.312761 | 3243.127671 | 3217.031423 |
Puerto Galvan | 1560.100062 | 1582.546956 | 1268.211063 | 1140.789694 | 1736.464228 | 1632.955541 | 1559.882134 |
Puerto Ibicuy | 1454.197706 | 1490.514356 | 1498.353126 | 1390.490892 | 1574.222229 | 1548.296641 | 1457.710146 |
Puerto Ingeniero White | 1564.322361 | 1586.795243 | 1272.578440 | 1145.157344 | 1740.624550 | 1637.223310 | 1564.110356 |
Puerto Madryn | 1901.650831 | 1911.852371 | 1407.887314 | 1296.852135 | 2092.861732 | 1950.535325 | 1899.018522 |
Puerto Nacional | 1563.104573 | 1585.547341 | 1270.905739 | 1143.485095 | 1739.472773 | 1635.951562 | 1562.885855 |
Puerto Rosales | 1593.251713 | 1615.809641 | 1300.856843 | 1173.441991 | 1769.326757 | 1666.296413 | 1593.059699 |
Puerto San Julian | 2839.970259 | 2840.372422 | 2244.591194 | 2166.152322 | 3030.504324 | 2867.369455 | 2835.740769 |
Puerto San Martin | 1248.063634 | 1285.408496 | 1348.724256 | 1249.832791 | 1360.920187 | 1343.143464 | 1251.953380 |
Puerto Santa Cruz | 2947.036083 | 2945.930140 | 2341.928533 | 2268.599189 | 3136.562228 | 2971.005939 | 2942.581463 |
Quequen | 1829.962862 | 1857.982316 | 1629.519705 | 1503.050968 | 1990.687385 | 1912.385032 | 1831.063967 |
Ramallo | 1354.972034 | 1391.332146 | 1410.225369 | 1304.745935 | 1475.250628 | 1449.116363 | 1358.497950 |
Rio Grande | 3631.118169 | 3630.134527 | 3025.242758 | 2952.777782 | 3820.745639 | 3655.211319 | 3626.688481 |
Rosario | 1267.597124 | 1304.586902 | 1353.551070 | 1252.683793 | 1383.396216 | 1362.359709 | 1271.351664 |
San Blas | 1766.185302 | 1785.349309 | 1404.230525 | 1278.774589 | 1948.417247 | 1832.897975 | 1765.271916 |
San Lorenzo | 1249.294208 | 1286.582886 | 1347.812218 | 1248.657434 | 1362.642848 | 1344.325495 | 1253.162220 |
San Nicolas | 1325.676642 | 1362.189510 | 1389.063574 | 1284.851600 | 1444.955533 | 1419.977001 | 1329.256779 |
San Pedro | 1380.378461 | 1416.666508 | 1430.675182 | 1324.343186 | 1501.052216 | 1474.447869 | 1383.879263 |
San Sebastian Bay | 3507.109332 | 3505.237819 | 2896.557734 | 2826.711511 | 3696.035984 | 3529.207004 | 3502.547643 |
Santa Fe | 1220.208747 | 1259.165176 | 1388.220033 | 1297.884673 | 1316.157764 | 1316.319786 | 1224.786793 |
Ushuaia | 3819.383366 | 3817.411262 | 3207.865087 | 3138.730586 | 4008.227963 | 3841.194319 | 3814.809402 |
Villa Constitucion | 1310.890693 | 1347.528734 | 1380.050811 | 1276.671881 | 1429.275088 | 1405.316112 | 1314.515950 |
Villa Constitucion | 1313.720621 | 1350.242636 | 1378.707640 | 1274.843205 | 1433.007950 | 1408.030212 | 1317.303798 |
Zarate | 1485.206065 | 1521.051395 | 1511.334626 | 1401.374532 | 1608.579836 | 1578.798546 | 1488.554323 |
third_row_distances = distanceMatrixKM_port_powerplant.iloc[2]
third_row_distances
Campana | |
---|---|
fna | |
Central Hidroelectrica Albardón | 1495.324676 |
Central Hidroeléctrica Los Caracoles | 1531.094405 |
Central Térmica El Portón | 1518.166782 |
Central Térmica Piedras Negras | 1407.788791 |
Estación Hidrológica Piedras Pintadas | 1619.190134 |
Usina Hidroeléctrica Don Claudio Tinto | 1588.833060 |
Usina Vitry | 1498.647196 |
min_powerplant_name = third_row_distances.idxmin()
min_powerplant_name
'Central Térmica Piedras Negras'
campana=main_port_arg[main_port_arg.portName.str.contains('Campana')]
campana
portName | Country Code | Latitude | Longitude | geometry | |
---|---|---|---|---|---|
35 | Campana | Argentina | -34.15 | -58.966667 | POINT (3223674.263 5977460.02) |
piedrasNegras = powerplant[powerplant.fna == min_powerplant_name]
piedrasNegras
gid | entidad | objeto | fna | gna | nam | fun | ppc | sag | fdc | geometry | |
---|---|---|---|---|---|---|---|---|---|---|---|
5 | 802 | 0.0 | Central Eléctrica | Central Térmica Piedras Negras | Central Térmica | Piedras Negras | 6.0 | 7.0 | IGN | IGN01 | POINT (1823544.924 5830806.987) |
%pip install folium matplotlib mapclassify
Requirement already satisfied: folium in /usr/local/lib/python3.11/dist-packages (0.19.7) Requirement already satisfied: matplotlib in /usr/local/lib/python3.11/dist-packages (3.10.0) Requirement already satisfied: mapclassify in /usr/local/lib/python3.11/dist-packages (2.9.0) Requirement already satisfied: branca>=0.6.0 in /usr/local/lib/python3.11/dist-packages (from folium) (0.8.1) Requirement already satisfied: jinja2>=2.9 in /usr/local/lib/python3.11/dist-packages (from folium) (3.1.6) Requirement already satisfied: numpy in /usr/local/lib/python3.11/dist-packages (from folium) (2.0.2) Requirement already satisfied: requests in /usr/local/lib/python3.11/dist-packages (from folium) (2.32.3) Requirement already satisfied: xyzservices in /usr/local/lib/python3.11/dist-packages (from folium) (2025.4.0) Requirement already satisfied: contourpy>=1.0.1 in /usr/local/lib/python3.11/dist-packages (from matplotlib) (1.3.2) Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.11/dist-packages (from matplotlib) (0.12.1) Requirement already satisfied: fonttools>=4.22.0 in /usr/local/lib/python3.11/dist-packages (from matplotlib) (4.58.4) Requirement already satisfied: kiwisolver>=1.3.1 in /usr/local/lib/python3.11/dist-packages (from matplotlib) (1.4.8) Requirement already satisfied: packaging>=20.0 in /usr/local/lib/python3.11/dist-packages (from matplotlib) (24.2) Requirement already satisfied: pillow>=8 in /usr/local/lib/python3.11/dist-packages (from matplotlib) (11.2.1) Requirement already satisfied: pyparsing>=2.3.1 in /usr/local/lib/python3.11/dist-packages (from matplotlib) (3.2.3) Requirement already satisfied: python-dateutil>=2.7 in /usr/local/lib/python3.11/dist-packages (from matplotlib) (2.9.0.post0) Requirement already satisfied: networkx>=3.2 in /usr/local/lib/python3.11/dist-packages (from mapclassify) (3.5) Requirement already satisfied: pandas>=2.1 in /usr/local/lib/python3.11/dist-packages (from mapclassify) (2.2.2) Requirement already satisfied: scikit-learn>=1.4 in /usr/local/lib/python3.11/dist-packages (from mapclassify) (1.6.1) Requirement already satisfied: scipy>=1.12 in /usr/local/lib/python3.11/dist-packages (from mapclassify) (1.15.3) Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.11/dist-packages (from jinja2>=2.9->folium) (3.0.2) Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.11/dist-packages (from pandas>=2.1->mapclassify) (2025.2) Requirement already satisfied: tzdata>=2022.7 in /usr/local/lib/python3.11/dist-packages (from pandas>=2.1->mapclassify) (2025.2) Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.11/dist-packages (from python-dateutil>=2.7->matplotlib) (1.17.0) Requirement already satisfied: joblib>=1.2.0 in /usr/local/lib/python3.11/dist-packages (from scikit-learn>=1.4->mapclassify) (1.5.1) Requirement already satisfied: threadpoolctl>=3.1.0 in /usr/local/lib/python3.11/dist-packages (from scikit-learn>=1.4->mapclassify) (3.6.0) Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.11/dist-packages (from requests->folium) (3.4.2) Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.11/dist-packages (from requests->folium) (3.10) Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.11/dist-packages (from requests->folium) (2.4.0) Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.11/dist-packages (from requests->folium) (2025.6.15)
base=campana.explore(color='red',marker_kwds=dict(radius=10))
piedrasNegras.explore(m=base,color='blue',marker_kwds=dict(radius=10))
DISTANCE BETWEEN LINE AND POINT¶
Exercise 2¶
Use a map of points and a map of lines from your country.
Compute the distance matrix for both.
Select one line of the distance matrix, and plot the closests and the farthest point to that line.
Let's take a look at the rivers we have:
ferrovias = gpd.read_file('https://github.com/valeriacaroe/Parte1/raw/refs/heads/main/maps/lineas_de_transporte_ferroviario_AN010/lineas_de_transporte_ferroviario_AN010Line.shp')
ferrovias=ferrovias.to_crs(5641)
ferrovias.fdc.unique()
array(['IGN/Trenes Argentinos Cargas', 'IGN', 'Imagery/IGN01/Ministerio de Transporte de la Nación/Dir. GeografÃa IGN', 'IGN/Ministerio de Transporte de la Nación', 'IGN/Ministerio de Transporte de la Nación/Ferroexpreso Pampeano', 'IGN/Ministerio de Transporte de la Nación/Ferrosur', 'IGN/Pagina web institucional', 'IGN/Tren Roca', 'IGN/Ministerio de Transporte de la Nación/NCA', 'IGN/Tren Belgrano Sur', 'IGN/Tren General Belgrano Sur', 'IGN/Tren Roca/Ferrosur', 'IGN/Tren Sarmiento', 'IGN/Ministerio de Transporte de la Nación/Trenes Argentinos Cargas', 'IGN/Tren Mitre', 'IGN/Tren Belgrano Norte', 'IGN/Tren San MartÃn', 'IGN/Tren Urquiza', 'IGN/Tren de la Costa', 'IGN/Parque Nacional Iguazú', 'IGN/Ministerio de Transporte de la Naciónl/Decreto 153/2003', 'Esri-world_imagery-2010/IGN04/Ministerio de Transporte de la Nación/Dir. GeografÃa IGN', 'Esri-Word_Imagery/IGN04/IGN Dirección de GeografÃa/Ferrosur', 'Esri-world_imagery-2010/Ministerio de Transporte de la Nación/Dir. GeografÃa IGN', 'Esri-Word_Imagery/IGN04/Ministerio de Transporte de la Nación/Ferrosur', 'IGN/Ministerio de Transporte de la Nación/Pagina Web empresa', 'IGN04/Ministerio de Transporte de la Nación/Ferrosur', 'Esri-world_imagery-2010/IGN01/Ministerio de Transporte de la Nación/Dir. GeografÃa IGN', 'Esri-World_imageryIGN01/Ministerio de Transporte de la Nación/IGN Dirección de GeografÃa', 'Esri-Word_Imagery/IG0N04/Ministerio de Transporte de la Nación/Ferrosur', 'IGN/Ministerio de la Nación/Dir. GeografÃa IGN/Sitio web del concesionario', 'IGN01/Ministerio de Transporte'], dtype=object)
print(ferrovias['fdc'].value_counts())
fdc IGN/Trenes Argentinos Cargas 376 IGN/Ministerio de Transporte de la Nación 327 IGN/Ministerio de Transporte de la Nación/NCA 117 IGN/Ministerio de Transporte de la Nación/Ferrosur 67 IGN/Ministerio de Transporte de la Nación/Ferroexpreso Pampeano 55 IGN 46 IGN/Tren Roca 25 IGN/Tren Mitre 13 IGN/Ministerio de Transporte de la Nación/Trenes Argentinos Cargas 8 IGN/Tren Belgrano Sur 7 IGN/Tren San MartÃn 6 IGN/Tren Belgrano Norte 5 IGN/Ministerio de Transporte de la Nación/Pagina Web empresa 4 IGN04/Ministerio de Transporte de la Nación/Ferrosur 4 IGN/Ministerio de Transporte de la Naciónl/Decreto 153/2003 4 IGN/Tren General Belgrano Sur 3 IGN/Tren Sarmiento 3 Esri-world_imagery-2010/IGN01/Ministerio de Transporte de la Nación/Dir. GeografÃa IGN 2 IGN/Tren Roca/Ferrosur 2 Esri-World_imageryIGN01/Ministerio de Transporte de la Nación/IGN Dirección de GeografÃa 2 IGN/Parque Nacional Iguazú 2 Esri-world_imagery-2010/IGN04/Ministerio de Transporte de la Nación/Dir. GeografÃa IGN 2 IGN/Tren de la Costa 2 IGN/Tren Urquiza 2 Imagery/IGN01/Ministerio de Transporte de la Nación/Dir. GeografÃa IGN 1 IGN/Pagina web institucional 1 Esri-world_imagery-2010/Ministerio de Transporte de la Nación/Dir. GeografÃa IGN 1 Esri-Word_Imagery/IGN04/IGN Dirección de GeografÃa/Ferrosur 1 Esri-Word_Imagery/IGN04/Ministerio de Transporte de la Nación/Ferrosur 1 Esri-Word_Imagery/IG0N04/Ministerio de Transporte de la Nación/Ferrosur 1 IGN/Ministerio de la Nación/Dir. GeografÃa IGN/Sitio web del concesionario 1 IGN01/Ministerio de Transporte 1 Name: count, dtype: int64
trenesDeCarga = ferrovias[ferrovias.fdc == 'IGN/Ministerio de Transporte de la Nación/Trenes Argentinos Cargas']
trenesDeCarga.drop_duplicates(subset=['fna'], inplace=True)
trenesDeCarga.reset_index(drop=True, inplace=True)
trenesDeCarga
/tmp/ipython-input-70-2031160285.py:2: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy trenesDeCarga.drop_duplicates(subset=['fna'], inplace=True)
gid | entidad | objeto | fna | gna | nam | fun | rgc | ltn | loc | fdc | sag | geometry | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 340 | 0.0 | Ferrocarril | Ferrocarril General San MartÃn Ramal SMB - Junin | Ferrocarril Nacional | General San MartÃn Ramal SMB - Junin | 6.0 | 1.0 | 1.0 | 44.0 | IGN/Ministerio de Transporte de la Nación/Tren... | IGN | LINESTRING (3100453.44 5915679.702, 3103553.31... |
1 | 400 | 0.0 | Ferrocarril | Ferrocarril Nacional General Belgrano Ramal F1 | Ferrocarril Nacional | General Belgrano Ramal F1 | 6.0 | 2.0 | 1.0 | 44.0 | IGN/Ministerio de Transporte de la Nación/Tren... | IGN | LINESTRING (3029107.645 6150749.166, 3029234.6... |
2 | 713 | 0.0 | Ferrocarril | Ferrocarril Nacional General Belgrano Ramal C3 | Ferrocarril Nacional | General Belgrano Ramal C3 | 6.0 | 2.0 | 1.0 | 44.0 | IGN/Ministerio de Transporte de la Nación/Tren... | IGN | LINESTRING (2963794.384 6855066.915, 2968665.2... |
3 | 954 | 0.0 | Ferrocarril | Ferrocarril Nacional General San MartÃn Ramal ... | Ferrocarril Nacional | General San MartÃn Ramal SMC - Junin | 6.0 | 1.0 | 1.0 | 44.0 | IGN/Ministerio de Transporte de la Nación/Tren... | IGN | LINESTRING (3003050.282 5919220.443, 3003214.6... |
4 | 959 | 0.0 | Ferrocarril | Ferrocarril Nacional General Belgrano Ramal F ... | Ferrocarril Nacional | General Belgrano Ramal F - Los Amores | 6.0 | 2.0 | 1.0 | 44.0 | IGN/Ministerio de Transporte de la Nación/Tren... | IGN | LINESTRING (3211809.33 6847876.308, 3208420.27... |
5 | 956 | 0.0 | Ferrocarril | Ferrocarril Nacional General Belgrano Ramal C6 | Ferrocarril Nacional | General Belgrano Ramal C6 | 6.0 | 2.0 | 1.0 | 44.0 | IGN/Ministerio de Transporte de la Nación/Tren... | IGN | LINESTRING (2953064.51 6783525.133, 2953480.88... |
trenesDeCarga.plot()
<Axes: >
# Drop duplicates in main_port_arg based on 'portName' before setting the index
distanceMatrixKM_2 = trenesDeCarga.drop_duplicates(subset=['fna']).set_index('fna').geometry.apply \
(lambda g: main_port_arg.drop_duplicates(subset=['portName']).set_index('portName').geometry.distance(g) / 1000). \
sort_index(axis=0).sort_index(axis=1)
distanceMatrixKM_2
portName | Bahia Blanca | Buenos Aires | Campana | Colon | Comodoro Rivadavia | Concepcion Del Uruguay | Concordia | Diamante | La Plata | Mar Del Plata | ... | Rosario | San Blas | San Lorenzo | San Nicolas | San Pedro | San Sebastian Bay | Santa Fe | Ushuaia | Villa Constitucion | Zarate |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
fna | |||||||||||||||||||||
Ferrocarril General San MartÃn Ramal SMB - Junin | 626.226163 | 123.444233 | 89.868672 | 355.786962 | 1835.144247 | 319.618524 | 457.390154 | 343.236547 | 178.174291 | 510.321345 | ... | 229.806494 | 867.461510 | 258.218794 | 171.452081 | 137.373325 | 3039.285717 | 397.660848 | 3330.863637 | 186.028537 | 92.709593 |
Ferrocarril Nacional General Belgrano Ramal C3 | 1519.948463 | 993.230388 | 915.276687 | 714.805953 | 2669.513570 | 740.209654 | 630.811905 | 606.541616 | 1041.388462 | 1471.146803 | ... | 722.007947 | 1775.950161 | 694.691028 | 777.999724 | 818.893203 | 3913.302842 | 551.954230 | 4214.590763 | 763.261261 | 904.631951 |
Ferrocarril Nacional General Belgrano Ramal C6 | 1447.838923 | 929.805856 | 850.276781 | 659.377658 | 2597.628606 | 683.009686 | 580.704146 | 537.142508 | 979.376312 | 1405.966172 | ... | 652.204019 | 1703.917044 | 624.662478 | 709.267116 | 751.404906 | 3841.081440 | 482.633119 | 4142.298938 | 694.262586 | 839.473013 |
Ferrocarril Nacional General Belgrano Ramal F - Los Amores | 1443.955561 | 862.105095 | 790.906985 | 565.657215 | 2620.994075 | 594.624812 | 473.117510 | 512.837071 | 905.223454 | 1343.211612 | ... | 627.593637 | 1696.760986 | 602.863091 | 674.655679 | 707.485119 | 3854.088971 | 460.103162 | 4151.774350 | 661.988224 | 781.046624 |
Ferrocarril Nacional General Belgrano Ramal F1 | 829.979647 | 350.552824 | 260.546501 | 297.869931 | 2020.403895 | 279.494453 | 349.058018 | 89.281776 | 411.773449 | 789.611527 | ... | 16.589651 | 1081.870112 | 0.754682 | 83.920102 | 139.816739 | 3243.929202 | 143.034148 | 3539.791691 | 66.622348 | 249.081705 |
Ferrocarril Nacional General San MartÃn Ramal SMC - Junin | 598.521578 | 284.798422 | 225.434623 | 441.135373 | 1796.846885 | 408.833877 | 528.759739 | 334.146550 | 340.308636 | 606.895340 | ... | 219.189627 | 849.175534 | 244.058054 | 183.087935 | 181.383015 | 3014.070820 | 387.860092 | 3308.860630 | 191.059641 | 220.778437 |
6 rows × 36 columns
Here, we see one row (river), that tells the distance to each column (large airport):
distances_SMB = distanceMatrixKM_2.loc[['Ferrocarril General San MartÃn Ramal SMB - Junin']]
distances_SMB
portName | Bahia Blanca | Buenos Aires | Campana | Colon | Comodoro Rivadavia | Concepcion Del Uruguay | Concordia | Diamante | La Plata | Mar Del Plata | ... | Rosario | San Blas | San Lorenzo | San Nicolas | San Pedro | San Sebastian Bay | Santa Fe | Ushuaia | Villa Constitucion | Zarate |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
fna | |||||||||||||||||||||
Ferrocarril General San MartÃn Ramal SMB - Junin | 626.226163 | 123.444233 | 89.868672 | 355.786962 | 1835.144247 | 319.618524 | 457.390154 | 343.236547 | 178.174291 | 510.321345 | ... | 229.806494 | 867.46151 | 258.218794 | 171.452081 | 137.373325 | 3039.285717 | 397.660848 | 3330.863637 | 186.028537 | 92.709593 |
1 rows × 36 columns
masLejano = distances_SMB.idxmax()
masLejano
0 | |
---|---|
portName | |
Bahia Blanca | Ferrocarril General San MartÃn Ramal SMB - Junin |
Buenos Aires | Ferrocarril General San MartÃn Ramal SMB - Junin |
Campana | Ferrocarril General San MartÃn Ramal SMB - Junin |
Colon | Ferrocarril General San MartÃn Ramal SMB - Junin |
Comodoro Rivadavia | Ferrocarril General San MartÃn Ramal SMB - Junin |
Concepcion Del Uruguay | Ferrocarril General San MartÃn Ramal SMB - Junin |
Concordia | Ferrocarril General San MartÃn Ramal SMB - Junin |
Diamante | Ferrocarril General San MartÃn Ramal SMB - Junin |
La Plata | Ferrocarril General San MartÃn Ramal SMB - Junin |
Mar Del Plata | Ferrocarril General San MartÃn Ramal SMB - Junin |
Parana | Ferrocarril General San MartÃn Ramal SMB - Junin |
Puerto Belgrano | Ferrocarril General San MartÃn Ramal SMB - Junin |
Puerto Deseado | Ferrocarril General San MartÃn Ramal SMB - Junin |
Puerto Gallegos | Ferrocarril General San MartÃn Ramal SMB - Junin |
Puerto Galvan | Ferrocarril General San MartÃn Ramal SMB - Junin |
Puerto Ibicuy | Ferrocarril General San MartÃn Ramal SMB - Junin |
Puerto Ingeniero White | Ferrocarril General San MartÃn Ramal SMB - Junin |
Puerto Madryn | Ferrocarril General San MartÃn Ramal SMB - Junin |
Puerto Nacional | Ferrocarril General San MartÃn Ramal SMB - Junin |
Puerto Rosales | Ferrocarril General San MartÃn Ramal SMB - Junin |
Puerto San Julian | Ferrocarril General San MartÃn Ramal SMB - Junin |
Puerto San Martin | Ferrocarril General San MartÃn Ramal SMB - Junin |
Puerto Santa Cruz | Ferrocarril General San MartÃn Ramal SMB - Junin |
Quequen | Ferrocarril General San MartÃn Ramal SMB - Junin |
Ramallo | Ferrocarril General San MartÃn Ramal SMB - Junin |
Rio Grande | Ferrocarril General San MartÃn Ramal SMB - Junin |
Rosario | Ferrocarril General San MartÃn Ramal SMB - Junin |
San Blas | Ferrocarril General San MartÃn Ramal SMB - Junin |
San Lorenzo | Ferrocarril General San MartÃn Ramal SMB - Junin |
San Nicolas | Ferrocarril General San MartÃn Ramal SMB - Junin |
San Pedro | Ferrocarril General San MartÃn Ramal SMB - Junin |
San Sebastian Bay | Ferrocarril General San MartÃn Ramal SMB - Junin |
Santa Fe | Ferrocarril General San MartÃn Ramal SMB - Junin |
Ushuaia | Ferrocarril General San MartÃn Ramal SMB - Junin |
Villa Constitucion | Ferrocarril General San MartÃn Ramal SMB - Junin |
Zarate | Ferrocarril General San MartÃn Ramal SMB - Junin |
mascercano = distances_SMB.idxmin()
mascercano
0 | |
---|---|
portName | |
Bahia Blanca | Ferrocarril General San MartÃn Ramal SMB - Junin |
Buenos Aires | Ferrocarril General San MartÃn Ramal SMB - Junin |
Campana | Ferrocarril General San MartÃn Ramal SMB - Junin |
Colon | Ferrocarril General San MartÃn Ramal SMB - Junin |
Comodoro Rivadavia | Ferrocarril General San MartÃn Ramal SMB - Junin |
Concepcion Del Uruguay | Ferrocarril General San MartÃn Ramal SMB - Junin |
Concordia | Ferrocarril General San MartÃn Ramal SMB - Junin |
Diamante | Ferrocarril General San MartÃn Ramal SMB - Junin |
La Plata | Ferrocarril General San MartÃn Ramal SMB - Junin |
Mar Del Plata | Ferrocarril General San MartÃn Ramal SMB - Junin |
Parana | Ferrocarril General San MartÃn Ramal SMB - Junin |
Puerto Belgrano | Ferrocarril General San MartÃn Ramal SMB - Junin |
Puerto Deseado | Ferrocarril General San MartÃn Ramal SMB - Junin |
Puerto Gallegos | Ferrocarril General San MartÃn Ramal SMB - Junin |
Puerto Galvan | Ferrocarril General San MartÃn Ramal SMB - Junin |
Puerto Ibicuy | Ferrocarril General San MartÃn Ramal SMB - Junin |
Puerto Ingeniero White | Ferrocarril General San MartÃn Ramal SMB - Junin |
Puerto Madryn | Ferrocarril General San MartÃn Ramal SMB - Junin |
Puerto Nacional | Ferrocarril General San MartÃn Ramal SMB - Junin |
Puerto Rosales | Ferrocarril General San MartÃn Ramal SMB - Junin |
Puerto San Julian | Ferrocarril General San MartÃn Ramal SMB - Junin |
Puerto San Martin | Ferrocarril General San MartÃn Ramal SMB - Junin |
Puerto Santa Cruz | Ferrocarril General San MartÃn Ramal SMB - Junin |
Quequen | Ferrocarril General San MartÃn Ramal SMB - Junin |
Ramallo | Ferrocarril General San MartÃn Ramal SMB - Junin |
Rio Grande | Ferrocarril General San MartÃn Ramal SMB - Junin |
Rosario | Ferrocarril General San MartÃn Ramal SMB - Junin |
San Blas | Ferrocarril General San MartÃn Ramal SMB - Junin |
San Lorenzo | Ferrocarril General San MartÃn Ramal SMB - Junin |
San Nicolas | Ferrocarril General San MartÃn Ramal SMB - Junin |
San Pedro | Ferrocarril General San MartÃn Ramal SMB - Junin |
San Sebastian Bay | Ferrocarril General San MartÃn Ramal SMB - Junin |
Santa Fe | Ferrocarril General San MartÃn Ramal SMB - Junin |
Ushuaia | Ferrocarril General San MartÃn Ramal SMB - Junin |
Villa Constitucion | Ferrocarril General San MartÃn Ramal SMB - Junin |
Zarate | Ferrocarril General San MartÃn Ramal SMB - Junin |
Let's try a simple plot of the river and the airports:
%pip install folium matplotlib mapclassify
Requirement already satisfied: folium in /usr/local/lib/python3.11/dist-packages (0.19.7) Requirement already satisfied: matplotlib in /usr/local/lib/python3.11/dist-packages (3.10.0) Requirement already satisfied: mapclassify in /usr/local/lib/python3.11/dist-packages (2.9.0) Requirement already satisfied: branca>=0.6.0 in /usr/local/lib/python3.11/dist-packages (from folium) (0.8.1) Requirement already satisfied: jinja2>=2.9 in /usr/local/lib/python3.11/dist-packages (from folium) (3.1.6) Requirement already satisfied: numpy in /usr/local/lib/python3.11/dist-packages (from folium) (2.0.2) Requirement already satisfied: requests in /usr/local/lib/python3.11/dist-packages (from folium) (2.32.3) Requirement already satisfied: xyzservices in /usr/local/lib/python3.11/dist-packages (from folium) (2025.4.0) Requirement already satisfied: contourpy>=1.0.1 in /usr/local/lib/python3.11/dist-packages (from matplotlib) (1.3.2) Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.11/dist-packages (from matplotlib) (0.12.1) Requirement already satisfied: fonttools>=4.22.0 in /usr/local/lib/python3.11/dist-packages (from matplotlib) (4.58.4) Requirement already satisfied: kiwisolver>=1.3.1 in /usr/local/lib/python3.11/dist-packages (from matplotlib) (1.4.8) Requirement already satisfied: packaging>=20.0 in /usr/local/lib/python3.11/dist-packages (from matplotlib) (24.2) Requirement already satisfied: pillow>=8 in /usr/local/lib/python3.11/dist-packages (from matplotlib) (11.2.1) Requirement already satisfied: pyparsing>=2.3.1 in /usr/local/lib/python3.11/dist-packages (from matplotlib) (3.2.3) Requirement already satisfied: python-dateutil>=2.7 in /usr/local/lib/python3.11/dist-packages (from matplotlib) (2.9.0.post0) Requirement already satisfied: networkx>=3.2 in /usr/local/lib/python3.11/dist-packages (from mapclassify) (3.5) Requirement already satisfied: pandas>=2.1 in /usr/local/lib/python3.11/dist-packages (from mapclassify) (2.2.2) Requirement already satisfied: scikit-learn>=1.4 in /usr/local/lib/python3.11/dist-packages (from mapclassify) (1.6.1) Requirement already satisfied: scipy>=1.12 in /usr/local/lib/python3.11/dist-packages (from mapclassify) (1.15.3) Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.11/dist-packages (from jinja2>=2.9->folium) (3.0.2) Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.11/dist-packages (from pandas>=2.1->mapclassify) (2025.2) Requirement already satisfied: tzdata>=2022.7 in /usr/local/lib/python3.11/dist-packages (from pandas>=2.1->mapclassify) (2025.2) Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.11/dist-packages (from python-dateutil>=2.7->matplotlib) (1.17.0) Requirement already satisfied: joblib>=1.2.0 in /usr/local/lib/python3.11/dist-packages (from scikit-learn>=1.4->mapclassify) (1.5.1) Requirement already satisfied: threadpoolctl>=3.1.0 in /usr/local/lib/python3.11/dist-packages (from scikit-learn>=1.4->mapclassify) (3.6.0) Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.11/dist-packages (from requests->folium) (3.4.2) Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.11/dist-packages (from requests->folium) (3.10) Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.11/dist-packages (from requests->folium) (2.4.0) Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.11/dist-packages (from requests->folium) (2025.6.15)
mascercano_port = main_port_arg[main_port_arg['portName'] == mascercano.iloc[0]]
masLejano_port = main_port_arg[main_port_arg['portName'] == masLejano.iloc[0]]
# Get the specific railway line
trenesDeCargaUso = trenesDeCarga[trenesDeCarga['fna'] == 'Ferrocarril General San MartÃn Ramal SMB - Junin']
# Plot the railway line, nearest port, and farthest port
base = trenesDeCargaUso.explore(color='blue')
mascercano_port.explore(m=base, color='green', marker_kwds=dict(radius=10))
masLejano_port.explore(m=base, color='red', marker_kwds=dict(radius=10))
/tmp/ipython-input-78-151150028.py:7: UserWarning: The GeoSeries you are attempting to plot is composed of empty geometries. Nothing has been displayed. mascercano_port.explore(m=base, color='green', marker_kwds=dict(radius=10)) /tmp/ipython-input-78-151150028.py:8: UserWarning: The GeoSeries you are attempting to plot is composed of empty geometries. Nothing has been displayed. masLejano_port.explore(m=base, color='red', marker_kwds=dict(radius=10))
Exercise 3¶
Create a HULL for some set of line map.
Compute the distance matrix between the HULLS and a map of points.
Plot the HULLS and the points. Show the closest and farthest points to the HULL.
## MI DISTANCIA LINEA-PUNTO ES FERROVIAS-PUERTOS
trenesDeCarga.convex_hull
0 | |
---|---|
0 | POLYGON ((3166810.984 5907281.017, 3166612.289... |
1 | POLYGON ((3029107.645 6150749.166, 3025589.95 ... |
2 | POLYGON ((2963794.384 6855066.915, 3025783.891... |
3 | POLYGON ((3003050.282 5919220.443, 3003214.641... |
4 | POLYGON ((3110892.729 6760284.512, 3111042.621... |
5 | POLYGON ((2953064.51 6783525.133, 2960845.402 ... |
trenesDeCarga.convex_hull.plot()
<Axes: >
trenesDeCarga_hulls=trenesDeCarga.convex_hull.to_frame()
trenesDeCarga_hulls['fna']='Ferrocarril General San MartÃn Ramal SMB - Junin'
trenesDeCarga_hulls.rename(columns={0:'geometry'},inplace=True)
trenesDeCarga_hulls=trenesDeCarga_hulls.set_geometry('geometry')
trenesDeCarga_hulls.crs="EPSG:5343"
trenesDeCarga_hulls
geometry | fna | |
---|---|---|
0 | POLYGON ((3166810.984 5907281.017, 3166612.289... | Ferrocarril General San MartÃn Ramal SMB - Junin |
1 | POLYGON ((3029107.645 6150749.166, 3025589.95 ... | Ferrocarril General San MartÃn Ramal SMB - Junin |
2 | POLYGON ((2963794.384 6855066.915, 3025783.891... | Ferrocarril General San MartÃn Ramal SMB - Junin |
3 | POLYGON ((3003050.282 5919220.443, 3003214.641... | Ferrocarril General San MartÃn Ramal SMB - Junin |
4 | POLYGON ((3110892.729 6760284.512, 3111042.621... | Ferrocarril General San MartÃn Ramal SMB - Junin |
5 | POLYGON ((2953064.51 6783525.133, 2960845.402 ... | Ferrocarril General San MartÃn Ramal SMB - Junin |
trenesDeCarga_hulls=trenesDeCarga_hulls.drop([0,1,2,3], axis=0)
trenesDeCarga_hulls
geometry | fna | |
---|---|---|
4 | POLYGON ((3110892.729 6760284.512, 3111042.621... | Ferrocarril General San MartÃn Ramal SMB - Junin |
5 | POLYGON ((2953064.51 6783525.133, 2960845.402 ... | Ferrocarril General San MartÃn Ramal SMB - Junin |
trenesDeCarga_hulls.plot()
<Axes: >
distanceMatrixKM_trenesCarga=trenesDeCarga_hulls.set_index('fna').geometry.apply\
(lambda g: powerplant.set_index('fna').geometry.distance(g)/1000).\
sort_index(axis=0).sort_index(axis=1)
distanceMatrixKM_trenesCarga
fna | Central Hidroelectrica Albardón | Central Hidroeléctrica Los Caracoles | Central Térmica El Portón | Central Térmica Piedras Negras | Estación Hidrológica Piedras Pintadas | Usina Hidroeléctrica Don Claudio Tinto | Usina Vitry |
---|---|---|---|---|---|---|---|
fna | |||||||
Ferrocarril General San MartÃn Ramal SMB - Junin | 1305.442566 | 1346.362731 | 1653.180621 | 1587.826452 | 1337.542551 | 1397.344314 | 1311.828349 |
Ferrocarril General San MartÃn Ramal SMB - Junin | 1155.952616 | 1196.758041 | 1535.056370 | 1477.662466 | 1181.308155 | 1246.565887 | 1162.512607 |
mins=distanceMatrixKM_trenesCarga.idxmin(axis="columns")
mins
0 | |
---|---|
fna | |
Ferrocarril General San MartÃn Ramal SMB - Junin | Central Hidroelectrica Albardón |
Ferrocarril General San MartÃn Ramal SMB - Junin | Central Hidroelectrica Albardón |
base=trenesDeCarga_hulls.explore()
powerplant[powerplant.fna.isin(mins)].explore(m=base,color='red',marker_kwds=dict(radius=10))
powerplant[~powerplant.fna.isin(mins)].explore(m=base,color='blue',marker_kwds=dict(radius=5))
Exercise 4¶
Select a line map and a point one.
Get the buffer for the lines, select a distance.
Keep the points that are within the buffer (you might need to play with differn distances until you show something interesting.
distanceMatrixKM_2
portName | Bahia Blanca | Buenos Aires | Campana | Colon | Comodoro Rivadavia | Concepcion Del Uruguay | Concordia | Diamante | La Plata | Mar Del Plata | ... | Rosario | San Blas | San Lorenzo | San Nicolas | San Pedro | San Sebastian Bay | Santa Fe | Ushuaia | Villa Constitucion | Zarate |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
fna | |||||||||||||||||||||
Ferrocarril General San MartÃn Ramal SMB - Junin | 626.226163 | 123.444233 | 89.868672 | 355.786962 | 1835.144247 | 319.618524 | 457.390154 | 343.236547 | 178.174291 | 510.321345 | ... | 229.806494 | 867.461510 | 258.218794 | 171.452081 | 137.373325 | 3039.285717 | 397.660848 | 3330.863637 | 186.028537 | 92.709593 |
Ferrocarril Nacional General Belgrano Ramal C3 | 1519.948463 | 993.230388 | 915.276687 | 714.805953 | 2669.513570 | 740.209654 | 630.811905 | 606.541616 | 1041.388462 | 1471.146803 | ... | 722.007947 | 1775.950161 | 694.691028 | 777.999724 | 818.893203 | 3913.302842 | 551.954230 | 4214.590763 | 763.261261 | 904.631951 |
Ferrocarril Nacional General Belgrano Ramal C6 | 1447.838923 | 929.805856 | 850.276781 | 659.377658 | 2597.628606 | 683.009686 | 580.704146 | 537.142508 | 979.376312 | 1405.966172 | ... | 652.204019 | 1703.917044 | 624.662478 | 709.267116 | 751.404906 | 3841.081440 | 482.633119 | 4142.298938 | 694.262586 | 839.473013 |
Ferrocarril Nacional General Belgrano Ramal F - Los Amores | 1443.955561 | 862.105095 | 790.906985 | 565.657215 | 2620.994075 | 594.624812 | 473.117510 | 512.837071 | 905.223454 | 1343.211612 | ... | 627.593637 | 1696.760986 | 602.863091 | 674.655679 | 707.485119 | 3854.088971 | 460.103162 | 4151.774350 | 661.988224 | 781.046624 |
Ferrocarril Nacional General Belgrano Ramal F1 | 829.979647 | 350.552824 | 260.546501 | 297.869931 | 2020.403895 | 279.494453 | 349.058018 | 89.281776 | 411.773449 | 789.611527 | ... | 16.589651 | 1081.870112 | 0.754682 | 83.920102 | 139.816739 | 3243.929202 | 143.034148 | 3539.791691 | 66.622348 | 249.081705 |
Ferrocarril Nacional General San MartÃn Ramal SMC - Junin | 598.521578 | 284.798422 | 225.434623 | 441.135373 | 1796.846885 | 408.833877 | 528.759739 | 334.146550 | 340.308636 | 606.895340 | ... | 219.189627 | 849.175534 | 244.058054 | 183.087935 | 181.383015 | 3014.070820 | 387.860092 | 3308.860630 | 191.059641 | 220.778437 |
6 rows × 36 columns
distanceMatrixKM_2.loc['Ferrocarril Nacional General Belgrano Ramal F - Los Amores'].min()
460.1031620099511
minMts=distanceMatrixKM_2.loc['Ferrocarril Nacional General Belgrano Ramal F - Los Amores'].min()*100
trenesDeCarga[trenesDeCarga.fna=='Ferrocarril Nacional General Belgrano Ramal F - Los Amores'].buffer(distance=minMts)
0 | |
---|---|
4 | POLYGON ((3073876.814 6809846.487, 3074504.225... |
bufferAroundLosAmores=trenesDeCarga[trenesDeCarga.fna=='Ferrocarril Nacional General Belgrano Ramal F - Los Amores'].buffer(distance=minMts)
bufferAsBase=bufferAroundLosAmores.explore(color='red')
trenesDeCarga[trenesDeCarga.fna=='Ferrocarril Nacional General Belgrano Ramal F - Los Amores'].explore(m=bufferAsBase,color='blue', style_kwds={'weight':0.5})
trenesDeCarga[trenesDeCarga.fna=='Ferrocarril Nacional General Belgrano Ramal F - Los Amores'].explore(m=bufferAsBase,color='blue',style_kwds={'weight':0.5})
centrales_electricas.explore(m=bufferAsBase,color='black')
centralesWithinBuffer=centrales_electricas.clip(mask=bufferAroundLosAmores)
centralesWithinBuffer
/usr/local/lib/python3.11/dist-packages/geopandas/geodataframe.py:2585: UserWarning: CRS mismatch between the CRS of left geometries and the CRS of right geometries. Use `to_crs()` to reproject one of the input geometries to match the CRS of the other. Left CRS: EPSG:5343 Right CRS: EPSG:5641 return geopandas.clip(self, mask=mask, keep_geom_type=keep_geom_type, sort=sort)
gid | entidad | objeto | fna | gna | nam | fun | ppc | sag | fdc | geometry | |
---|---|---|---|---|---|---|---|---|---|---|---|
176 | 326 | 0.0 | Central Eléctrica | Central Térmica Oberá | Central Térmica | Oberá | 6.0 | 7.0 | IGN | IGN/SecretarÃa de Gobierno de EnergÃa | POINT (3181452.055 6842283.504) |
175 | 325 | 0.0 | Central Eléctrica | Central Térmica Aristóbulo del Valle | Central Térmica | Aristóbulo del Valle | 6.0 | 7.0 | IGN | IGN/SecretarÃa de Gobierno de EnergÃa | POINT (3214548.023 6884991.742) |
bufferAsBase=bufferAroundLosAmores.explore(color='red')
trenesDeCarga[trenesDeCarga.fna=='Ferrocarril Nacional General Belgrano Ramal F - Los Amores'].explore(m=bufferAsBase,color='blue',style_kwds={'weight':0.5})
centralesWithinBuffer.explore(m=bufferAsBase,color='black')
distanceMatrixKM_2.min(axis=1).min()
0.7546821248580667
minMinMts_5=5*distanceMatrixKM_2.min(axis=1).min()*1000
allMinBuffer=ferrovias.buffer(distance=minMinMts_5).explore(color='red')
ferrovias.explore(m=allMinBuffer,color='blue',style_kwds={'weight':0.5})