diff --git a/examples/Overview.ipynb b/examples/Overview.ipynb index 9f22362..be55687 100644 --- a/examples/Overview.ipynb +++ b/examples/Overview.ipynb @@ -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", @@ -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()" diff --git a/examples/download.py b/examples/download.py new file mode 100644 index 0000000..4715cdc --- /dev/null +++ b/examples/download.py @@ -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 diff --git a/pixi.toml b/pixi.toml index 5932f4e..371a4e4 100644 --- a/pixi.toml +++ b/pixi.toml @@ -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 =================== diff --git a/spatialpandas/tests/tools/test_sjoin.py b/spatialpandas/tests/tools/test_sjoin.py index f83dac1..8d546ce 100644 --- a/spatialpandas/tests/tools/test_sjoin.py +++ b/spatialpandas/tests/tools/test_sjoin.py @@ -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)