pystac icon indicating copy to clipboard operation
pystac copied to clipboard

Implement `__geo_interface__`

Open TomAugspurger opened this issue 2 years ago • 5 comments

__geo_interface__ is a way for Python objects to return geojson (-like) representations of themselves. Should pystac objects implement this?

This might be helpful for cases like https://github.com/stac-utils/pystac-client/issues/146, where libraries want to support a range of geojson-like objects without having to know how to convert each particular object to geojson.

TomAugspurger avatar Apr 06 '22 01:04 TomAugspurger

Should pystac objects implement this?

Probably just Item since its the only STACObject that has a defined geometry?

gadomski avatar Apr 06 '22 14:04 gadomski

Collection could also conceivably implement this by creating a Polygon or MultiPolygon from Collection.extent.spatial (depending on how many bboxes are present). In the case of a single bbox we could construct a single polygon. For multiple bboxes we could ignore the first bbox and construct a MultiPolygon from the remaining boxes. I could see that being a useful way of filtering collections to see which ones overlap another geometry.

duckontheweb avatar Apr 06 '22 14:04 duckontheweb

Item is definitely the clearest, and John's suggestion for Collections make sense.

ItemCollection is a bit murky. There's a comment on that gist about letting __geo_interface__ include FeatureCollection, but it didn't seem to go anywhere.

TomAugspurger avatar Apr 06 '22 15:04 TomAugspurger

ItemCollection is a bit murky. There's a comment on that gist about letting __geo_interface__ include FeatureCollection, but it didn't seem to go anywhere.

Yeah, the ItemCollection implementation seems murky to me. It seems like it would be most appropriate to represent it as a GeometryCollection since it could conceivably contain geometries of different types. shapely seems to support most geometric operations (but not affine transformations) on GeometryCollections, but it doesn't seem to have the same support for FeatureCollections (shapely/shapely#770).

Maybe we should also support this for SpatialExtent. We could follow the same process I suggested above for Collections and then just surface that in Collection.__geo_interface__, too.

duckontheweb avatar May 13 '22 21:05 duckontheweb

Strongly in favor of implementing this for Item, since a STAC Item is a GeoJSON Feature with foreign members.

I'm not clear on what the value is for Collection or ItemCollection, so I think it would be better not to do that until we can really determine how it would be used.

philvarner avatar May 27 '22 16:05 philvarner