DatasetWriter¶
A DatasetWriter provides write access to a geospatial dataset.
The add_asset() method accepts any provider
type: ImageAssetProvider,
BufferedImageAssetProvider,
TextAssetProvider,
BufferedTextAssetProvider,
DataAssetProvider,
GraphicsAssetProvider, or
AssetProvider (created via
AssetProvider.from_bytes).
- class aws.osml.io.DatasetWriter¶
Bases:
objectProvides write access to geospatial datasets.
A
DatasetWritercreates a new geospatial dataset (NITF, GeoTIFF, etc.) and populates it with assets and metadata. UseIO.open()with mode"w"and a format name to obtain an instance. The writer handles format-specific encoding details so you can focus on the content. It supports the Python context manager protocol, so resources are flushed and released automatically when thewithblock exits.Example:
```python from aws.osml.io import IO, BufferedMetadataProvider
metadata = BufferedMetadataProvider() metadata.set(“IC”, “NC”)
- with IO.open([“output.ntf”], “w”, “nitf”) as writer:
writer.metadata = metadata writer.add_asset(
“image:0”, image_provider, “Primary Image”, “RGB scene”, [“data”],
)
- add_asset(key, provider, title, description, roles)¶
Add an asset to the dataset.
Each asset is identified by a unique key and backed by an
AssetProvider(or any subtype such asBufferedImageAssetProvider).- Parameters:
key (str) – Unique string identifier for the asset.
provider (AssetProvider | ImageAssetProvider | BufferedImageAssetProvider) – The asset data to add.
title (str) – Human-readable title for the asset.
description (str) – Detailed description of the asset.
roles (list[str]) – Semantic roles (e.g.,
"data","thumbnail").
- Raises:
ValueError – If an asset with the given key already exists.
TypeError – If provider is not a valid asset provider type.
Example:
“image:0”, image_provider, “Primary Image”, “RGB scene”, [“data”],
)¶
- close()¶
Flush pending data and release all resources.
After calling this method the writer should not be used. When using the context manager (
withstatement),closeis called automatically on exit.- Raises:
IOError – If flushing data to storage fails.
- metadata¶
Set the dataset-level metadata.
Assign a
MetadataProvider(orBufferedMetadataProvider) containing file-level fields for the output file. For NITF, this populates the file header (security markings, originator, etc.). For TIFF, this has no effect — IFD tags and encoding hints are sourced from each asset provider’s metadata instead.- Raises:
IOError – If the metadata cannot be applied to the dataset.
- strict_encoding¶
Enable or disable strict encoding validation for metadata fields.
When strict is
True, numeric TRE fields are validated against their exact declared encoding (e.g. BCS-NPI rejects+,-,.). WhenFalse(the default), numeric fields accept any printable ASCII, tolerating real-world deviations from the spec.- Parameters:
strict (bool) – Whether to enforce strict encoding validation.
Example:
```python with IO.open(“output.ntf”, “w”, “nitf”) as writer:
writer.strict_encoding = True # enforce spec-exact validation