Aquí hay un código de trabajo completo para su problema. En primer lugar, he cargado geojson a geodataframe. A continuación, se itera a través de cada característica y comprobar si lom_name coincide con el uno para el que las líneas se están fusionando.
Luego creé Shapely MultiLineString a partir de un array de LineStrings.
Espero que esto sea lo que buscaba.
import json
import geopandas as gpd
from shapely import geometry
def merge_gdf(name):
l_seg = json.loads("""
{
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"properties": {
"checkpoint": 6,
"lom_name": "marathon19"
},
"geometry": {
"type": "LineString",
"coordinates": [
[1, 4],
[2, 5]
]
}
}, {
"type": "Feature",
"properties": {
"checkpoint": 0,
"lom_name": "marathon19"
},
"geometry": {
"type": "LineString",
"coordinates": [
[3, 6],
[4, 7]
]
}
}, {
"type": "Feature",
"properties": {
"checkpoint": 0,
"lom_name": "marathon20"
},
"geometry": {
"type": "LineString",
"coordinates": [
[6, 8],
[10, 12]
]
}
}]
}
""")
line_segments = []
gdf = gpd.GeoDataFrame.from_features(l_seg["features"])
print(gdf.head())
for idx, row in gdf.iterrows():
if row['lom_name'] == name:
line_segments.append(row['geometry'])
multiline = geometry.MultiLineString(line_segments)
print(multiline)
gs = gpd.GeoSeries(multiline)
print(gs.to_json())
if __name__ == '__main__':
merge_gdf('marathon19')