Beispiel #1
0
        private (bool, StatAreaLocation) NearestBoundingBox(LatLong pt, OrderedFeatures locations)
        {
            foreach (var feat in locations.BoundariesContainingPoint(pt))
            {
                // allocate to the first bounding box  it finds

                var areaName        = feat.Parameters.Name;
                var statisticalArea = long.Parse(feat.Parameters.Id);

                return(true, new StatAreaLocation(statisticalArea, areaName));
            }


            return(false, StatAreaLocation.Null());
        }
        public BoundingBox(string sequence)
        {
            var arr = sequence.Split(' ');

            if (arr.Length != 2)
            {
                throw new ArgumentException("missing");
            }

            var lowerLeft  = new LatLong(arr[0]);
            var upperRight = new LatLong(arr[1]);

            Xmin = Math.Min(lowerLeft.Lon, upperRight.Lon);
            Xmax = Math.Max(lowerLeft.Lon, upperRight.Lon);
            Ymin = Math.Min(lowerLeft.Lat, upperRight.Lat);
            Ymax = Math.Max(lowerLeft.Lat, upperRight.Lat);
        }
Beispiel #3
0
        public StatisticalAreaClassification WhatRegions(LatLong pt)
        {
            if (Locations.TryGetValue(pt, out var area))
            {
                return(area);
            }


            // else work out where fits
            var clas = new StatisticalAreaClassification(pt);

            foreach (var setpair in SASets)
            {
                (bool found, StatAreaLocation loc) = InFeatureSet(pt, setpair.Value);

                if (!found)
                {
                    (found, loc) = NearestBoundingBox(pt, setpair.Value);
                }

                if (found)
                {
                    clas.Regions.Add(setpair.Key, loc);

                    if (!SANames.TryGetValue(setpair.Key, out var outer))
                    {
                        outer = new Dictionary <long, string>();
                        SANames.Add(setpair.Key, outer);
                    }

                    if (!outer.ContainsKey(loc.Id))
                    {
                        outer.Add(loc.Id, loc.Name);
                    }
                }
                else
                {
                    //   Console.WriteLine($"Still Missed {setpair.Key}\t{pt.Lat}, {pt.Lon}");
                }
            }

            return(clas);
        }
Beispiel #4
0
        private (bool, StatAreaLocation) InFeatureSet(LatLong pt, OrderedFeatures locations)
        {
            foreach (var feat in locations.BoundariesContainingPoint(pt))
            {
                foreach (var poly in feat.Locations)
                {
                    if (poly.PointInPolygon(pt))
                    {
                        // allocate to the first region it finds

                        var areaName        = feat.Parameters.Name;
                        var statisticalArea = long.Parse(feat.Parameters.Id);

                        return(true, new StatAreaLocation(statisticalArea, areaName));
                    }
                }
            }


            return(false, StatAreaLocation.Null());
        }
Beispiel #5
0
 public StatisticalAreaClassification(LatLong pt)
 {
     Location = pt;
 }
 public bool InBox(LatLong pt)
 {
     return(Xmin <= pt.Lon && pt.Lon <= Xmax &&
            Ymin <= pt.Lat && pt.Lat <= Ymax);
 }