geometamaker.models module

pydantic model geometamaker.models.ArchiveResource[source]

Bases: Resource

Class for metadata for an archive resource.

field compression: str = ''

The compression method used to create the archive.

model_post_init(_Resource__context)

This function is meant to behave like a BaseModel method to initialize private attributes.

It takes context as an argument since that’s what pydantic-core passes when calling it.

Parameters:
  • self – The BaseModel instance.

  • context – The context.

set_spatial(spatial: SpatialSchema)[source]

Set spatial properties of a resource.

pydantic model geometamaker.models.BandSchema[source]

Bases: Parent

Class for metadata for a raster band.

field description: str = ''

A description of the band.

field gdal_metadata: dict = {}

Metadata key:value pairs stored in the GDAL band object.

field gdal_type: str [Required]

The GDAL data type of the band.

field index: int [Required]

The index of the band of a GDAL raster, starting at 1.

field nodata: int | float | None [Required]

The pixel value that represents no data in the band.

field numpy_type: str [Required]

The numpy data type of the band.

field raster_attribute_table: RasterAttributeTable | None = None

A representation of a GDAL-readable Raster Attribute Table.

field title: str = ''

A human-readable title for the band.

field units: str = ''

Unit of measurement for the pixel values.

pydantic model geometamaker.models.BaseMetadata[source]

Bases: Parent

A class for the things shared by Resource and Profile.

field contact: ContactSchema [Optional]

Contact information for the data author.

field license: LicenseSchema [Optional]

Data license information.

get_contact()[source]

Get metadata from a contact section.

Returns:

ContactSchema

get_license()[source]

Get license for the dataset.

Returns:

models.LicenseSchema

replace(other)[source]

Replace attribute values with those from another instance.

Only attributes that exist in self will exist in the returned instance. Only attribute values that are not empty in other will be used to replace values in self.

Parameters:

other (BaseMetadata)

Returns:

an instance of same type as self

Raises:

TypeError if other is not an instance of BaseMetadata.

set_contact(organization=None, individual_name=None, position_name=None, email=None)[source]

Add a contact section.

Parameters:
  • organization (str) – name of the responsible organization

  • individual_name (str) – name of the responsible person

  • position_name (str) – role or position of the responsible person

  • email (str) – address of the responsible organization or individual

set_license(title=None, path=None)[source]

Add a license for the dataset.

Either or both title and path are required if there is a license. Call with no arguments to remove license info.

Parameters:
  • title (str) – human-readable title of the license

  • path (str) – url for the license

pydantic model geometamaker.models.BaseResource[source]

Bases: BaseMetadata

Base class for metadata for a resource.

https://datapackage.org/standard/data-resource/ This class borrows from the Data Package - Resource specification. But we have some additional properties that are important to us.

All attributes are keyword-only so that we can init with default values, allowing the user to get a template with which to complete later.

field bytes: int = 0

File size of the resource in bytes.

field citation: str = ''

A citation for the resource.

field description: str = ''

A text description of the resource.

field doi: str = ''

A digital object identifier for the resource.

field edition: str = ''

A string representing the edition, or version, of the resource.

field format: str = ''

File format of the resource.

field geometamaker_version: str = ''

The version of geometamaker used to create this metadata resource.

field keywords: list[str] [Optional]

A list of keywords that describe the subject-matter of the resource.

field last_modified: str = ''

Last modified time of the file at path.

field lineage: str = ''

A text description of how the resource was created.

field metadata_path: str = ''
field path: str = ''

Path to the resource being described.

field placenames: list[str] [Optional]

A list of geographic places associated with the resource.

field purpose: str = ''

The author’s stated purpose for the resource.

field scheme: str = ''

File protocol for opening the resource.

field spatial: SpatialSchema | None = None

An object for describing spatial properties of the resource.

field title: str = ''

The title of the resource.

field type: str = ''

The type of resource being described.

field uid: str = ''

Unique identifier for the resource.

field url: str = ''

A URL where the resource is available.

classmethod load(filepath)[source]

Load metadata document from a yaml file.

Parameters:

filepath (str) – path to yaml file

Returns:

instance of the class

Raises:
  • FileNotFoundError if filepath does not exist

  • ValueError if the metadata is found to be incompatible with – geometamaker.

get_citation()[source]

Get the citation for the dataset.

get_description()[source]

Get the description for the dataset.

get_doi()[source]

Get the doi for the dataset.

get_edition()[source]

Get the edition of the dataset.

Returns:

str or None if edition does not exist.

get_keywords()[source]

Get the keywords describing the dataset.

Returns:

list

get_lineage()[source]

Get the lineage statement of the dataset.

Returns:

str

get_placenames()[source]

Get the placenames describing the dataset.

Returns:

list

get_purpose()[source]

Get purpose for the dataset.

Returns:

str

get_title()[source]

Get the title for the dataset.

get_url()[source]

Get the url for the dataset.

model_post_init(context: Any, /) None

This function is meant to behave like a BaseModel method to initialize private attributes.

It takes context as an argument since that’s what pydantic-core passes when calling it.

Parameters:
  • self – The BaseModel instance.

  • context – The context.

set_citation(citation)[source]

Add a citation string for the dataset.

Parameters:

citation (str)

set_description(description)[source]

Add a description for the dataset.

Parameters:

description (str)

set_doi(doi)[source]

Add a doi string for the dataset.

Parameters:

doi (str)

set_edition(edition)[source]

Set the edition for the dataset.

Parameters:

edition (str) – version of the cited resource

set_keywords(keywords)[source]

Describe a dataset with a list of keywords.

Parameters:

keywords (list) – sequence of strings

set_lineage(statement)[source]

Set the lineage statement for the dataset.

Parameters:

statement (str) – general explanation describing the lineage or provenance of the dataset

set_placenames(placenames)[source]

Describe the geography of a dataset with a list of placenames.

Parameters:

places (list) – sequence of strings

set_purpose(purpose)[source]

Add a purpose for the dataset.

Parameters:

purpose (str) – description of the purpose of the source dataset

set_title(title)[source]

Add a title for the dataset.

Parameters:

title (str)

set_url(url)[source]

Add a url for the dataset.

Parameters:

url (str)

write(workspace=None, backup=True)[source]

Write metadata yaml to disk.

This creates sidecar files with ‘.yml’ appended to the full filename of the data source. For example,

  • ‘myraster.tif’

  • ‘myraster.tif.yml’

For a CollectionResource, the name of the target YML document can be specified with the target_filename argument of describe_collection.

Parameters:
  • workspace (str) – if None, files write to the same location as the source data. If not None, a path to a local directory to write the file. Use this option if the source data is not on the local filesystem.

  • backup (bool) – whether to write a backup of a pre-existing metadata file before ovewriting it in cases where that file is not a valid geometamaker document.

class geometamaker.models.BoundingBox(xmin: float, ymin: float, xmax: float, ymax: float)[source]

Bases: object

Class for a spatial bounding box.

to_list()[source]

Return the bounding box as a list: [xmin, ymin, xmax, ymax].

xmax: float
xmin: float
ymax: float
ymin: float
pydantic model geometamaker.models.CollectionItemSchema[source]

Bases: Parent

Class for metadata for collection items.

field description: str = ''

A text description of the resource.

field metadata: str = ''

Path to metadata document describing resource

field path: str = ''

Path to the resource being described.

pydantic model geometamaker.models.CollectionResource[source]

Bases: BaseResource

Class for metadata for a collection resource.

In the spatial properties of a collection, the bounding box is the union of the bounding boxes of all the items in the collection. If all items share the same CRS, the collection’s bounding box will match that CRS. If items use a different CRS from each other, bounding boxes are transformed to WGS84 before unioning.

field items: list[CollectionItemSchema] [Optional]

Files in collection.

model_post_init(_CollectionResource__context)[source]

This function is meant to behave like a BaseModel method to initialize private attributes.

It takes context as an argument since that’s what pydantic-core passes when calling it.

Parameters:
  • self – The BaseModel instance.

  • context – The context.

set_spatial(spatial: SpatialSchema)[source]

Set spatial properties of a resource.

pydantic model geometamaker.models.ContactSchema[source]

Bases: Parent

Class for storing contact information of data author.

field email: str = ''
field individual_name: str = ''
field organization: str = ''
field position_name: str = ''
pydantic model geometamaker.models.FieldSchema[source]

Bases: Parent

Metadata for a field in a table.

field description: str = ''

A description of the field.

field name: str [Required]

The name used to uniquely identify the field.

field title: str = ''

A human-readable title for the field.

field type: str [Required]

Datatype of the content of the field.

String label of a type inferred by pandas.api.types.infer_dtype

field units: str = ''

Unit of measurement for values in the field.

pydantic model geometamaker.models.LayerSchema[source]

Bases: Parent

Class for metadata for a GDAL vector’s layer.

field gdal_metadata: dict = {}

Metadata key:value pairs stored in the GDAL layer object.

field n_features: int [Required]

Number of features in the layer.

field name: str [Required]

The layer name.

field table: TableSchema [Optional]

A models.TableSchema object for describing fields in a layer’s table.

pydantic model geometamaker.models.LicenseSchema[source]

Bases: Parent

Class for storing data license information.

field path: str = ''

URL that describes the license.

field title: str = ''

Name of a license, such as one from http://licenses.opendefinition.org/

pydantic model geometamaker.models.Parent[source]

Bases: BaseModel

Parent class on which to configure validation.

Extra attributes are forbidden because we anticipate users editing YML docs manually and this can help catch accidental edits like a typo in an attribute name.

pydantic model geometamaker.models.Profile[source]

Bases: BaseMetadata

Class for a metadata profile.

A Profile can store metadata properties that are likely to apply to more than one resource, such as contact and license.

classmethod load(filepath)[source]

Load metadata document from a yaml file.

Parameters:

filepath (str) – path to yaml file

Returns:

instance of the class

write(target_path)[source]

Write profile data to a yaml file.

Parameters:

target_path (str) – path to a yaml file to be written

pydantic model geometamaker.models.RATColumnDefn[source]

Bases: Parent

Class for metadata for a column in a raster attribute table.

field name: str [Required]

The name used to uniquely identify the column.

field type: str [Required]

Datatype of the content of the column.

String representation of one of GDALRATFieldType or OGRFieldType.

field usage: str [Required]

The intended use of the column.

String representation of one of GDALRATFieldUsage.

pydantic model geometamaker.models.RasterAttributeTable[source]

Bases: Parent

Class for metadata for a raster attribute table.

field columns: list[RATColumnDefn] [Required]

A list of column definitions in the raster attribute table.

field rows: list[dict] [Required]

A list of dicts representing rows in the raster attribute table.

field table_type: Literal['Thematic', 'Athematic', 'Unknown'] [Required]

One of GDALRATTableType or Unknown.

classmethod from_gdal(rat)[source]

Create a RasterAttributeTable from a GDAL RAT object.

classmethod from_gdal_dbf(dbf_path)[source]

Create a RasterAttributeTable from a DBF file.

pydantic model geometamaker.models.RasterResource[source]

Bases: Resource

Class for metadata for a raster resource.

field data_model: RasterSchema [Required]

An object for describing raster properties and bands.

field spatial: SpatialSchema [Required]

An object for describing spatial properties of a GDAL dataset.

get_band_description(band_number)[source]

Get the metadata for a band.

Parameters:

band_number (int) – a raster band index, starting at 1

Returns:

BandSchema

get_rat(band_number)[source]

Get the raster attribute table for a band, if it exists.

Parameters:

band_number (int) – a raster band index, starting at 1

Returns:

RasterAttributeTable or None if no RAT exists for the band

model_post_init(_Resource__context)

This function is meant to behave like a BaseModel method to initialize private attributes.

It takes context as an argument since that’s what pydantic-core passes when calling it.

Parameters:
  • self – The BaseModel instance.

  • context – The context.

set_band_description(band_number, title=None, description=None, units=None)[source]

Define metadata for a raster band.

Parameters:
  • band_number (int) – a raster band index, starting at 1

  • title (str) – title for the raster band

  • description (str) – description of the raster band

  • units (str) – unit of measurement for the band’s pixel values

pydantic model geometamaker.models.RasterSchema[source]

Bases: Parent

Class for metadata for raster bands.

field bands: list[BandSchema] [Required]

A list of BandSchema objects.

field gdal_metadata: dict = {}

Metadata key:value pairs stored in the GDAL raster object.

field pixel_size: tuple[int | float, int | float] [Required]

The width and height of a pixel measured in SpatialSchema.crs_units.

field raster_size: dict | list [Required]

The width and height of the raster measured in number of pixels.

model_post_init(_RasterSchema__context)[source]

Override this method to perform additional initialization after __init__ and model_construct. This is useful if you want to do some validation that requires the entire model to be initialized.

pydantic model geometamaker.models.Resource[source]

Bases: BaseResource

Metadata class for general-purpose resources.

This class extends BaseResource and provides metadata for a single file or dataset, including encoding and source file references. It serves as a base for more specific resource types (e.g., table, raster, vector, archive) and is typically initialized by describe().

field encoding: str = ''

File encoding of the resource.

field sources: list[str] [Optional]

A list of files which comprise the dataset or resource.

model_post_init(_Resource__context)[source]

This function is meant to behave like a BaseModel method to initialize private attributes.

It takes context as an argument since that’s what pydantic-core passes when calling it.

Parameters:
  • self – The BaseModel instance.

  • context – The context.

pydantic model geometamaker.models.SpatialSchema[source]

Bases: Parent

Class for keeping track of spatial info.

field bounding_box: BoundingBox [Required]

Spatial extent [xmin, ymin, xmax, ymax].

field crs: str [Required]

Coordinate Reference System.

field crs_units: str [Required]

Units of measure for coordinates in the CRS.

pydantic model geometamaker.models.TableResource[source]

Bases: Resource

Class for metadata for a table resource.

field data_model: TableSchema [Optional]

A models.TableSchema object for describing fields.

get_field_description(name)[source]

Get the attribute metadata for a field.

Parameters:

name (str) – name and unique identifier of the field

Returns:

FieldSchema

model_post_init(_Resource__context)

This function is meant to behave like a BaseModel method to initialize private attributes.

It takes context as an argument since that’s what pydantic-core passes when calling it.

Parameters:
  • self – The BaseModel instance.

  • context – The context.

set_field_description(name, title=None, description=None, units=None, type=None)[source]

Define metadata for a tabular field.

Parameters:
  • name (str) – name and unique identifier of the field

  • title (str) – title for the field

  • description (str) – description of the field

  • units (str) – unit of measurement for the field’s values

  • type (str) – datatype of values in the field

set_spatial(spatial: SpatialSchema)[source]

Set spatial properties of a resource.

pydantic model geometamaker.models.TableSchema[source]

Bases: Parent

Class for metadata for tables.

field fields: list[FieldSchema] [Required]

A list of FieldSchema objects.

field foreignKeys: list[str] [Optional]

A field or list of fields that can be used to join another table.

See https://datapackage.org/standard/table-schema/#foreignKeys

field missingValues: list [Optional]

A list of values that represent missing data.

field primaryKey: list[str] [Optional]

A field or list of fields that uniquely identifies each row in the table.

get_field_description(name)[source]

Get the attribute metadata for a field.

Parameters:

name (str) – name and unique identifier of the field

Returns:

FieldSchema

set_field_description(name, title=None, description=None, units=None, type=None)[source]

Define metadata for a tabular field.

Parameters:
  • name (str) – name and unique identifier of the field

  • title (str) – title for the field

  • description (str) – description of the field

  • units (str) – unit of measurement for the field’s values

  • type (str) – datatype of values in the field

pydantic model geometamaker.models.VectorResource[source]

Bases: Resource

Class for metadata for a vector resource.

field data_model: VectorSchema [Required]

An object for describing vector properties and layers.

field spatial: SpatialSchema [Required]

An object for describing spatial properties of a GDAL dataset.

get_field_description(name)[source]

Get the attribute metadata for a field.

Parameters:

name (str) – name and unique identifier of the field

Returns:

FieldSchema

model_post_init(_Resource__context)

This function is meant to behave like a BaseModel method to initialize private attributes.

It takes context as an argument since that’s what pydantic-core passes when calling it.

Parameters:
  • self – The BaseModel instance.

  • context – The context.

set_field_description(name, title=None, description=None, units=None, type=None)[source]

Define metadata for a tabular field.

Parameters:
  • name (str) – name and unique identifier of the field

  • title (str) – title for the field

  • description (str) – description of the field

  • units (str) – unit of measurement for the field’s values

  • type (str) – datatype of values in the field

pydantic model geometamaker.models.VectorSchema[source]

Bases: Parent

field gdal_metadata: dict = {}

Metadata key:value pairs stored in the GDAL vector object.

field layers: list[LayerSchema] [Required]

A list of layers in the vector.

Geometamaker currently only supports vectors with one layer.