Skip to content

add eo STAC extension support #38

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

Merged
merged 5 commits into from
Sep 2, 2022
Merged

add eo STAC extension support #38

merged 5 commits into from
Sep 2, 2022

Conversation

vincentsarago
Copy link
Member

@vincentsarago vincentsarago commented Sep 2, 2022

closes #36

//rio stac tests/fixtures/dataset_cog.tif | jq
{
  "type": "Feature",
  "stac_version": "1.0.0",
  "id": "dataset_cog.tif",
  "properties": {
    "proj:epsg": 32621,
    "proj:geometry": {
      "type": "Polygon",
      "coordinates": [
        [
          [
            373185,
            8019284.949381611
          ],
          [
            639014.9492102272,
            8019284.949381611
          ],
          [
            639014.9492102272,
            8286015
          ],
          [
            373185,
            8286015
          ],
          [
            373185,
            8019284.949381611
          ]
        ]
      ]
    },
    "proj:bbox": [
      373185,
      8019284.949381611,
      639014.9492102272,
      8286015
    ],
    "proj:shape": [
      2667,
      2658
    ],
    "proj:transform": [
      100.01126757344893,
      0,
      373185,
      0,
      -100.01126757344893,
      8286015,
      0,
      0,
      1
    ],
    "datetime": "2022-09-02T16:23:11.514913Z"
  },
  "geometry": {
    "type": "Polygon",
    "coordinates": [
      [
        [
          -60.72634617297825,
          72.23689137791739
        ],
        [
          -52.91627525610924,
          72.22979795551834
        ],
        [
          -52.301598718454485,
          74.61378388950398
        ],
        [
          -61.28762442711404,
          74.62204314252978
        ],
        [
          -60.72634617297825,
          72.23689137791739
        ]
      ]
    ]
  },
  "links": [],
  "assets": {
    "asset": {
      "href": "/Users/vincentsarago/Dev/DevSeed/rio-stac/tests/fixtures/dataset_cog.tif",
      "raster:bands": [
        {
          "data_type": "uint16",
          "scale": 1,
          "offset": 0,
          "sampling": "point",
          "statistics": {
            "mean": 2107.524612053134,
            "minimum": 1,
            "maximum": 7872,
            "stddev": 2271.0065537857326,
            "valid_percent": 9.564764936336924e-05
          },
          "histogram": {
            "count": 11,
            "min": 1,
            "max": 7872,
            "buckets": [
              503460,
              0,
              0,
              161792,
              283094,
              0,
              0,
              0,
              87727,
              9431
            ]
          }
        }
      ],
      "eo:bands": [
        {
          "name": "b1",
          "description": "gray"
        }
      ],
      "roles": []
    }
  },
  "bbox": [
    -61.28762442711404,
    72.22979795551834,
    -52.301598718454485,
    74.62204314252978
  ],
  "stac_extensions": [
    "https://stac-extensions.github.io/projection/v1.0.0/schema.json",
    "https://stac-extensions.github.io/raster/v1.1.0/schema.json",
    "https://stac-extensions.github.io/eo/v1.0.0/schema.json"
  ]
}

Possible discussion includes:

  • is setting eo:bands name to b{index} something good?
  • is using colorinterp value for description (even when undefined) user friendly?

rio_stac/stac.py Outdated
@@ -271,28 +302,51 @@ def create_stac_item(
get_media_type(dataset) if asset_media_type == "auto" else asset_media_type
)

# Try to get datetime from https://gdal.org/user/raster_data_model.html#imagery-domain-remote-sensing
dst_date = src_dst.get_tag_item("ACQUISITIONDATETIME", "IMAGERY")
Copy link
Member Author

Choose a reason for hiding this comment

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

get Datetime from Raster Data model metadata


if "start_datetime" not in properties and "end_datetime" not in properties:
input_datetime = (
input_datetime or dst_datetime or datetime.datetime.utcnow()
Copy link
Member Author

Choose a reason for hiding this comment

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

user input OR dataset metadata OR now

)

eo_info = {"eo:bands": get_eobands_info(src_dst)}

cloudcover = src_dst.get_tag_item("CLOUDCOVER", "IMAGERY")
Copy link
Member Author

Choose a reason for hiding this comment

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

get cloud cover from GDAL Raster Data model

# Description metadata or Colorinterp or Nothing
description = descr or color
if description:
band_meta["description"] = description
Copy link
Member Author

Choose a reason for hiding this comment

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

eo:bands description will be either:


colors = src_dst.colorinterp
for ix in src_dst.indexes:
band_meta = {"name": f"b{ix}"}
Copy link
Member Author

Choose a reason for hiding this comment

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

we set name to b{band index value} (e.g b1, b2, ....)

@gadomski
Copy link

gadomski commented Sep 2, 2022

FYSA I aped this for GDAL: OSGeo/gdal#6309

@vincentsarago vincentsarago merged commit 3f8edfc into master Sep 2, 2022
@vincentsarago vincentsarago deleted the eoExtension branch September 2, 2022 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add eo extension
2 participants