Skip to content

Commit

Permalink
Merge pull request #24 from davemfish/exp/data-package
Browse files Browse the repository at this point in the history
Major refactor to use dataclasses that loosely follow DataPackage - Resource models
  • Loading branch information
phargogh authored Jul 25, 2024
2 parents ce1801e + d95f025 commit d75583c
Show file tree
Hide file tree
Showing 8 changed files with 1,013 additions and 1,188 deletions.
46 changes: 27 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
A Python library for creating [Metadata Control Files](https://geopython.github.io/pygeometa/reference/mcf/)
A Python library for creating human and machine-readable metadata for geospatial data.

Supported datatypes include:
* everything supported by GDAL
* tabular formats supported by `frictionless`
* compressed formats supported by `frictionless`


See `requirements.txt` for dependencies

Expand All @@ -7,48 +13,50 @@ See `requirements.txt` for dependencies
#### Creating & adding metadata to file:

```python
from geometamaker import MetadataControl
import geometamaker

data_path = 'data/watershed_gura.shp'
mc = MetadataControl(data_path)
resource = geometamaker.describe(data_path)

mc.set_title('My Dataset')
mc.set_abstract('all about my dataset')
mc.set_keywords(['hydrology', 'watersheds'])
resource.set_title('My Dataset')
resource.set_description('all about my dataset')
resource.set_keywords(['hydrology', 'watersheds'])

# For a vector:
mc.set_field_description(
resource.set_field_description(
'field_name', # the name of an actual field in the vector's table
abstract='something about the field',
description='something about the field',
units='mm')

# or for a raster:
mc.set_band_description(
data_path = 'data/dem.tif'
resource = geometamaker.describe(data_path)
resource.set_band_description(
1, # a raster band index, starting at 1
name='band name',
abstract='something about the band',
description='something about the band',
units='mm')


mc.validate()
mc.write()
resource.write()
```

#### Creating metadata for a batch of files:
```python
import os

from geometamaker import MetadataControl
import geometamaker

data_dir = 'C:/Users/dmf/projects/invest/data/invest-sample-data'
for path, dirs, files in os.walk(data_dir):
for file in files:
if file.endswith(('.shp', '.gpkg', '.tif')):
filepath = os.path.join(path, file)
print(filepath)
mc = MetadataControl(filepath)
mc.validate()
mc.write()
filepath = os.path.join(path, file)
print(filepath)
try:
resource = geometamaker.describe(filepath)
except ValueError as err:
print(err)
resource.write()
```

#### For a complete list of methods:
Expand Down
6 changes: 2 additions & 4 deletions docs/environment-rtd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ name: env-readthedocs
channels:
- conda-forge
dependencies:
- python=3.8
- python=3.10
- frictionless
- fsspec
- gdal>=3
- jsonschema
- numpy
- pygeometa
- pygeoprocessing>=2.4.2
- shapely
- pyyaml
- sphinx_rtd_theme
3 changes: 1 addition & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

import datetime
import os
import sys
import sphinx.ext.apidoc
from pkg_resources import get_distribution

sys.path.insert(0, os.path.abspath('../../src/geometamaker'))
sys.path.insert(0, os.path.abspath('../../src'))

# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
Expand Down
4 changes: 1 addition & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
aiohttp
fsspec
GDAL
jsonschema
frictionless
numpy
pygeometa
pygeoprocessing>=2.4.3
pyyaml
requests
shapely
7 changes: 6 additions & 1 deletion src/geometamaker/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
from .geometamaker import MetadataControl
import importlib.metadata

from .geometamaker import describe


__version__ = importlib.metadata.version('geometamaker')
Loading

0 comments on commit d75583c

Please sign in to comment.