public static Query MakeQuery(SpatialStrategy spatialStrategy, string shapeWKT, SpatialRelation relation, double distanceErrorPct = 0.025) { SpatialOperation spatialOperation; Shape shape = ShapeReadWriter.ReadShape(shapeWKT); switch (relation) { case SpatialRelation.Within: spatialOperation = SpatialOperation.IsWithin; break; case SpatialRelation.Contains: spatialOperation = SpatialOperation.Contains; break; case SpatialRelation.Disjoint: spatialOperation = SpatialOperation.IsDisjointTo; break; case SpatialRelation.Intersects: spatialOperation = SpatialOperation.Intersects; break; case SpatialRelation.Nearby: var nearbyArgs = new SpatialArgs(SpatialOperation.IsWithin, shape); nearbyArgs.SetDistPrecision(distanceErrorPct); // only sort by this, do not filter return new FunctionQuery(spatialStrategy.MakeValueSource(nearbyArgs)); default: throw new ArgumentOutOfRangeException("relation"); } var args = new SpatialArgs(spatialOperation, shape); args.SetDistPrecision(distanceErrorPct); return spatialStrategy.MakeQuery(args); }
public SpatialArgs Parse(String v, SpatialContext ctx) { int idx = v.IndexOf('('); int edx = v.LastIndexOf(')'); if (idx < 0 || idx > edx) { throw new InvalidSpatialArgument("missing parens: " + v); } SpatialOperation op = SpatialOperation.Get(v.Substring(0, idx).Trim()); //Substring in .NET is (startPosn, length), But in Java it's (startPosn, endPosn) //see http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#substring(int, int) String body = v.Substring(idx + 1, edx - (idx + 1)).Trim(); if (body.Length < 1) { throw new InvalidSpatialArgument("missing body : " + v); } var shape = ctx.ReadShape(body); var args = new SpatialArgs(op, shape); if (v.Length > (edx + 1)) { body = v.Substring(edx + 1).Trim(); if (body.Length > 0) { Dictionary<String, String> aa = ParseMap(body); args.Min = ReadDouble(aa["min"]); args.Max = ReadDouble(aa["max"]); args.SetDistPrecision(ReadDouble(aa["distPrec"])); if (aa.Count > 3) { throw new InvalidSpatialArgument("unused parameters: " + aa); } } } return args; }