Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • Juraj.Zvolensky/raster-to-stac
  • earth_observation_public/raster-to-stac
2 results
Show changes
Commits on Source (5)
# Raster-to-STAC # Raster-to-STAC
This package allows the creation of STAC Collection with Items and Assets starting from different kind of raster datasets. This component allows the creation of STAC Collection with Items and Assets starting from different kinds of raster datasets. It also allows the user to automatically upload the resulting files to an Amazon S3 Bucket, to make them publicly accessible and reachable worldwide. The goal is to make a dataset easily accessible, interoperable, and shareable.
Depending on the requirements, two approaches can be taken: Depending on the requirements, two approaches can be taken:
1. Via COGs 1. Via COGs
...@@ -69,4 +70,4 @@ print(ds_stac) ...@@ -69,4 +70,4 @@ print(ds_stac)
## License ## License
This project is distributed with MIT license - see 'LICENSE' for details. This project is distributed with MIT license - see 'LICENSE' for details.
\ No newline at end of file
...@@ -44,6 +44,8 @@ from urllib.parse import urlparse, urlunparse ...@@ -44,6 +44,8 @@ from urllib.parse import urlparse, urlunparse
_log = logging.getLogger(__name__) _log = logging.getLogger(__name__)
DATACUBE_EXT_VERSION = "v1.0.0"
class Raster2STAC(): class Raster2STAC():
""" """
Raster2STAC Class - Converte dati raster nel formato STAC. Raster2STAC Class - Converte dati raster nel formato STAC.
...@@ -168,22 +170,23 @@ class Raster2STAC(): ...@@ -168,22 +170,23 @@ class Raster2STAC():
f"https://stac-extensions.github.io/projection/{PROJECTION_EXT_VERSION}/schema.json", f"https://stac-extensions.github.io/projection/{PROJECTION_EXT_VERSION}/schema.json",
f"https://stac-extensions.github.io/raster/{RASTER_EXT_VERSION}/schema.json", f"https://stac-extensions.github.io/raster/{RASTER_EXT_VERSION}/schema.json",
f"https://stac-extensions.github.io/eo/{EO_EXT_VERSION}/schema.json", f"https://stac-extensions.github.io/eo/{EO_EXT_VERSION}/schema.json",
# f"https://stac-extensions.github.io/datacube/{DATACUBE_EXT_VERSION}/schema.json",
] ]
self.set_media_type(pystac.MediaType.COG) # we could also use rio_stac.stac.get_media_type) self.set_media_type(pystac.MediaType.COG) # we could also use rio_stac.stac.get_media_type)
if output_folder is not None: if output_folder is not None:
self.output_folder = output_folder self.output_folder = output_folder
else: else:
self.output_folder = datetime.datetime.utcnow().strftime('%Y%m%d%H%M%S%f')[:-3] self.output_folder = datetime.datetime.utcnow().strftime('%Y%m%d%H%M%S%f')[:-3]
if output_file is not None: if output_file is not None:
if not output_file.endswith(".json"): if not output_file.endswith(".json"):
output_file += ".json" output_file += ".json"
self.output_file = output_file self.output_file = output_file
else: else:
self.output_file = f"{self.collection_id}.json" self.output_file = f"{self.collection_id}.json"
if not os.path.exists(self.output_folder): if not os.path.exists(self.output_folder):
os.mkdir(self.output_folder) os.mkdir(self.output_folder)
...@@ -194,12 +197,12 @@ class Raster2STAC(): ...@@ -194,12 +197,12 @@ class Raster2STAC():
self.aws_region = aws_region self.aws_region = aws_region
self.s3_upload = s3_upload self.s3_upload = s3_upload
self.s3_client = None self.s3_client = None
self.version = version self.version = version
self.title = title self.title = title
if self.s3_upload: if self.s3_upload:
# Initializing an S3 client # Initializing an S3 client
self.s3_client = boto3.client('s3', aws_access_key_id=aws_access_key, aws_secret_access_key=aws_secret_key) #region_name=aws_region, self.s3_client = boto3.client('s3', aws_access_key_id=aws_access_key, aws_secret_access_key=aws_secret_key) #region_name=aws_region,
self.output_format = output_format self.output_format = output_format
self.license = license self.license = license
...@@ -298,7 +301,7 @@ class Raster2STAC(): ...@@ -298,7 +301,7 @@ class Raster2STAC():
# Write the result to the GeoTIFF file # Write the result to the GeoTIFF file
self.data.loc[{self.T_DIM:t,self.B_DIM:band}].to_dataset(name=band).rio.to_raster(raster_path=path, driver='COG') self.data.loc[{self.T_DIM:t,self.B_DIM:band}].to_dataset(name=band).rio.to_raster(raster_path=path, driver='COG')
link_path = path link_path = path
if self.s3_upload: if self.s3_upload:
#Uploading file to s3 #Uploading file to s3
...@@ -484,6 +487,7 @@ class Raster2STAC(): ...@@ -484,6 +487,7 @@ class Raster2STAC():
if self.sci_citation is not None or self.sci_doi is not None: if self.sci_citation is not None or self.sci_doi is not None:
self.extensions.append("https://stac-extensions.github.io/scientific/v1.0.0/schema.json") self.extensions.append("https://stac-extensions.github.io/scientific/v1.0.0/schema.json")
extra_fields["summaries"] = eo_info extra_fields["summaries"] = eo_info
......