示例#1
0
 public MapTileRepository([NotNull][ItemNotNull] List <OsmFeature> allFeatures)
 {
     _allFeatures           = allFeatures;
     BoundingBoxAllFeatures = BoundingBoxAllFeatures = MakeAllFeatureBoundingBox(_allFeatures);
     SplitIntoTiles();
 }
示例#2
0
        private void SplitIntoTiles()
        {
            _latdict  = new List <Tuple <double, int> >();
            _longdict = new List <Tuple <double, int> >();
            var latInterval = (BoundingBoxAllFeatures.RightLat - BoundingBoxAllFeatures.LeftLat) / (NumberOfBuckets - 1);

            if (latInterval < 0)
            {
                throw new Exception("Inverted box left right");
            }

            var lonInterval = (BoundingBoxAllFeatures.TopLon - BoundingBoxAllFeatures.BottomLon) / (NumberOfBuckets - 1);

            if (lonInterval < 0)
            {
                throw new Exception("Inverted box top bottom");
            }

            var    currLat  = BoundingBoxAllFeatures.LeftLat;
            var    fullList = new MapTile[NumberOfBuckets, NumberOfBuckets];
            double currLon;

            for (var latBucket = 0; latBucket < NumberOfBuckets; latBucket++)
            {
                _latdict.Add(new Tuple <double, int>(currLat, latBucket));
                currLon = BoundingBoxAllFeatures.BottomLon;
                for (var lonBucket = 0; lonBucket < NumberOfBuckets; lonBucket++)
                {
                    var r = new MapTile(currLat, currLon + lonInterval, currLon, currLat + latInterval);
                    fullList[latBucket, lonBucket] = r;
                    _allTiles.Add(r);
                    currLon += lonInterval;
                }

                currLat += latInterval;
            }

            currLon = BoundingBoxAllFeatures.BottomLon;
            for (var ybucket = 0; ybucket < NumberOfBuckets; ybucket++)
            {
                _longdict.Add(new Tuple <double, int>(currLon, ybucket));
                currLon += lonInterval;
            }

            // splitterTest
            //TestSplitting(allTiles);


            if (_longdict.Count != NumberOfBuckets)
            {
                throw new Exception("Logic error");
            }

            if (_latdict.Count != NumberOfBuckets)
            {
                throw new Exception("Logic error");
            }

            foreach (var feature in _allFeatures)
            {
                foreach (var point in feature.WgsPoints)
                {
                    if (!BoundingBoxAllFeatures.IsInside(point))
                    {
                        throw new Exception("Point is not in global bounding box");
                    }

                    var foundAtLeastOneTile = false;
                    foreach (var tile in _allTiles)
                    {
                        if (tile.IsInside(point))
                        {
                            foundAtLeastOneTile = true;
                            if (!tile.OsmFeaturesInRectangle.Contains(feature))
                            {
                                tile.OsmFeaturesInRectangle.Add(feature);
                            }
                        }
                    }

                    if (!foundAtLeastOneTile)
                    {
                        throw new Exception("No tile found");
                    }
                }
            }

            var totalAssignedFeatures = _allTiles.Select(x => x.OsmFeaturesInRectangle.Count).Sum();

            if (totalAssignedFeatures == 0)
            {
                throw new Exception("no features were assigned");
            }

            /* if(_allFeatures.Count != totalAssignedFeatures)
             * {
             *   throw new Exception("not all features assigned");
             * }*/
            _mapTileArray = fullList;
        }