public PointAnalysisTool(PlanarProjection projection, bool snap, ArbiterRoadNetwork arn, WorldTransform wt)
 {
     this.projection = projection;
     this.snapToWaypoints = snap;
     this.roadNetwork = arn;
     this.wt = wt;
 }
        /// <summary>
        /// Converts an xy rndf to a Rndf Network
        /// </summary>
        /// <param name="rndf"></param>
        /// <param name="projection"></param>
        /// <returns></returns>
        public static RndfNetwork ConvertXyRndfToRndfNetwork(IRndf rndf, PlanarProjection projection)
        {
            // create rndf network generator
            RndfNetworkGenerator networkGenerator = new RndfNetworkGenerator();

            // create the rndf network
            RndfNetwork rndfNetwork = networkGenerator.CreateRndfNetwork(rndf, projection);

            // return the rndf
            return rndfNetwork;
        }
        /// <summary>
        /// Opens an rndf file and transforms the points to xy around a central projection
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="rndf"></param>
        /// <param name="projection"></param>
        public static void GenerateXyRndfAndProjection(string fileName, out IRndf rndf, out PlanarProjection projection)
        {
            // generate the gps rndf
            IRndf gpsRndf = GenerateGpsRndf(fileName);

            // get the planar projection
            projection = GetProjection(gpsRndf);

            // create an xy rndf
            IRndf xyRndf = gpsRndf;

            #region Apply transform to all point

            // Get coordinates from segments
            foreach (SimpleSegment segment in xyRndf.Segments)
            {
                // Get coordinates from lanes
                List<SimpleLane> lanes = (List<SimpleLane>)segment.Lanes;
                foreach (SimpleLane lane in lanes)
                {
                    // Get coordinates from waypoints
                    List<SimpleWaypoint> waypoints = (List<SimpleWaypoint>)lane.Waypoints;
                    foreach (SimpleWaypoint waypoint in waypoints)
                    {
                        // Transform the gps coordinate into an xy xoordinate
                        GpsCoordinate position = new GpsCoordinate(waypoint.Position.X, waypoint.Position.Y);
                        Coordinates tmpXY = projection.ECEFtoXY(WGS84.LLAtoECEF(GpsTools.DegreesToLLA(position)));

                        // Add position to the coordinate list
                        waypoint.Position = tmpXY;
                    }
                }
            }

            foreach (SimpleZone zone in xyRndf.Zones)
            {
                // Get coordinates from perimeter
                ZonePerimeter perimeter = zone.Perimeter;
                List<PerimeterPoint> perimeterPoints = (List<PerimeterPoint>)perimeter.PerimeterPoints;
                foreach (PerimeterPoint perimeterPoint in perimeterPoints)
                {
                    // Transform the gps coordinate into an xy xoordinate
                    GpsCoordinate position = new GpsCoordinate(perimeterPoint.position.X, perimeterPoint.position.Y);
                    Coordinates tmpXY = projection.ECEFtoXY(WGS84.LLAtoECEF(GpsTools.DegreesToLLA(perimeterPoint.position)));

                    // Add position to the coordinate list
                    perimeterPoint.position = tmpXY;
                }

                // Get coordiantes from parking spots
                List<ParkingSpot> parkingSpots = (List<ParkingSpot>)zone.ParkingSpots;
                foreach (ParkingSpot parkingSpot in parkingSpots)
                {
                    // Transform the gps coordinate into an xy xoordinate
                    GpsCoordinate position = new GpsCoordinate(parkingSpot.Waypoint1.Position.X, parkingSpot.Waypoint1.Position.Y);
                    Coordinates tmpXY = projection.ECEFtoXY(WGS84.LLAtoECEF(GpsTools.DegreesToLLA(parkingSpot.Waypoint1.Position)));

                    // wp1 position set
                    parkingSpot.Waypoint1.Position = tmpXY;

                    // Transform the gps coordinate into an xy xoordinate
                    position = new GpsCoordinate(parkingSpot.Waypoint2.Position.X, parkingSpot.Waypoint2.Position.Y);
                    Coordinates tmpXY2 = projection.ECEFtoXY(WGS84.LLAtoECEF(GpsTools.DegreesToLLA(parkingSpot.Waypoint2.Position)));

                    // wp1 position set
                    parkingSpot.Waypoint2.Position = tmpXY2;
                }
            }

            # endregion

            // set the return xy rndf
            rndf = xyRndf;
        }
 /// <summary>
 /// Creates an rndf network from an xy rndf
 /// </summary>
 /// <returns></returns>
 public RndfNetwork CreateRndfNetwork(IRndf xyRndf, PlanarProjection projection)
 {
     return null;
 }
        /// <summary>
        /// LLA Coord in rad
        /// </summary>
        /// <param name="coordinate"></param>
        /// <param name="proj"></param>
        /// <returns></returns>
        public static LLACoord XyToLlaRadians(Coordinates coordinate, PlanarProjection proj)
        {
            // lla coord
            LLACoord llaRad = WGS84.ECEFtoLLA(proj.XYtoECEF(coordinate));

            // return
            return llaRad;
        }
        /// <summary>
        /// LLA coord in degrees
        /// </summary>
        /// <param name="coordiante"></param>
        /// <param name="proj"></param>
        /// <returns></returns>
        public static LLACoord XyToLlaDegrees(Coordinates coordiante, PlanarProjection proj)
        {
            // radians
            LLACoord llaRad = XyToLlaRadians(coordiante, proj);

            // degrees
            LLACoord lla = new LLACoord(llaRad.lat * 180.0 / Math.PI, llaRad.lon * 180.0 / Math.PI, 0);

            // return
            return lla;
        }
 /// <summary>
 /// Transoforms list of gps coordinates to xy coordinates
 /// </summary>
 /// <param name="gpsCoordinates"></param>
 /// <param name="projection"></param>
 /// <returns></returns>
 public static Coordinates TransformToXy(GpsCoordinate gpsCoordinate, PlanarProjection projection)
 {
     // generate xy coordinate from projection
     return projection.ECEFtoXY(WGS84.LLAtoECEF(new LLACoord(gpsCoordinate.latitude, gpsCoordinate.longitude, 0)));
 }
        /// <summary>
        /// Transoforms list of gps coordinates to xy coordinates
        /// </summary>
        /// <param name="gpsCoordinates"></param>
        /// <param name="projection"></param>
        /// <returns></returns>
        public static List<Coordinates> TransformToXy(List<GpsCoordinate> gpsCoordinates, PlanarProjection projection)
        {
            // final list of referenced coordinates
            List<Coordinates> xyCoordinates = new List<Coordinates>();

            // loop through coordinates
            foreach (GpsCoordinate gpsCooridnate in gpsCoordinates)
            {
                // generate xy coordinate from projection
                xyCoordinates.Add(projection.ECEFtoXY(WGS84.LLAtoECEF(new LLACoord(gpsCooridnate.latitude, gpsCooridnate.longitude, 0))));
            }

            // return final list
            return xyCoordinates;
        }
        /// <summary>
        /// Transforms a pose log into xy coordinates
        /// </summary>
        /// <param name="stream">filestream attached to the log</param>
        /// <param name="firstColumnTimeStamp">true if the first column of data contains a timestamp</param>
        /// <param name="ecef">if the data is in ecef format (usually true)</param>
        /// <param name="projection">projection we are using for the rest of the data</param>
        /// <returns></returns>
        public static List<Coordinates> TransformPoseLogToXy(FileStream dataStream, bool firstColumnTimeStamp, bool ecef, PlanarProjection projection)
        {
            // read in the line and split on the commas
            TextReader reader = new StreamReader(dataStream);

            // initialize list of final xy points
            List<Coordinates> xyCoordinates = new List<Coordinates>();

            // read data
            string line;
            while ((line = reader.ReadLine()) != null)
            {
                int offset = 0;
                if (firstColumnTimeStamp)
                    offset = 1;

                // split the line
                string[] parts = line.Split(',');
                double x = double.Parse(parts[0 + offset]);
                double y = double.Parse(parts[1 + offset]);
                double z = double.Parse(parts[2 + offset]);

                // perform the projection
                Coordinates xy = projection.ECEFtoXY(new Vector3(x, y, z));

                // add to final list of coordinates
                xyCoordinates.Add(xy);
            }

            // close reader
            reader.Dispose();
            reader.Close();

            // retrun list of coorinates
            return xyCoordinates;
        }
 public abstract void SetProjection(PlanarProjection proj);
        /// <summary>
        /// Saves the temp points to a file of degrees
        /// </summary>
        /// <param name="fileName"></param>
        public void SaveToFileAsDegrees(string fileName, PlanarProjection pp)
        {
            FileStream fs = new FileStream(fileName, FileMode.Create);
            StreamWriter sw = new StreamWriter(fs);

            foreach (KeyValuePair<string, Coordinates> c in this.Points)
            {
                LLACoord lla = GpsTools.XyToLlaDegrees(c.Value, pp);
                //LLACoord lla = new LLACoord(c.Value.X, c.Value.Y, 0);
                sw.WriteLine(c.Key + "\t" + lla.lat.ToString("F6") + "\t" + lla.lon.ToString("F6"));
            }

            sw.Close();
            fs.Dispose();
        }
        /// <summary>
        /// Reads in a file with arc mins to coords
        /// </summary>
        /// <param name="fileName"></param>
        public void ReadArcMinutesFromFile(string fileName, PlanarProjection pp)
        {
            Points = new Dictionary<string, Coordinates>();
            FileStream fs = new FileStream(fileName, FileMode.Open);
            StreamReader sr = new StreamReader(fs);

            while (!sr.EndOfStream)
            {
                string lineStream = sr.ReadLine();

                string[] del1 = new string[] {"\t"};
                string[] nwSplit = lineStream.Split(del1, StringSplitOptions.RemoveEmptyEntries);

                /*string name = nwSplit[0];

                string[] del2 = new string[] { " " };
                string[] n = nwSplit[1].Split(del2, StringSplitOptions.RemoveEmptyEntries);
                string[] w = nwSplit[2].Split(del2, StringSplitOptions.RemoveEmptyEntries);
                 */
                string name = nwSplit[0];
                double degN = double.Parse(nwSplit[1]);
                double degE = double.Parse(nwSplit[2]);
                Coordinates c = pp.ECEFtoXY(WGS84.LLAtoECEF((new LLACoord(degN * Math.PI / 180.0, degE * Math.PI / 180.0, 0.0))));
                Points.Add(name, c);
            }

            sr.Close();
            fs.Dispose();
        }