コード例 #1
0
        /*
         * Returns the closest point on the map based on the TConnection network created for carpooling rides
         */
        public List <TNodeCarpooling> ResolvePointTNode(Point P, float delta, int n = 1)
        {
            double distance;

            SortedDictionary <double, List <TNodeCarpooling> > Q = new SortedDictionary <double, List <TNodeCarpooling> >();

            Containers.RTree.Rectangle rect = new Containers.RTree.Rectangle((float)P.Longitude - delta / 2.0f, (float)P.Latitude - delta / 2.0f,
                                                                             (float)P.Longitude + delta / 2.0f, (float)P.Latitude + delta / 2.0f, 0, 0);

            List <RNode> Nodes = SpatialQuadTree.Contains(rect);

            foreach (KeyValuePair <long, TNodeCarpooling> TNC in TNodesCarpooling)
            {
                distance = TNC.Value.Point.DistanceFrom(P);
                if (distance < CarpoolParser.CARPOOLING_MAX_DISTANCE_PTCONNECTIONS)
                {
                    if (Q.ContainsKey(distance))
                    {
                        Q[distance].Add(TNC.Value);
                    }
                    else
                    {
                        Q.Add(distance, new List <TNodeCarpooling>());
                        Q[distance].Add(TNC.Value);
                    }
                }
            }

            return(Q.SelectMany(x => x.Value).Take(n).ToList());
        }
コード例 #2
0
        /*
         * Returns the closest point on the map
         */
        public List <RNode> ResolvePoint(Point P, float delta, int n = 1)
        {
            double distance;

            SortedDictionary <double, List <RNode> > Q = new SortedDictionary <double, List <RNode> >();

            Containers.RTree.Rectangle rect = new Containers.RTree.Rectangle((float)P.Longitude - delta / 2.0f, (float)P.Latitude - delta / 2.0f,
                                                                             (float)P.Longitude + delta / 2.0f, (float)P.Latitude + delta / 2.0f, 0, 0);

            List <RNode> Nodes = SpatialQuadTree.Contains(rect);

            foreach (RNode N in Nodes)
            {
                distance = N.Point.DistanceFrom(P);
                if (Q.ContainsKey(distance))
                {
                    Q[distance].Add(N);
                }
                else
                {
                    Q.Add(distance, new List <RNode>());
                    Q[distance].Add(N);
                }
            }

            return(Q.SelectMany(x => x.Value).Take(n).ToList());
        }
コード例 #3
0
        public RNode AddNode(long id, Point Coordinates)
        {
            RNode N = new RNode(id, Coordinates);

            GNodes.Add(id, N);
            RNodes.Add(id, N);
            //SpatialQuadTree.Insert(new QuadTreeNodeItem<RNode>(N, (float)N.Point.Longitude, (float)N.Point.Latitude));

            Containers.RTree.Rectangle rect = new Containers.RTree.Rectangle((float)Coordinates.Longitude, (float)Coordinates.Latitude,
                                                                             (float)Coordinates.Longitude + 0.001f, (float)Coordinates.Latitude + 0.001f, 0, 0);

            SpatialQuadTree.Add(rect, N);

            return(N);
        }
コード例 #4
0
        public void SetBoundaries(Point MinPoint, Point MaxPoint)
        {
            this.MinPoint = MinPoint;
            this.MaxPoint = MaxPoint;

            //this.SpatialQuadTree = new QuadTree<QuadTreeNodeItem<RNode>>(
            //    new System.Drawing.RectangleF(
            //            (float)MinPoint.Longitude, (float)MinPoint.Latitude,
            //            (float)(MaxPoint.Longitude - MinPoint.Longitude + 0.1f),
            //            (float)(MaxPoint.Latitude - MaxPoint.Latitude + 0.1f)
            //            )
            //        );

            this.SpatialQuadTree = new Containers.RTree.RTree <RNode>();
            Containers.RTree.Rectangle rect = new Containers.RTree.Rectangle((float)MinPoint.Longitude, (float)MinPoint.Latitude,
                                                                             (float)MaxPoint.Longitude, (float)MaxPoint.Latitude,
                                                                             0, 0);
        }