API Documentation

Dataset

class meridian.dataset.Dataset(data: Iterator[T], properties: <sphinx.ext.autodoc.importer._MockObject object at 0x7f82989092d0> = None)

Bases: typing.Generic

The Dataset provides a wrapper for Records, giving the user a way to query the Records within spatially.

bounds

The bounds of the Dataset.

Returns: 4-tuple (xmin, ymin, xmax, ymax)

count(query) → int

Count the number of objects in the SpatialDataset which intersect with the query object.

Args:
query: an object which exposes a bounds property of the (xmin, ymin, xmax, ymax) format.
Returns:
int
intersection(query) → Tuple[T, ...]

Find the intersection of the input geometry / spatial data and the SpatialDataset.

Args:
query: an object which exposes a bounds property of the (xmin, ymin, xmax, ymax) format.
Returns:
SpatialDataset of intersecting objects
intersects(query) → bool

Check if the SpatialDataset intersects with the query object.

Args:
query:
Returns:
bool
nearest(query, num_results=1) → Tuple[T, ...]

Find the nearest n objects in the SpatialDataset to the query object.

Args:
query: num_results:
Returns:
tuple of nearest records
class meridian.dataset.FastRTree(*args, **kwargs)

Bases: sphinx.ext.autodoc.importer._MockObject

A faster Rtree which uses a lower protocol when pickling objects for storage.

Record

class meridian.record.Record

Bases: tuple, typing.Generic

bounds

The bounds of the Record’s geometry, as a tuple like (xmin, ymin, xmax, ymax)

Returns:
4-tuple of float
classmethod from_geojson(geojson: Dict[str, Any]) → meridian.record.Record

Create a new Record from a geojson-like dict.

Args:
geojson:
Returns:
A new instance of the Record subclass.
geojson

Get the record as geojson

Returns:

geom

The geometry of the Record.

classmethod load_from(src: Any, **kwargs) → Dataset

Create a Dataset of the implemented model from a source, either a fiona-readable data file or iterable of geojson.

Args:
src: a path to a fiona-readable file or an
iterable of geojson-like dictionaries
kwargs:
passed directly to kwargs of fiona.open()
Returns:
A Dataset containing the items specified.

Product

class meridian.product.Product(d1: meridian.dataset.Dataset[~_T][_T], d2: meridian.dataset.Dataset[~_U][_U], predicate='intersects', error_callback=None)

Bases: object

Product represents a “spatial join” between two Datasets. It wraps an iterator of Record tuples which fulfill the chosen predicate.

Behavior is similar to itertools.product, except that it is not a full cartestian product; The tuples first item will match the first Dataset’s Record type, and the second will match the second.

the outer loop’s geometry is prepared so predicates will be efficient.

meridian.product.intersection(d1: meridian.dataset.Dataset[~_T][_T], d2: meridian.dataset.Dataset[~_U][_U]) → Iterator[Tuple[_T, _U]]

A special case of Product based on the “intersects” predicate.

meridian.product.product(d1: meridian.dataset.Dataset[~_T][_T], d2: meridian.dataset.Dataset[~_U][_U], predicate: str = 'intersects') → Iterator[Tuple[_T, _U]]

Helper function if you don’t care about metadata like errors etc.