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.

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

```