-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Fix GeoPandas dataset compatibility for naturalearth_cities #5420
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,7 +56,22 @@ fig.show() | |
| import plotly.express as px | ||
| import geopandas as gpd | ||
|
|
||
| geo_df = gpd.read_file(gpd.datasets.get_path('naturalearth_cities')) | ||
| # Handle both old and new GeoPandas versions without requiring network access | ||
| try: | ||
| # Try the old method (GeoPandas < 1.0) | ||
| geo_df = gpd.read_file(gpd.datasets.get_path('naturalearth_cities')) | ||
| except (AttributeError, ValueError): | ||
| # Use the new method (GeoPandas >= 1.0) | ||
| try: | ||
| import geodatasets | ||
| geo_df = gpd.read_file(geodatasets.get_path('naturalearth.cities')) | ||
| except ImportError: | ||
| # Fallback: build a tiny in-memory GeoDataFrame (no internet or extra deps) | ||
| from shapely.geometry import Point | ||
| geo_df = gpd.GeoDataFrame( | ||
| {"name": ["City A", "City B"], "geometry": [Point(0, 0), Point(10, 10)]}, | ||
| crs="EPSG:4326", | ||
| ) | ||
|
Comment on lines
+60
to
+74
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As So something like import plotly.express as px
import geopandas as gpd
from shapely.geometry import Point
geo_df = gpd.GeoDataFrame({
'name': ['London', 'Paris', 'Berlin', 'Madrid', 'Rome'],
'geometry': [
Point(-0.13, 51.51),
Point(2.35, 48.86),
Point(13.41, 52.52),
Point(-3.70, 40.42),
Point(12.50, 41.90),
]
}, crs="EPSG:4326")
fig = px.scatter_map(geo_df,
lat=geo_df.geometry.y,
lon=geo_df.geometry.x,
hover_name="name",
zoom=3)
fig.show()And something similar for the scatter-plots-on-maps example |
||
|
|
||
| fig = px.scatter_map(geo_df, | ||
| lat=geo_df.geometry.y, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This dataset doesn't currently exist on geodatasets, so this will never be successful even with geopandas >=1.0