Skip to content
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

Add to_geopandas() method #38

Merged
merged 13 commits into from
Feb 5, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ci/environment-dev-3.6.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@ dependencies:
- xarray
- rasterio
- ipywidgets
- geopandas
- pip:
- sphinx_copybutton
1 change: 1 addition & 0 deletions ci/environment-dev-3.7-upstream.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ dependencies:
- xarray
- rasterio
- ipywidgets
- geopandas
- pip:
- sphinx_copybutton
- git+https://github.com/sat-utils/sat-stac.git
Expand Down
1 change: 1 addition & 0 deletions ci/environment-dev-3.7.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@ dependencies:
- xarray
- rasterio
- ipywidgets
- geopandas
- pip:
- sphinx_copybutton
20 changes: 20 additions & 0 deletions intake_stac/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import yaml
from intake.catalog import Catalog
from intake.catalog.local import LocalCatalogEntry
import tempfile

from . import __version__

Expand Down Expand Up @@ -152,6 +153,25 @@ def _load(self):
def _get_metadata(self, **kwargs):
return kwargs

def to_geopandas(self):
jhamman marked this conversation as resolved.
Show resolved Hide resolved
"""
Load the STAC Item Collection into a geopandas GeoDataFrame
"""
try:
import geopandas as gpd
except ImportError:
raise ImportError(
"Using to_geopandas requires the `geopandas` package"
)
andersy005 marked this conversation as resolved.
Show resolved Hide resolved

with tempfile.NamedTemporaryFile(suffix=".geojson") as f:
self._stac_obj.save(f.name)
gf = gpd.read_file(f.name)
jhamman marked this conversation as resolved.
Show resolved Hide resolved
return gf

def from_geopandas(self):
...


class StacCollection(AbstractStacCatalog):
"""
Expand Down
8 changes: 8 additions & 0 deletions intake_stac/tests/test_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,14 @@ def test_stac_entry_constructor():
assert d["metadata"] == item


def test_cat_to_geopandas(stac_item_collection_obj):
import geopandas as gpd

cat = StacItemCollection(stac_item_collection_obj)
df = cat.to_geopandas()
assert isinstance(df, gpd.GeoDataFrame)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we also assert that the new df has a few features that we expect (e.g. number or rows, index values, etc.)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. I added a few more tests to address this



# TODO - Add tests for:
# StacEntry._get_driver()
# StacEntryy._get_args()
Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pytest>=4.5.0
pytest-cov>=2.7.1
geopandas