Package: meridian
meridianPerformant geospatial data processing in Python's language.Meridian lets you treat your geospatial dataset like you would any other Python data structure, but it is backed
with a spatial index for fast spatial queries. All data is stored in tuple-like objects,
which makes it very memory-efficient.Note: this library is still in alpha. The API and functionality will change often and without notice.UsageWhen shouldn't I use Meridian?Meridian is not meant to be a replacement for a database system, and as such it's not particularly
optimized or ergonomic for operations like finding specific records, though this is pretty easy to
do with a filter. Also, if your data is highly mutable, e.g. you want to modify records in place, then
you should probably look elsewhere.When should I use Meridian?Meridian shines when you have some reference dataset that you want to compare to an input dataset or single record.Meridian expects that you have a decent understanding of the data which you would like to work with. It requires
you to define an annotated model class which lists the attributes of the dataset which you want to work with.
You do this by subclassing themeridian.Recordobject:importmeridianclassCounty(meridian.Record):name:strfips:strSupposing you had a shape file with county geometry and the fields above, you could create aDatasetofCountys like so:counties=County.load_from("path/to/counties.shp")Meridian depends on the Fiona library to open most data files, which requires GDAL/OGR.
Wheels are available for many platforms, but not all.Creating aDatasetwill immediately load the data into memory and create a spatial index
which will be used for all queries. ADatasethas many attributes of other Python data structures:
it is iterable, has alen, etc.importmeridianfromshapelyimportgeometryclassCounty(meridian.Record):name:strfips:strcounties=County.load_from("path/to/counties.shp")# Find out how many records you haveprint(len(counties))poi=geometry.shape({'type':'Point','coordinates':[-72.319261,43.648956]})# Check if your poi intersects with the datasetprint(counties.intersects(poi))# True# See how many records intersectprint(counties.count(poi))# 1# Find the n nearest records to the query geometryprint(counties.nearest(poi,3))# The dataset itself is iterable.forcountyincounties:print(county.name)# iterate through all records in the dataset which bbox-intersect with poi# Dataset.intersection returns a tuple of Records.forcountyincounties.intersection(poi):print(county.name)Please note that spatial methods check only for a bounding-box intersection; you must confirm that the
objects returned actually intersect with your input.All of the spatial query methods on aDatasetrequire only that the query object has aboundsproperty which returns a 4-tuple like(xmin, ymin, xmax, ymax). As long as that exists,meridianis agnostic of query geometry implementation, however it does useshapelygeometry
under the hood for the records stored within.poi=geometry.shape({'type':'Point','coordinates':[-72.319261,43.648956]})forcountyincounties:print(county.geojson)# get back the record as GeoJSONprint(county.bounds)# The bounds of the geometryprint(county.name)# Record objects are fully compatible with all of the# objects & operations defined in the shapely package.print(poi.intersects(county))# Even advanced operations like cascaded union work as expected.fromshapely.opsimportcascaded_unionsubset=counties.intersection(poi)unioned=cascaded_union(subset)print(unioned.wkt)Finally, Meridian also includes utilities to easily and efficiently relate multiple datasets.For now, see theexamplesdirectory.TO BE FILLED IN:Product / intersection helpersModel behaviorField defaultsDerived attributesInstallationmeridianrequires GEOS (for theshapelylibrary), GDAL/OGR for reading data formats, andRtree/libspatialindexto create the spatial index used for querying.Rtree does not have wheels and this thelibspatialindexlibrary must be installed independently. Installation info can be foundhere.On Ubuntu you can use apt:aptinstall-ylibspatialindex-devArch:pacman-SyuspatialindexOn most systems,libspatialindexcan be compiled from source. These instructions should work on Linux & macOS:wget-qO-http://download.osgeo.org/libspatialindex/spatialindex-src-1.8.5.tar.gz|tarxz-C/tmpcd/tmp/spatialindex-src-1.8.5&&./configure;make;makeinstallOn Linux, you might need to runldconfigafterwards to ensure that thertreepython library can find the library correctly.Frompypi:pip install meridianOr, clone the repo and runpython path/to/repo/setup.py installYou can also usepipto install directly from the github repo:pip install git+git://github.com/tomplex/meridian.gitIf you use docker, there are images with all dependencies and the latest version ofmeridianpre-installed available ondocker hub.Opinionsmeridianis opinionated and believes that data should generally be immutable. If you need your data to change, you should create new data representing your input + processing instead of changing old data. Thus, aDatasetis more like afrozensetin behavior than alist.