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.For a library-opened remote destination this also closes the retained Python file handle(s), committing the object-store upload(s). The format writer is finalized first (each final
flushmust land before the corresponding handle closes and the upload commits), then every handle is closed and any error surfaced as aPyErr— an upload-commit failure is a real write failure, which is why this lives in the explicitclose/__exit__path rather than aDropimpl that could not report it. There may be one handle (single-path write) or several (a multi-path R-set pyramid, one per remote key). All steps run even if an earlier one fails, so no partial handle is left dangling; the first error wins. Idempotent: a secondcloseis a no-op (the takeninnerand drained handles leave nothing to do).- 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