示例#1
0
        public bool CheckHitting(LocationPolygon poligon)
        {
            if (poligon == null || poligon.Count == 0)
            {
                return(false);
            }

            bool hit = false; // количество пересечений луча слева в право четное = false, нечетное = true;

            for (int i = 0; i < poligon.Count - 1; i++)
            {
                if (((poligon[i].Lat <= this.Lat) && ((poligon[i + 1].Lat > this.Lat))) || ((poligon[i].Lat > this.Lat) && ((poligon[i + 1].Lat <= this.Lat))))
                {
                    if ((poligon[i].Lon > this.Lon) && (poligon[i + 1].Lon > this.Lon))
                    {
                        hit = !hit;
                    }
                    else if (!((poligon[i].Lon < this.Lon) && (poligon[i + 1].Lon < this.Lon)))
                    {
                        if (this.Lon < poligon[i + 1].Lon - (this.Lat - poligon[i + 1].Lat) * (poligon[i + 1].Lon - poligon[i].Lon) / (poligon[i].Lat - poligon[i + 1].Lat))
                        {
                            hit = !hit;
                        }
                    }
                }
            }
            int i_ = poligon.Count - 1;

            if (((poligon[i_].Lat <= this.Lat) && ((poligon[0].Lat > this.Lat))) || ((poligon[i_].Lat > this.Lat) && ((poligon[0].Lat <= this.Lat))))
            {
                if ((poligon[i_].Lon > this.Lon) && (poligon[0].Lon > this.Lon))
                {
                    hit = !hit;
                }
                else if (!((poligon[i_].Lon < this.Lon) && (poligon[0].Lon < this.Lon)))
                {
                    if (this.Lon < poligon[0].Lon - (this.Lat - poligon[0].Lat) * (poligon[0].Lon - poligon[i_].Lon) / (poligon[i_].Lat - poligon[0].Lat))
                    {
                        hit = !hit;
                    }
                }
            }

            return(hit);
        }
示例#2
0
        private static List <DTO.Station> FindStations(DM.Tour tour)
        {
            var result = new List <DTO.Station>();

            var polygon = new MDC.LocationPolygon(tour.LocationList);

            if (polygon.Count <= 0)
            {
                throw new InvalidOperationException("Location list is empty");
            }
            var polygonRect = polygon.GetRect();

            using (var allStationsReader = Repository.ReadEntities <DM.AllStation>(source =>
            {
                source.SetAdditional($"([{MD.AllStations.Fields.Standart}] in ('{tour.RadioTechList.Replace(",", "','")}'))");
                source.SetWhere(MD.AllStations.Fields.Latitude, IMRecordset.Operation.Ge, polygonRect.Min.Lat);
                source.SetWhere(MD.AllStations.Fields.Latitude, IMRecordset.Operation.Le, polygonRect.Max.Lat);
                source.SetWhere(MD.AllStations.Fields.Longitude, IMRecordset.Operation.Ge, polygonRect.Min.Lon);
                source.SetWhere(MD.AllStations.Fields.Longitude, IMRecordset.Operation.Le, polygonRect.Max.Lon);
            }))
            {
                while (allStationsReader.Read())
                {
                    var allStation = allStationsReader.GetEntity();

                    var checkLocation = new MDC.Location(allStation.Longitude, allStation.Latitude);
                    if (checkLocation.CheckHitting(polygon))
                    {
                        var station = new DTO.Station
                        {
                            Id        = allStation.Id,
                            TableName = allStation.TableName,
                            TableId   = allStation.TableId,
                        };

                        if (CheckStationApplicationCurrentState(tour, station))
                        {
                            result.Add(station);
                        }
                    }
                }
            }

            return(result);
        }