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: object

Provides write access to geospatial datasets.

A DatasetWriter creates a new geospatial dataset (NITF, GeoTIFF, etc.) and populates it with assets and metadata. Use IO.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 the with block 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 as BufferedImageAssetProvider).

Parameters:
Raises:
  • ValueError – If an asset with the given key already exists.

  • TypeError – If provider is not a valid asset provider type.

Example:

```python writer.add_asset(

“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 (with statement), close is 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 flush must land before the corresponding handle closes and the upload commits), then every handle is closed and any error surfaced as a PyErr — an upload-commit failure is a real write failure, which is why this lives in the explicit close/__exit__ path rather than a Drop impl 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 second close is a no-op (the taken inner and drained handles leave nothing to do).

Raises:

IOError – If flushing data to storage fails.

metadata

Set the dataset-level metadata.

Assign a MetadataProvider (or BufferedMetadataProvider) 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 +, -, .). When False (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

```