/// <summary> /// The factory class is lookuped up via "spatialContextFactory" in args /// then falling back to a Java system property (with initial caps). If neither are specified /// then {@link SimpleSpatialContextFactory} is chosen. /// </summary> /// <param name="args"></param> /// <returns></returns> public static SpatialContext MakeSpatialContext(Dictionary<String, String> args) { SpatialContextFactory instance; String cname; //if (!Configuration.GetValue("SpatialContextFactory", out cname) || cname == null) if (!args.TryGetValue("spatialContextFactory", out cname) || cname == null) { instance = new SpatialContextFactory(); instance.Init(args); return instance.NewSpatialContext(); } else { Type t = Type.GetType(cname); instance = (SpatialContextFactory)Activator.CreateInstance(t); //See if the specified type has subclassed the "NewSpatialContext" method and if so call it to do the setup var subClassedMethod = t.GetMethod("NewSpatialContext", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.DeclaredOnly); if (subClassedMethod != null) return (SpatialContext)subClassedMethod.Invoke(instance, new object[] { }); //Otherwise fallback to the default behaviour instance.Init(args); return instance.NewSpatialContext(); } }
/// <summary> /// The factory class is lookuped up via "spatialContextFactory" in args /// then falling back to a Java system property (with initial caps). If neither are specified /// then {@link SimpleSpatialContextFactory} is chosen. /// </summary> /// <param name="args"></param> /// <returns></returns> public static SpatialContext MakeSpatialContext(Dictionary <String, String> args) { SpatialContextFactory instance; String cname; //if (!Configuration.GetValue("SpatialContextFactory", out cname) || cname == null) if (!args.TryGetValue("spatialContextFactory", out cname) || cname == null) { instance = new SpatialContextFactory(); instance.Init(args); return(instance.NewSpatialContext()); } else { Type t = Type.GetType(cname); instance = (SpatialContextFactory)Activator.CreateInstance(t); //See if the specified type has subclassed the "NewSpatialContext" method and if so call it to do the setup var subClassedMethod = t.GetMethod("NewSpatialContext", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.DeclaredOnly); if (subClassedMethod != null) { return((SpatialContext)subClassedMethod.Invoke(instance, new object[] { })); } //Otherwise fallback to the default behaviour instance.Init(args); return(instance.NewSpatialContext()); } }
private static SpatialContextFactory InitFromLegacyConstructor(bool geo, IDistanceCalculator calculator, IRectangle worldBounds) { SpatialContextFactory factory = new SpatialContextFactory(); factory.geo = geo; factory.distCalc = calculator; factory.worldBounds = worldBounds; return(factory); }
private static SpatialContext Call(params string[] argsStr) { var args = new Dictionary <string, string>(); for (int i = 0; i < argsStr.Length; i += 2) { string key = argsStr[i]; string val = argsStr[i + 1]; args.Add(key, val); } return(SpatialContextFactory.MakeSpatialContext(args)); }
/// <summary> /// Called by <see cref="SpatialContextFactory.NewSpatialContext()"/>. /// </summary> /// <param name="factory"></param> public SpatialContext(SpatialContextFactory factory) { this.geo = factory.geo; if (factory.distCalc == null) { this.calculator = IsGeo ? (IDistanceCalculator) new GeodesicSphereDistCalc.Haversine() : new CartesianDistCalc(); } else { this.calculator = factory.distCalc; } //TODO remove worldBounds from Spatial4j: see Issue #55 IRectangle bounds = factory.worldBounds; if (bounds == null) { this.worldBounds = IsGeo ? new Rectangle(-180, 180, -90, 90, this) : new Rectangle(-double.MaxValue, double.MaxValue, -double.MaxValue, double.MaxValue, this); } else { if (IsGeo && !bounds.Equals(new Rectangle(-180, 180, -90, 90, this))) { throw new ArgumentException("for geo (lat/lon), bounds must be " + GEO.WorldBounds); } if (bounds.MinX > bounds.MaxX) { throw new ArgumentException("worldBounds minX should be <= maxX: " + bounds); } if (bounds.MinY > bounds.MaxY) { throw new ArgumentException("worldBounds minY should be <= maxY: " + bounds); } //hopefully worldBounds' rect implementation is compatible this.worldBounds = new Rectangle(bounds, this); } this.normWrapLongitude = factory.normWrapLongitude && this.IsGeo; this.wktShapeParser = factory.MakeWktShapeParser(this); this.binaryCodec = factory.MakeBinaryCodec(this); }
/// <summary> /// Creates a new <see cref="SpatialContext"/> based on configuration in /// <paramref name="args"/>. See the class definition for what keys are looked up /// in it. /// The factory class is looked up via "spatialContextFactory" in args /// then falling back to an <see cref="Environment.GetEnvironmentVariable(string)"/> setting (with initial caps). If neither are specified /// then <see cref="SpatialContextFactory"/> is chosen. /// </summary> /// <param name="args">Non-null map of name-value pairs.</param> public static SpatialContext MakeSpatialContext(IDictionary <string, string> args) { SpatialContextFactory instance; string cname; args.TryGetValue("spatialContextFactory", out cname); if (cname == null) { cname = Environment.GetEnvironmentVariable("SpatialContextFactory"); } if (cname == null) { instance = new SpatialContextFactory(); } else { Type t = Type.GetType(cname); instance = (SpatialContextFactory)Activator.CreateInstance(t); } instance.Init(args); return(instance.NewSpatialContext()); }