eNepper
eNepper

Reputation: 1969

Azure DocumentDb - Query Spatial Data

I'm testing Azure DocumentDb to decide if we should change our database from mongodb to doucmentDb.

We have a database with 10.000+ locations in mongodb where the locations are saved as geojson. So it no problem to move our data, but how do I query my data using the linq provider in the .NET SDK?

We have our own implementation of geojson that we use with our mongodb, so we are not interested in changing our data model to depend on the spatial classes provided in the .NET SDK.

Is there a way to use to linq provider with custom spatial classes when querying DocumentDb?

Upvotes: 2

Views: 838

Answers (1)

Adrian Hofman
Adrian Hofman

Reputation: 1451

DocumentDB has recently added support for spatial data types,and natively supports the GeoJSON standard: https://azure.microsoft.com/en-us/blog/announcing-geospatial-support-in-azure-documentdb/

Below is an example of using LINQ to do spatial queries in DocumentDB:

// An example document with spatial data
public class MyDocument 
{
    public string Id { get; set; }
    public Microsoft.Azure.Documents.Spatial.Point Location { get; set; }
}

// An example distance query - get all documents within 30 km of a given point
client.CreateDocumentQuery<MyDocument>(collection.SelfLink)
    .Where(x => x.Location.Distance(new Point(32.33, -4.66)) < 30000))

Upvotes: 3

Related Questions