示例#1
0
 private void AddDownloadedChunkToList(PolylineChunk chunk)
 {
     lock (downloadedChunks)
     {
         downloadedChunks.Add(chunk);
     }
 }
 private void AddChunkToProcessedList(PolylineChunk chunk)
 {
     lock (processedChunks)
     {
         processedChunks.Add(chunk);
     }
 }
        /// <summary>
        /// Получить словарь улиц из Geo Json
        /// </summary>
        /// <param name="geoJson">Geo Json</param>
        /// <returns>Словарь улиц</returns>
        public Dictionary <string, Road> GetRoadsDictionaryFromGeoJson(GeoJson geoJson)
        {
            Dictionary <string, Road> roads   = new Dictionary <string, Road>();
            GeographiData             geoData = GeographiData.Instance;
            List <Element>            ways    = new List <Element>();

            foreach (Element elem in geoJson.Elements)
            {
                if (elem.Type == "way" && !string.IsNullOrEmpty(elem.Tags.Name) && !geoData.Chunks.Keys.Contains(elem.Id))
                {
                    ways.Add(elem);
                }
                else if (elem.Type == "node" && !geoData.Locations.Keys.Contains(elem.Id))
                {
                    geoData.Locations.Add(elem.Id, new LocationEntity(elem));
                }
            }

            foreach (Element elem in ways)
            {
                PolylineChunk chunk = CreateChunk(elem);
                geoData.Chunks.Add(chunk.OverpassId, chunk);
                if (geoData.Roads.Keys.Contains(elem.Tags.Name))
                {
                    Road road = geoData.Roads[elem.Tags.Name];
                    AddElementToWay(road.PolylineChunks, chunk);
                    road.IsStreetViewsDownloaded = false;
                    if (!roads.Keys.Contains(road.Name))
                    {
                        roads.Add(road.Name, road);
                    }
                }
                else
                {
                    Road road = new Road(elem.Tags.Name);
                    AddElementToWay(road.PolylineChunks, chunk);
                    roads.Add(road.Name, road);
                    geoData.Roads.Add(road.Name, road);
                }
            }

            foreach (Road road in roads.Values)
            {
                int chunkCount = road.PolylineChunks.Count;
                for (int i = 0; i < chunkCount; i++)
                {
                    road.PolylineChunks[i].Order = i;
                }
            }
            return(roads);
        }
        // ==============================================================================================================
        // = Implementation
        // ==============================================================================================================

        private PolylineChunk CreateChunk(Element way)
        {
            GeographiData geoData = GeographiData.Instance;
            PolylineChunk chunk   = new PolylineChunk();

            chunk.OverpassId = way.Id;
            chunk.OrderedLocationEntities = new List <OrderedLocationEntity>();
            for (int i = 0; i < way.Nodes.Count(); i++)
            {
                LocationEntity location = geoData.Locations[way.Nodes[i]];
                chunk.OrderedLocationEntities.Add(new OrderedLocationEntity(i, location));
            }
            return(chunk);
        }
        private void DetectSignForChunkInversed(PolylineChunk chunk)
        {
            for (int i = 0; i < chunk.OrderedLocationEntities.Count - 1; i++)
            {
                LocationEntity start         = chunk.OrderedLocationEntities.Find(x => x.Order == i).LocationEntity;
                LocationEntity end           = chunk.OrderedLocationEntities.Find(x => x.Order == i + 1).LocationEntity;
                ImagePack      packToProcess = GetImagePack(end, start);

                if (packToProcess != null)
                {
                    DetectSignForImagePack(packToProcess);
                }
            }
            AddChunkToProcessedList(chunk);
        }
示例#6
0
        private void DownloadChunkStreetViews(PolylineChunk chunk)
        {
            List <LocationEntity> locations = new List <LocationEntity>();

            foreach (OrderedLocationEntity ordered in chunk.OrderedLocationEntities)
            {
                locations.Add(ordered.LocationEntity);
            }
            for (int j = 0; j < locations.Count - 1; j++)
            {
                DownloadImagePack(locations[j], locations[j + 1]);
                DownloadImagePack(locations[j + 1], locations[j]);
            }
            chunk.IsStreetViewsDownloaded = true;
            context.SaveChanges();
        }
        private void AddElementToWay(List <PolylineChunk> way, PolylineChunk partWay)
        {
            int prev = way.FindIndex(elem => elem.OrderedLocationEntities[elem.OrderedLocationEntities.Count - 1].LocationEntity.OverpassId == partWay.OrderedLocationEntities[0].LocationEntity.OverpassId);
            int next = way.FindIndex(elem => elem.OrderedLocationEntities[0].LocationEntity.OverpassId == partWay.OrderedLocationEntities[partWay.OrderedLocationEntities.Count - 1].LocationEntity.OverpassId);

            if (prev == -1 && next == -1)
            {
                way.Add(partWay);
            }
            else if (prev != -1 && next == -1)
            {
                way.Insert(prev + 1, partWay);
            }
            else if (prev == -1 && next != -1)
            {
                way.Insert(next, partWay);
            }
            else if (prev != -1 && next != -1)
            {
                if (prev < next)
                {
                    for (int i = way.Count - 1; i >= next; i--)
                    {
                        PolylineChunk chunk = way[way.Count - 1];
                        way.RemoveAt(way.Count - 1);
                        way.Insert(prev + 1, chunk);
                    }
                    way.Insert(prev + 1, partWay);
                }
                else if (prev > next)
                {
                    int index = prev;
                    while (index > 0 && way[index].OrderedLocationEntities[0].LocationEntity.OverpassId == way[index - 1].OrderedLocationEntities[way[index - 1].OrderedLocationEntities.Count - 1].LocationEntity.OverpassId)
                    {
                        index--;
                    }
                    for (int i = prev; i >= index; i--)
                    {
                        PolylineChunk elem = way[prev];
                        way.RemoveAt(prev);
                        way.Insert(next, elem);
                    }
                    way.Insert(next + 1, partWay);
                }
            }
        }
示例#8
0
        internal GMapRoute GetRouteForChunk(PolylineChunk chunk)
        {
            GMapRoute route = new GMapRoute(chunk.OverpassId.ToString());

            if ("MainRoute".Equals(routeType) && chunk.IsStreetViewsDownloaded)
            {
                route.Stroke = new Pen(color2, 2);
            }
            else if ("MiniRoute".Equals(routeType) && chunk.IsSignDetected)
            {
                route.Stroke = new Pen(color2, 2);
            }
            else
            {
                route.Stroke = new Pen(color1, 2);
            }
            route.Points.AddRange(GetListOfPoinLatLng(chunk.OrderedLocationEntities.OrderBy(i => i.Order).Select(x => x.LocationEntity).ToList()));
            return(route);
        }
        /// <summary>
        /// Получение участков пути из Geo Json
        /// </summary>
        /// <param name="geoJson">Geo Json</param>
        /// <returns>Список учасков пути</returns>
        public List <PolylineChunk> GetPolylineChunksFromGeoJson(GeoJson geoJson)
        {
            List <PolylineChunk>       resultChunks = new List <PolylineChunk>();
            Dictionary <long, Element> ways         = new Dictionary <long, Element>();
            Dictionary <long, Element> nodes        = new Dictionary <long, Element>();
            Dictionary <string, Road>  roads        = new Dictionary <string, Road>();

            foreach (Element elem in geoJson.Elements)
            {
                if (elem.Type == "way")
                {
                    ways.Add(elem.Id, elem);
                    if (!roads.ContainsKey(elem.Tags.Name))
                    {
                        roads.Add(elem.Tags.Name, new Road(elem.Tags.Name));
                    }
                }
                else if (elem.Type == "node")
                {
                    nodes.Add(elem.Id, elem);
                }
            }

            foreach (Element way in ways.Values)
            {
                PolylineChunk chunk = new PolylineChunk();
                chunk.OverpassId = way.Id;
                List <OrderedLocationEntity> chunkLocation = new List <OrderedLocationEntity>();
                for (int i = 0; i < way.Nodes.Count() - 1; i++)
                {
                    LocationEntity start = new LocationEntity(nodes[way.Nodes[i]].Lat, nodes[way.Nodes[i]].Lon);
                    chunkLocation.Add(new OrderedLocationEntity(i, start));
                    LocationEntity end = new LocationEntity(nodes[way.Nodes[i + 1]].Lat, nodes[way.Nodes[i + 1]].Lon);
                    //chunkLocation.AddRange(GetIntermediateLocations(start, end));
                    chunkLocation.Add(new OrderedLocationEntity(i + 1, start));
                }
                chunk.OrderedLocationEntities = chunkLocation;
                resultChunks.Add(chunk);
            }
            return(resultChunks);
        }
示例#10
0
        // ==============================================================================================================
        // = Implementation
        // ==============================================================================================================

        private void DownloadChunkStreetViews(PolylineChunk chunk, string path)
        {
            List <LocationEntity> listOfLocations = new List <LocationEntity>();

            foreach (OrderedLocationEntity ordered in chunk.OrderedLocationEntities)
            {
                listOfLocations.Add(ordered.LocationEntity);
            }
            for (int j = 0; j < listOfLocations.Count; j++)
            {
                double angle = 0;

                if (j < listOfLocations.Count - 1)
                {
                    angle = geoService.CalculateAngle(listOfLocations[j].Lat - listOfLocations[j + 1].Lat, listOfLocations[j].Lng - listOfLocations[j + 1].Lng);
                }
                else
                {
                    angle = geoService.CalculateAngle(listOfLocations[j - 1].Lat - listOfLocations[j].Lat, listOfLocations[j - 1].Lng - listOfLocations[j].Lng);
                }
                try
                {
                    Stream viewStream = restService.GetStreetViewStream(listOfLocations[j].Lat.ToString(), listOfLocations[j].Lng.ToString(), angle.ToString());
                    string filePath   = path + "\\" + j + ".jpeg";
                    using (var fileStream = File.Create(filePath))
                    {
                        viewStream.CopyTo(fileStream);
                    }
                    //listOfLocations[j].PathToStreetView = filePath;
                }
                catch (WebException ex)
                {
                    j--;
                }
            }
        }