/// <summary> /// Constructs a planar projection based upon an origin latitude and longitude /// </summary> /// <param name="latitude"></param> /// <param name="longitude"></param> /// <returns></returns> public static PlanarProjection PlanarProjection(GpsCoordinate origin, bool isDegrees) { if (isDegrees) { // transform LLACoord llaOrigin = DegreesToLLA(origin); // returns a new planar projection based on origin return(new PlanarProjection(llaOrigin.lat, llaOrigin.lon)); } // returns a new planar projection based on origin return(new PlanarProjection(origin.latitude, origin.longitude)); }
/// <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> /// Transforms a gps coordinate in degrees to an lla coordinate in radians /// </summary> /// <param name="gpsCoordinate"></param> /// <returns></returns> public static LLACoord DegreesToLLA(GpsCoordinate gpsCoordinate) { return(new LLACoord(gpsCoordinate.latitude * Math.PI / 180.0, gpsCoordinate.longitude * Math.PI / 180.0, 0)); }
/// <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> /// Transforms a gps coordinate in degrees to an lla coordinate in radians /// </summary> /// <param name="gpsCoordinate"></param> /// <returns></returns> public static LLACoord DegreesToLLA(GpsCoordinate gpsCoordinate) { return new LLACoord(gpsCoordinate.latitude * Math.PI / 180.0, gpsCoordinate.longitude * Math.PI / 180.0, 0); }
/// <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> /// Constructs a planar projection based upon an origin latitude and longitude /// </summary> /// <param name="latitude"></param> /// <param name="longitude"></param> /// <returns></returns> public static PlanarProjection PlanarProjection(GpsCoordinate origin, bool isDegrees) { if (isDegrees) { // transform LLACoord llaOrigin = DegreesToLLA(origin); // returns a new planar projection based on origin return new PlanarProjection(llaOrigin.lat, llaOrigin.lon); } // returns a new planar projection based on origin return new PlanarProjection(origin.latitude, origin.longitude); }
/// <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