Skip to content

Commit

Permalink
fix set_geometry bug with geopandas
Browse files Browse the repository at this point in the history
  • Loading branch information
xoolive committed Apr 15, 2024
1 parent 07a24d3 commit 48d7f89
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/traffic/core/airspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,18 @@ def dissolve(self, keep_levels: bool = False) -> gpd.GeoDataFrame:
columns += ["upper", "lower"]
name_table = self.data[["designator", "name"]].drop_duplicates()

return gpd.GeoDataFrame(
self.data.groupby(columns)
.agg(dict(geometry=unary_union))
.reset_index()
.merge(name_table)
).assign( # centroid is only accessible on a GeoDataFrame...
longitude=lambda df: df.centroid.x,
latitude=lambda df: df.centroid.y,
return (
gpd.GeoDataFrame(
self.data.groupby(columns)
.agg(dict(geometry=unary_union))
.reset_index()
.merge(name_table)
)
.assign( # centroid is only accessible on a GeoDataFrame...
longitude=lambda df: df.centroid.x,
latitude=lambda df: df.centroid.y,
)
.set_geometry("geometry")
)


Expand Down
1 change: 1 addition & 0 deletions src/traffic/data/eurocontrol/ddr/airspaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def init_cache(self) -> None:
)
.query("designator != component or geometry.notnull()")
.assign(upper=lambda df: df.upper.replace(999, float("inf")))
.set_geometry("geometry")
)

def read_are(self, filename: Path) -> None:
Expand Down
1 change: 1 addition & 0 deletions src/traffic/data/eurocontrol/ddr/freeroute.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def init_cache(self) -> None:
self.read_sls(sls_file)

data = gpd.GeoDataFrame.from_records(self.elements_list)
data = data.set_geometry("geometry")
if "name" not in data.columns:
data = data.assign(name="")
self.fra = self.data = data.assign(type="FRA")
Expand Down
1 change: 1 addition & 0 deletions src/traffic/data/eurocontrol/eurofirs.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def __init__(self, data: gpd.GeoDataFrame | None = None) -> None:
),
)
.drop(columns=["UPPERUNIT", "LOWERUNIT", "EFFECTDATE", "ICAO"])
.set_geometry("geometry")
)


Expand Down
1 change: 1 addition & 0 deletions src/traffic/data/faa/_airspace_boundary.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def __init__(self, data: gpd.GeoDataFrame | None = None) -> None:
lower=lambda df: df.lower.replace(-9998, 0),
upper=lambda df: df.upper.replace(-9998, float("inf")),
)
.set_geometry("geometry")
)

def back(self) -> Dict[str, Airspace]:
Expand Down

0 comments on commit 48d7f89

Please sign in to comment.