RavenDB Integration - sibartlett/Geo GitHub Wiki

RavenDB 2.0 introduced better support for indexing and querying spatial information. Geo has been integrated with the RavenDB Client library to provide a more elegant API for handling spatial information.

Geo's RavenDB Integration allows you to store, index, and query the following Geo data types:

  • Geometries (Point, LineString, Polygon, GeometryCollection, Circle, etc...)
  • Envelope
  • GPS datatypes (Track, Route)

The following sections assume you have some working knowledge of RavenDB.

Configuration

When configuring your document store, you're need to apply Geo's RavenDB conventions:

store.ApplyGeoConventions().Initialize();

Example Usage

The following examples will compare the standard RavenDB spatial API to the enhanced API provided by Geo's ravenDB integration.

Storing a spatial document

RavenDB 2.0 (vanilla):

var doc = new MySpatialDoc {
		Title = "My House",
		Geometry = "POINT (0 56.9)"
	};

session.Store(doc);

RavenDB 2.0 with Geo:

var doc = new MySpatialDoc {
		Title = "My House",
		Geometry = new Point(56.9, 0)
	};

session.Store(doc);

Indexing spatial documents

RavenDB 2.0 (vanilla):

public class MySpatialIndex : AbstractIndexCreationTask<MySpatialDoc>
{
	public MySpatialIndex()
	{
		Map = docs => from doc in docs
			select new
				{
					Title = doc.Title,
					_ = SpatialGenerate("MySpatialField", doc.Geometry)
				};
	}
}

RavenDB 2.0 with Geo:

public class MySpatialIndex : GeoIndexCreationTask<MySpatialDoc>
{
	public MySpatialIndex()
	{
		Map = docs => from doc in docs
			select new
				{
					Title = doc.Title,
					_ = GeoIndex(doc.Geometry)
				};
	}
}

Querying

RavenDB 2.0 (vanilla):

var polygonString = "POLYGON ((0 0, 0 90, 90 0, 90 -90, 0 0))";

var items = session.Query<MySpatialDoc>()
			.Customise(x => x.RelatesToShape(fieldName: "MySpatialField", shapeWKT: polygonString, SpatialRelation.Within))
			.ToList();

RavenDB 2.0 with Geo:

var polygon = new Polygon(
		new Coordinate(0, 0),
		new Coordinate(90, 0),
		new Coordinate(0, 90),
		new Coordinate(-90, 90),
		new Coordinate(0, 0)
	);

var items = session.Query<MySpatialDoc>()
			.Geo(x => x.Geometry, x => x.Within(polygon))
			.ToList();
⚠️ **GitHub.com Fallback** ⚠️