本文整理汇总了C#中Spatial4n.Core.Context.SpatialContext类的典型用法代码示例。如果您正苦于以下问题:C# SpatialContext类的具体用法?C# SpatialContext怎么用?C# SpatialContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SpatialContext类属于Spatial4n.Core.Context命名空间,在下文中一共展示了SpatialContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetTestData
/** Reads the stream, consuming a format that is a tab-separated values of 3 columns:
* an "id", a "name" and the "shape". Empty lines and lines starting with a '#' are skipped.
* The stream is closed.
*/
public static IEnumerator<SpatialTestData> GetTestData(Stream @in, SpatialContext ctx)
{
List<SpatialTestData> results = new List<SpatialTestData>();
TextReader bufInput = new StreamReader(@in, Encoding.UTF8);
try
{
String line;
while ((line = bufInput.ReadLine()) != null)
{
if (line.Length == 0 || line[0] == '#')
continue;
SpatialTestData data = new SpatialTestData();
String[] vals = line.Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries);
if (vals.Length != 3)
throw new ArgumentException("bad format; expecting 3 tab-separated values for line: " + line);
data.id = vals[0];
data.name = vals[1];
try
{
data.shape = ctx.ReadShapeFromWkt(vals[2]);
}
catch (ParseException e)
{
throw new ApplicationException(e.Message, e);
}
results.Add(data);
}
}
finally
{
bufInput.Dispose();
}
return results.GetEnumerator();
}
示例2: ResolveDistErr
/// <summary>
/// Gets the error distance that specifies how precise the query shape is. This
/// looks at <see cref="DistErr"/>, <see cref="DistErrPct"/>, and
/// <paramref name="defaultDistErrPct"/>.
/// </summary>
/// <param name="ctx"></param>
/// <param name="defaultDistErrPct">0 to 0.5</param>
/// <returns>>= 0</returns>
public virtual double ResolveDistErr(SpatialContext ctx, double defaultDistErrPct)
{
if (DistErr != null)
return DistErr.Value;
double distErrPct = (this.distErrPct ?? defaultDistErrPct);
return CalcDistanceFromErrPct(Shape, distErrPct, ctx);
}
示例3: MakeSPT
//1m
/// <summary>The factory is looked up via "prefixTree" in args, expecting "geohash" or "quad".
/// </summary>
/// <remarks>
/// The factory is looked up via "prefixTree" in args, expecting "geohash" or "quad".
/// If its neither of these, then "geohash" is chosen for a geo context, otherwise "quad" is chosen.
/// </remarks>
public static SpatialPrefixTree MakeSPT(IDictionary<string, string> args, SpatialContext ctx)
{
SpatialPrefixTreeFactory instance;
string cname = args[PrefixTree];
if (cname == null)
{
cname = ctx.IsGeo() ? "geohash" : "quad";
}
if ("geohash".Equals(cname, StringComparison.OrdinalIgnoreCase))
{
instance = new GeohashPrefixTree.Factory();
}
else
{
if ("quad".Equals(cname, StringComparison.OrdinalIgnoreCase))
{
instance = new QuadPrefixTree.Factory();
}
else
{
try
{
Type c = Type.GetType(cname);
instance = (SpatialPrefixTreeFactory)System.Activator.CreateInstance(c);
}
catch (Exception e)
{
throw new Exception(string.Empty, e);
}
}
}
instance.Init(args, ctx);
return instance.NewSPT();
}
示例4: TestSimpleCircle
public void TestSimpleCircle(SpatialContext ctx)
{
base.ctx = ctx;
double[] theXs = new double[] { -10, 0, 10 };
foreach (double x in theXs)
{
double[] theYs = new double[] { -20, 0, 20 };
foreach (double y in theYs)
{
TestCircle(x, y, 0);
TestCircle(x, y, 5);
}
}
testCircleReset(ctx);
//INTERSECTION:
//Start with some static tests that have shown to cause failures at some point:
Assert.Equal( /*"getX not getY",*/
SpatialRelation.INTERSECTS,
ctx.MakeCircle(107, -81, 147).Relate(ctx.MakeRectangle(92, 121, -89, 74)));
TestCircleIntersect();
}
示例5: QuadPrefixTree
public QuadPrefixTree(SpatialContext ctx, Rectangle bounds, int maxLevels)
: base(ctx, maxLevels)
{
//not really sure how big this should be
// side
// number
xmin = bounds.GetMinX();
xmax = bounds.GetMaxX();
ymin = bounds.GetMinY();
ymax = bounds.GetMaxY();
levelW = new double[maxLevels];
levelH = new double[maxLevels];
levelS = new int[maxLevels];
levelN = new int[maxLevels];
gridW = xmax - xmin;
gridH = ymax - ymin;
xmid = xmin + gridW / 2.0;
ymid = ymin + gridH / 2.0;
levelW[0] = gridW / 2.0;
levelH[0] = gridH / 2.0;
levelS[0] = 2;
levelN[0] = 4;
for (int i = 1; i < levelW.Length; i++)
{
levelW[i] = levelW[i - 1] / 2.0;
levelH[i] = levelH[i - 1] / 2.0;
levelS[i] = levelS[i - 1] * 2;
levelN[i] = levelN[i - 1] * 4;
}
}
示例6: QuadPrefixTree
internal readonly int[] levelN; // number
public QuadPrefixTree(SpatialContext ctx, IRectangle bounds, int maxLevels)
: base(ctx, maxLevels)
{
xmin = bounds.MinX;
xmax = bounds.MaxX;
ymin = bounds.MinY;
ymax = bounds.MaxY;
levelW = new double[maxLevels];
levelH = new double[maxLevels];
levelS = new int[maxLevels];
levelN = new int[maxLevels];
gridW = xmax - xmin;
gridH = ymax - ymin;
this.xmid = xmin + gridW / 2.0;
this.ymid = ymin + gridH / 2.0;
levelW[0] = gridW / 2.0;
levelH[0] = gridH / 2.0;
levelS[0] = 2;
levelN[0] = 4;
for (int i = 1; i < levelW.Length; i++)
{
levelW[i] = levelW[i - 1] / 2.0;
levelH[i] = levelH[i - 1] / 2.0;
levelS[i] = levelS[i - 1] * 2;
levelN[i] = levelN[i - 1] * 4;
}
}
示例7: testMultiShape
public void testMultiShape(SpatialContext ctx)
{
this.ctx = ctx;
if(ctx.IsGeo()) return;//TODO not yet supported!
//come up with some random shapes
int NUM_SHAPES = random.Next(1, 5);
var shapes = new List<Rectangle>(NUM_SHAPES);
while (shapes.Count < NUM_SHAPES)
{
shapes.Add(RandomRectangle(20));
}
var multiShape = new MultiShape(shapes.Cast<Shape>(), ctx);
//test multiShape.getBoundingBox();
Rectangle msBbox = multiShape.GetBoundingBox();
if (shapes.Count == 1)
{
Assert.Equal(shapes[0], msBbox.GetBoundingBox());
}
else
{
foreach (Rectangle shape in shapes)
{
AssertRelation("bbox contains shape", SpatialRelation.CONTAINS, msBbox, shape);
}
}
//TODO test multiShape.relate()
}
示例8: MakeSPT
/// <summary>The factory is looked up via "prefixTree" in args, expecting "geohash" or "quad".</summary>
/// <remarks>
/// The factory is looked up via "prefixTree" in args, expecting "geohash" or "quad".
/// If its neither of these, then "geohash" is chosen for a geo context, otherwise "quad" is chosen.
/// </remarks>
public static SpatialPrefixTree MakeSPT(IDictionary<string, string> args, SpatialContext ctx)
{
SpatialPrefixTreeFactory instance;
string cname;
if (!args.TryGetValue(PREFIX_TREE, out cname))
{
cname = ctx.IsGeo ? "geohash" : "quad";
}
if ("geohash".Equals(cname, StringComparison.OrdinalIgnoreCase))
{
instance = new GeohashPrefixTree.Factory();
}
else if ("quad".Equals(cname, StringComparison.OrdinalIgnoreCase))
{
instance = new QuadPrefixTree.Factory();
}
else
{
try
{
Type c = Type.GetType(cname);
instance = (SpatialPrefixTreeFactory)Activator.CreateInstance(c);
}
catch (Exception e)
{
throw new ApplicationException(string.Empty, e);
}
}
instance.Init(args, ctx);
return instance.NewSPT();
}
示例9: Init
protected void Init(SpatialContext ctx, Rectangle bounds, int maxLevels)
{
this.xmin = bounds.GetMinX();
this.xmax = bounds.GetMaxX();
this.ymin = bounds.GetMinY();
this.ymax = bounds.GetMaxY();
levelW = new double[maxLevels];
levelH = new double[maxLevels];
levelS = new int[maxLevels];
levelN = new int[maxLevels];
gridW = xmax - xmin;
gridH = ymax - ymin;
xmid = xmin + gridW / 2.0;
ymid = ymin + gridH / 2.0;
levelW[0] = gridW / 2.0;
levelH[0] = gridH / 2.0;
levelS[0] = 2;
levelN[0] = 4;
for (int i = 1; i < levelW.Length; i++)
{
levelW[i] = levelW[i - 1] / 2.0;
levelH[i] = levelH[i - 1] / 2.0;
levelS[i] = levelS[i - 1] * 2;
levelN[i] = levelN[i - 1] * 4;
}
}
示例10: CalcBoxByDistFromPt
public override Rectangle CalcBoxByDistFromPt(Point @from, double distance, SpatialContext ctx)
{
Debug.Assert(radius == ctx.GetUnits().EarthRadius());
if (distance == 0)
return from.GetBoundingBox();
return DistanceUtils.CalcBoxByDistFromPtDEG(from.GetY(), from.GetX(), distance, ctx);
}
示例11: CircleImpl
//we don't have a line shape so we use a rectangle for these axis
public CircleImpl(Point p, double dist, SpatialContext ctx)
{
//We assume any normalization / validation of params already occurred (including bounding dist)
this.point = p;
this.distRadius = dist;
this.ctx = ctx;
this.enclosingBox = ctx.GetDistCalc().CalcBoxByDistFromPt(point, distRadius, ctx);
}
示例12: CircleImpl
//we don't have a line shape so we use a rectangle for these axis
public CircleImpl(Point p, double radiusDEG, SpatialContext ctx)
{
//We assume any validation of params already occurred (including bounding dist)
this.ctx = ctx;
this.point = p;
this.radiusDEG = radiusDEG;
this.enclosingBox = ctx.GetDistCalc().CalcBoxByDistFromPt(point, this.radiusDEG, ctx, null);
}
示例13: ShapeFieldCacheDistanceValueSource
public ShapeFieldCacheDistanceValueSource(SpatialContext ctx,
ShapeFieldCacheProvider<IPoint> provider, IPoint from, double multiplier)
{
this.ctx = ctx;
this.from = from;
this.provider = provider;
this.multiplier = multiplier;
}
示例14: testCircleReset
public static void testCircleReset(SpatialContext ctx)
{
Circle c = ctx.MakeCircle(3, 4, 5);
Circle c2 = ctx.MakeCircle(5, 6, 7);
c2.Reset(3, 4, 5); // to c1
Assert.Equal(c, c2);
Assert.Equal(c.GetBoundingBox(), c2.GetBoundingBox());
}
示例15: SpatialStrategy
/// <summary>
/// Constructs the spatial strategy with its mandatory arguments.
/// </summary>
/// <param name="ctx"></param>
/// <param name="fieldName"> </param>
protected SpatialStrategy(SpatialContext ctx, string fieldName)
{
if (ctx == null)
throw new ArgumentException("ctx is required", "ctx");
this.ctx = ctx;
if (string.IsNullOrEmpty(fieldName))
throw new ArgumentException("fieldName is required", "fieldName");
this.fieldName = fieldName;
}