Пример #1
0
        /// <summary>
        /// Extracts a tile of stops.
        /// </summary>
        public static Stop[] ExtractPointsForStops(this TransitDb transitDb, ulong tileId,
                                                   StopLayerConfig config)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }
            if (config.Name == null)
            {
                throw new ArgumentException("Layer configuration has no name set.");
            }

            if (transitDb.StopsCount == 0)
            {
                return(new Stop[0]);
            }

            var tile    = new Tile(tileId);
            var diffX   = (tile.Top - tile.Bottom);
            var diffY   = (tile.Right - tile.Left);
            var marginX = diffX / 1024;
            var marginY = diffY / 1024;

            var tileBox = new LocalGeo.Box(tile.Bottom - marginY, tile.Left - marginX,
                                           tile.Top + marginY, tile.Right + marginX);

            var stopsEnumerator = transitDb.GetStopsEnumerator();
            var stopIds         = stopsEnumerator.Search(
                tileBox.MinLat - diffY, tileBox.MinLon - diffX,
                tileBox.MaxLat + diffY, tileBox.MaxLon + diffX);

            var stops = new Stop[stopIds.Count];
            var i     = 0;

            foreach (var stopId in stopIds)
            {
                stopsEnumerator.MoveTo(stopId);

                if (config != null && config.IncludeStopsFunc != null &&
                    !config.IncludeStopsFunc(stopsEnumerator))
                { // explicitly excluded this stop.
                    continue;
                }

                stops[i] = new Stop()
                {
                    Latitude  = stopsEnumerator.Latitude,
                    Longitude = stopsEnumerator.Longitude,
                    MetaId    = stopsEnumerator.MetaId
                };

                i++;
            }
            return(stops);
        }
Пример #2
0
        /// <summary>
        /// Extracts a tile of stops.
        /// </summary>
        public static StopLayer ExtractPointLayerForStops(this TransitDb transitDb, ulong tileId,
                                                          StopLayerConfig config)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }
            if (config.Name == null)
            {
                throw new ArgumentException("Layer configuration has no name set.");
            }

            return(new StopLayer()
            {
                Meta = transitDb.StopAttributes,
                Name = config.Name,
                Points = transitDb.ExtractPointsForStops(tileId, config)
            });
        }
Пример #3
0
        /// <summary>
        /// Extracts a tile of stops.
        /// </summary>
        public static VectorTile ExtractTileForStops(this TransitDb transitDb, ulong tileId,
                                                     StopLayerConfig config)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }
            if (config.Name == null)
            {
                throw new ArgumentException("Layer configuration has no name set.");
            }

            var layers = new List <Layer>(1);

            layers.Add(transitDb.ExtractPointLayerForStops(tileId, config));

            return(new VectorTile()
            {
                Layers = layers,
                TileId = tileId
            });
        }