Here's come code that is working for me. I haven't had time to write
the unit tests and check it in. Sorry fot the code dump. Let me know
if you have any questions.
//NearQualifier
namespace Norm
{
/// <summary>
/// The within qualifier
/// </summary>
public class NearQualifier : QualifierCommand
{
/// <summary>
/// Initializes a new instance of the <see
cref="NearQualifier"/> class.
/// </summary>
/// <param name="center"></param>
public NearQualifier(LatLng center)
: base("$near", center.ToArray())
{
}
}
}
//STOP
using Norm.BSON;
namespace Norm
{
/// <summary>
/// Interface to limit classes for the Within Qualifier
/// </summary>
public interface IWhitinShapeQualifier
{
}
/// <summary>
/// The within qualifier
/// </summary>
public class WithinQualifier : QualifierCommand
{
/// <summary>
/// Initializes a new instance of the <see
cref="WithinQualifier"/> class.
/// </summary>
/// <param name="qualifier"></param>
public WithinQualifier(IWhitinShapeQualifier qualifier)
: base("$within", qualifier)
{
}
}
/// <summary>
/// Represents a coordinate
/// </summary>
public class LatLng {
/// <summary>
/// The latitude
/// </summary>
public double Latitude { get; set;}
/// <summary>
/// The longitude
/// </summary>
public double Longitude{get; set;}
/// <summary>
/// Creates an array of doubles
/// </summary>
/// <returns></returns>
public double[] ToArray(){
return new double[]{
this.Latitude ,
this.Longitude
};
}
}
/// <summary>
/// The Box Qualifier
/// </summary>
public class BoxQualifer : QualifierCommand,
IWhitinShapeQualifier
{
/// <summary>
/// Initializes a new instance of the <see cref="BoxQualifer"/
> class.
/// </summary>
/// <param name="northEast">The top right corner of the box</
param>
/// <param name="southWest">The bottom left corner of the box</
param>
public BoxQualifer(LatLng southWest, LatLng northEast)
: base("$box", new object[] { southWest.ToArray(),
northEast.ToArray() })
{
}
}
/// <summary>
/// The Circle Qualifier
/// </summary>
public class CircleQualifer : QualifierCommand,
IWhitinShapeQualifier
{
/// <summary>
/// Initializes a new instance of the <see
cref="CircleQualifer"/> class.
/// </summary>
/// <param name="center">The center point</param>
/// <param name="radius">The radius of the search</param>
public CircleQualifer(LatLng center, double radius )
: base("$center", new object [] { center.ToArray(),
radius })
{
}
}
}
//STOP
Add these to the Q.cs
/// <summary>
/// Builds a $near : [lat, lng] qualifier for the search.
/// </summary>
/// <param name="center">Center location</param>
/// <returns></returns>
public static NearQualifier Exists(LatLng center)
{
return new NearQualifier(center);
}
/// <summary>
/// Builds a $within {$box : [southwestnortheast, southwest]}
qualifier for the search.
/// </summary>
/// <param name="northEast">Top right</param>
/// <param name="southWest">Left bottom</param>
/// <returns></returns>
public static WithinQualifier WithinBox(LatLng southWest,
LatLng northEast)
{
IWhitinShapeQualifier shapeQualifier = new
BoxQualifer(southWest, northEast);
return new WithinQualifier(shapeQualifier);
}
/// <summary>
/// Builds a $within {$center : [center, radius]}qualifier
for the search.
/// </summary>
/// <param name="center">Center of the circle</param>
/// <param name="radius">Radius of the circle</param>
/// <returns></returns>
public static WithinQualifier WithinCircle(LatLng center,
double radius)
{
IWhitinShapeQualifier shapeQualifier = new
CircleQualifer(center, radius);
return new WithinQualifier(shapeQualifier);
}
//USAGE
var collection = _provider.DB.GetCollection<City>();
return collection.Find(new
{
loc = Q.WithinBox(
new LatLng() { Latitude = box.SouthWest.Latitude,
Longitude = box.SouthWest.Longitude },
new LatLng() { Latitude = box.NorthEast.Latitude,
Longitude = box.NorthEast.Longitude }
)
}).ToList();
On Apr 21, 5:02 am, luke <
lukenlow...@gmail.com> wrote:
> Hey guys,
>
> I working on a project that is going to do some location based storage
> and querying and I really want to give mongodb and norm a go.
>
> Does Norm support any of these mongo geospacial features -
http://www.mongodb.org/display/DOCS/Geospatial+Indexing?