Skip to content

Commit 2e7cef7

Browse files
author
Tom Augspurger
authored
Docs for pyarrow reader / writer (#46)
* Docs for pyarrow reader / writer
1 parent 5c0a682 commit 2e7cef7

File tree

1 file changed

+16
-28
lines changed

1 file changed

+16
-28
lines changed

README.md

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,28 @@ This library helps convert [STAC Items](https://github.com/radiantearth/stac-spe
88

99
## Usage
1010

11-
`stac_geoparquet.to_dataframe` does it all. You give it a list of (STAC Item) dictionaries. It just converts them to a `geopandas.GeoDataFrame`, which can be written to parquet with `.to_parquet`.
12-
13-
```python
14-
>>> import requests
15-
>>> import stac_geoparquet
16-
>>> item = requests.get("https://planetarycomputer.microsoft.com/api/stac/v1/collections/naip/items/ia_m_4209150_sw_15_060_20190828_20191105").json()
17-
>>> df = stac_geoparquet.to_geodataframe([item])
18-
>>> df.to_parquet("naip.parquet")
19-
```
11+
Use `stac_geoparquet.to_arrow.stac_items_to_arrow` and
12+
`stac_geoparquet.from_arrow.stac_table_to_items` to convert between STAC items
13+
and Arrow tables. Arrow Tables of STAC items can be written to parquet with
14+
`stac_geoparquet.to_parquet.to_parquet`.
2015

2116
Note that `stac_geoparquet` lifts the keys in the item `properties` up to the top level of the DataFrame, similar to `geopandas.GeoDataFrame.from_features`.
2217

2318
```python
24-
>>> list(df.columns)
25-
['type',
26-
'stac_version',
27-
'stac_extensions',
28-
'id',
29-
'geometry',
30-
'bbox',
31-
'links',
32-
'assets',
33-
'collection',
34-
'gsd',
35-
'datetime',
36-
'naip:year',
37-
'proj:bbox',
38-
'proj:epsg',
39-
'naip:state',
40-
'proj:shape',
41-
'proj:transform']
19+
>>> import requests
20+
>>> import stac_geoparquet.arrow
21+
>>> import pyarrow.parquet
22+
23+
>>> items = requests.get(
24+
... "https://planetarycomputer.microsoft.com/api/stac/v1/collections/sentinel-2-l2a/items"
25+
... ).json()["features"]
26+
>>> table = stac_geoparquet.arrow.parse_stac_items_to_arrow(items)
27+
>>> stac_geoparquet.arrow.to_parquet(table, "items.parquet")
28+
>>> table2 = pyarrow.parquet.read_table("items.parquet")
29+
>>> items2 = list(stac_geoparquet.arrow.stac_table_to_items(table2))
4230
```
4331

44-
We also provide `stac_geoparquet.to_dict` and `stac_geoparquet.to_item_collection` helpers that can be used to convert from DataFrames back to the original STAC items.
32+
See the [specification](./spec/stac-geoparquet-spec.md) for details on the output stac-geoparquet dataset.
4533

4634
## pgstac integration
4735

0 commit comments

Comments
 (0)