/**
  * See {@link SpatialContext#SpatialContext(com.spatial4j.core.distance.DistanceUnits, com.spatial4j.core.distance.DistanceCalculator, com.spatial4j.core.shape.Rectangle)}.
  *
  * @param geometryFactory optional
  */
 public NtsSpatialContext(GeometryFactory geometryFactory, DistanceUnits units, DistanceCalculator calculator, Rectangle worldBounds)
     : base(units, calculator, worldBounds)
 {
     this.geometryFactory = geometryFactory ?? new GeometryFactory();
 }
 protected void InitUnits()
 {
     String unitsStr;
     if (!Args.TryGetValue("units", out unitsStr) || unitsStr == null)
         Units = DistanceUnits.KILOMETERS;
     else
         Units = DistanceUnits.FindDistanceUnit(unitsStr);
 }
 public NtsSpatialContext(DistanceUnits units)
     : base(units, null, null)
 {
     geometryFactory = new GeometryFactory();
 }
Beispiel #4
0
 public SpatialContext(DistanceUnits units)
 {
     Init(units, null, null);
 }
Beispiel #5
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="units">Required; and establishes geo vs cartesian.</param>
 /// <param name="calculator">Optional; defaults to Haversine or cartesian depending on units.</param>
 /// <param name="worldBounds">Optional; defaults to GEO_WORLDBOUNDS or MAX_WORLDBOUNDS depending on units.</param> 
 public SpatialContext(DistanceUnits units, DistanceCalculator calculator, Rectangle worldBounds)
 {
     Init(units, calculator, worldBounds);
 }
Beispiel #6
0
        protected void Init(DistanceUnits units, DistanceCalculator calculator, Rectangle worldBounds)
        {
            if (units == null)
                throw new ArgumentException("units can't be null", "units");

            this.units = units;

            if (calculator == null)
            {
                calculator = IsGeo()
                    ? (DistanceCalculator)new GeodesicSphereDistCalc.Haversine(units.EarthRadius())
                    : new CartesianDistCalc();
            }
            this.calculator = calculator;

            if (worldBounds == null)
            {
                worldBounds = IsGeo() ? GEO_WORLDBOUNDS : MAX_WORLDBOUNDS;
            }
            else
            {
                if (IsGeo())
                    Debug.Assert(new RectangleImpl(worldBounds).Equals(GEO_WORLDBOUNDS));
                if (worldBounds.GetCrossesDateLine())
                    throw new ArgumentException("worldBounds shouldn't cross dateline: " + worldBounds, "worldBounds");
            }
            //copy so we can ensure we have the right implementation
            worldBounds = MakeRect(worldBounds.GetMinX(), worldBounds.GetMaxX(), worldBounds.GetMinY(), worldBounds.GetMaxY());
            this.worldBounds = worldBounds;

            shapeReadWriter = MakeShapeReadWriter();

            this.maxCircleDistance = IsGeo() ? calculator.DegreesToDistance(180) : (double?)null;
        }
Beispiel #7
0
 /// <summary>
 /// Converts the given distance in given DistanceUnit, to a distance in the unit represented by {@code this}
 /// </summary>
 /// <param name="distance">Distance to convert</param>
 /// <param name="from">Unit to convert the distance from</param>
 /// <returns>Given distance converted to the distance in the given unit</returns>
 public double Convert(double distance, DistanceUnits from)
 {
     if (from == this)
     {
         return distance;
     }
     if (this == CARTESIAN || from == CARTESIAN)
     {
         throw new InvalidOperationException("Can't convert cartesian distances: " + from + " -> " + this);
     }
     return (this == MILES) ? distance * DistanceUtils.KM_TO_MILES : distance * DistanceUtils.MILES_TO_KM;
 }