Skip to content

Commit

Permalink
Support Geopandas 1 (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxbro authored Aug 13, 2024
1 parent 4381df5 commit dbdf154
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
5 changes: 3 additions & 2 deletions examples/Overview.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -903,9 +903,10 @@
],
"source": [
"import geopandas\n",
"from download import download_map\n",
"\n",
"world_gp = geopandas.read_file(\n",
" geopandas.datasets.get_path('naturalearth_lowres')\n",
" download_map('naturalearth_lowres')\n",
")\n",
"world_gp = world_gp.sort_values('name').reset_index(drop=True)\n",
"world_gp = world_gp[['pop_est', 'continent', 'name', 'geometry']]\n",
Expand Down Expand Up @@ -3123,7 +3124,7 @@
],
"source": [
"cities_gp = geopandas.read_file(\n",
" geopandas.datasets.get_path('naturalearth_cities')\n",
" download_map('naturalearth_cities')\n",
")\n",
"cities_df = GeoDataFrame(cities_gp)\n",
"cities_df.head()"
Expand Down
34 changes: 34 additions & 0 deletions examples/download.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
try:
import requests
from platformdirs import user_cache_path
except ImportError:
raise ImportError("requests and platformdirs are needed to download data")


def download_map(dataset):
if dataset not in ("naturalearth_lowres", "naturalearth_cities"):
raise ValueError(f"Unknown dataset: {dataset}, supported datasets are 'naturalearth_lowres' and 'naturalearth_cities'")
url = f"https://api.github.com/repos/geopandas/geopandas/contents/geopandas/datasets/{dataset}?ref=v0.14.4"
local_dir = user_cache_path() / "spatialpandas" / dataset

if local_dir.exists():
return local_dir

response = requests.get(url)
if response.status_code == 200:
files = response.json()
else:
print(f"Failed to retrieve contents: {response.status_code}")
return None

if not local_dir.exists():
local_dir.mkdir(parents=True)

for file in files:
file_url = file["download_url"]
file_name = file["name"]
file_response = requests.get(file_url)
with open(local_dir / file_name, "wb") as f:
f.write(file_response.content)

return local_dir
6 changes: 4 additions & 2 deletions pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ python = "3.12.*"
datashader = "*"
descartes = "*"
distributed = "*"
geopandas-base = "<1" # FIX: temporary upper pin
pyogrio = "*"
geopandas-base = "*"
holoviews = "*"
matplotlib-base = "*"
platformdirs = "*"
pyogrio = "*"
requests = "*"

# =============================================
# =================== TESTS ===================
Expand Down
2 changes: 2 additions & 0 deletions spatialpandas/tests/tools/test_sjoin.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ def test_sjoin(how, gp_points, gp_polygons):
gp_expected = gp_expected.rename(columns={"v_x": "v_left", "v_y": "v_right"})
if how == "right":
gp_expected.index.name = right_gpdf.index.name
gp_expected = gp_expected.rename(columns={"a_left": "index_left", "a_right": "a"}) # geopandas 1.0 compability
else:
gp_expected.index.name = left_gpdf.index.name
gp_expected = gp_expected.rename(columns={"b": "index_right", "a_right": "a"}) # geopandas 1.0 compability

# join with spatialpandas
left_spdf = GeoDataFrame(left_gpdf)
Expand Down

0 comments on commit dbdf154

Please sign in to comment.