//Returns the distance between two points... public static double GetDistance(UtmCoordinate currentPosition, UtmCoordinate currentDestination) { double dEast, dNorth; //Check to see if within the same UTM zone if (currentPosition.Zone == currentDestination.Zone) { dEast = currentPosition.Easting - currentDestination.Easting; dNorth = currentPosition.Northing - currentDestination.Northing; return Math.Sqrt(dEast * dEast + dNorth * dNorth); } else { //Convert to UTM back to latitude and longitude LatLongCoordinate CurrentPositionLatLong = UtmToLL(RefEllipse, currentPosition); LatLongCoordinate DestinationPositionLatLong = UtmToLL(RefEllipse, currentDestination); //Work out distance double Distance = DistanceBetweenLatLongPoints(RefEllipse, CurrentPositionLatLong, DestinationPositionLatLong); //and return the result return Distance; } }
/// <summary> /// Returns the distance between two points... /// </summary> /// <param name="currentPosition"></param> /// <param name="currentDestination"></param> /// <returns></returns> public static double GetDistance(UtmCoordinate currentPosition, UtmCoordinate currentDestination) { double dEast, dNorth; //Check to see if within the same UTM zone if (currentPosition.Zone == currentDestination.Zone) { dEast = currentPosition.Easting - currentDestination.Easting; dNorth = currentPosition.Northing - currentDestination.Northing; return(Math.Sqrt(dEast * dEast + dNorth * dNorth)); } else { //Convert to UTM back to latitude and longitude LatLongCoordinate CurrentPositionLatLong = UtmToLL(RefEllipse, currentPosition); LatLongCoordinate DestinationPositionLatLong = UtmToLL(RefEllipse, currentDestination); //Work out distance double Distance = DistanceBetweenLatLongPoints(RefEllipse, CurrentPositionLatLong, DestinationPositionLatLong); //and return the result return(Distance); } }
public static int RefEllipse = 2; //Australia public static UtmCoordinate LocationFromRangeBearing(UtmCoordinate currentLocation, double range, double bearing) { //SohCahToa //Using the bearing from north, create a triangle and use geometry to work out new coordinates double BearingAsRadians = bearing * Math.PI / 180.0; double NorthDistance = range * Math.Cos(BearingAsRadians); double EastDistance = range * Math.Sin(BearingAsRadians); UtmCoordinate TargetLocation = new UtmCoordinate(); TargetLocation.Easting = currentLocation.Easting + EastDistance; TargetLocation.Northing = currentLocation.Northing + NorthDistance; TargetLocation.Zone = currentLocation.Zone; TargetLocation.ZoneIdentifier = currentLocation.ZoneIdentifier; return TargetLocation; }
public static UtmCoordinate LocationFromRangeBearing(UtmCoordinate currentLocation, double range, double bearing) { //SohCahToa //Using the bearing from north, create a triangle and use geometry to work out new coordinates double BearingAsRadians = bearing * Math.PI / 180.0; double NorthDistance = range * Math.Cos(BearingAsRadians); double EastDistance = range * Math.Sin(BearingAsRadians); UtmCoordinate TargetLocation = new UtmCoordinate(); TargetLocation.Easting = currentLocation.Easting + EastDistance; TargetLocation.Northing = currentLocation.Northing + NorthDistance; TargetLocation.Zone = currentLocation.Zone; TargetLocation.ZoneIdentifier = currentLocation.ZoneIdentifier; return(TargetLocation); }
public static LatLongCoordinate UtmToLL(int referenceEllipsoid, UtmCoordinate position) { return UtmToLL(referenceEllipsoid, position.Northing, position.Easting, position.Zone, position.ZoneIdentifier); }
public static System.Drawing.PointF LLToUtm(double latitude, double longitude, double eqRadius, double eccSquared, double scaleFactor) { //converts latitude/long to UTM coords. Equations from USGS Bulletin 1532 //East Longitudes are positive, West longitudes are negative. //North latitudes are positive, South latitudes are negative //latitude and longitude are in decimal degrees //Written by Chuck Gantz- [email protected] UtmCoordinate CoordinateSet = new UtmCoordinate(); double UTMEasting, UTMNorthing; double a = eqRadius; //double eccSquared = EllipseCollection[referenceEllipsoid].EccentricitySquared; double k0 = scaleFactor;// 0.9996; double LongOrigin; double eccPrimeSquared; double N, T, C, A, M; //Make sure the longitude is between -180.00 .. 179.9 double LongTemp = (longitude + 180) - (int)((longitude + 180) / 360) * 360 - 180; // -180.00 .. 179.9; double LatRad = latitude * (Math.PI / 180.0); double LongRad = LongTemp * (Math.PI / 180.0); double LongOriginRad; int ZoneNumber; ZoneNumber = (int)((LongTemp + 180) / 6) + 1; if (latitude >= 56.0 && latitude < 64.0 && LongTemp >= 3.0 && LongTemp < 12.0) ZoneNumber = 32; // Special zones for Svalbard if (latitude >= 72.0 && latitude < 84.0) { if (LongTemp >= 0.0 && LongTemp < 9.0) ZoneNumber = 31; else if (LongTemp >= 9.0 && LongTemp < 21.0) ZoneNumber = 33; else if (LongTemp >= 21.0 && LongTemp < 33.0) ZoneNumber = 35; else if (LongTemp >= 33.0 && LongTemp < 42.0) ZoneNumber = 37; } LongOrigin = (ZoneNumber - 1) * 6 - 180 + 3; //+3 puts origin in middle of zone LongOriginRad = LongOrigin * (Math.PI / 180.0); //compute the UTM Zone from the latitude and longitude //sprintf(zone, "%d%c", ZoneNumber, UTMLetterDesignator(latitude)); CoordinateSet.Zone = ZoneNumber; CoordinateSet.ZoneIdentifier = UTMLetterDesignator(latitude); eccPrimeSquared = (eccSquared) / (1 - eccSquared); N = a / Math.Sqrt(1 - eccSquared * Math.Sin(LatRad) * Math.Sin(LatRad)); T = Math.Tan(LatRad) * Math.Tan(LatRad); C = eccPrimeSquared * Math.Cos(LatRad) * Math.Cos(LatRad); A = Math.Cos(LatRad) * (LongRad - LongOriginRad); M = a * ((1 - eccSquared / 4 - 3 * eccSquared * eccSquared / 64 - 5 * eccSquared * eccSquared * eccSquared / 256) * LatRad - (3 * eccSquared / 8 + 3 * eccSquared * eccSquared / 32 + 45 * eccSquared * eccSquared * eccSquared / 1024) * Math.Sin(2 * LatRad) + (15 * eccSquared * eccSquared / 256 + 45 * eccSquared * eccSquared * eccSquared / 1024) * Math.Sin(4 * LatRad) - (35 * eccSquared * eccSquared * eccSquared / 3072) * Math.Sin(6 * LatRad)); UTMEasting = (double)(k0 * N * (A + (1 - T + C) * A * A * A / 6 + (5 - 18 * T + T * T + 72 * C - 58 * eccPrimeSquared) * A * A * A * A * A / 120) + 500000.0); UTMNorthing = (double)(k0 * (M + N * Math.Tan(LatRad) * (A * A / 2 + (5 - T + 9 * C + 4 * C * C) * A * A * A * A / 24 + (61 - 58 * T + T * T + 600 * C - 330 * eccPrimeSquared) * A * A * A * A * A * A / 720))); if (latitude < 0) UTMNorthing += 10000000.0; //10000000 meter offset for southern hemisphere //CoordinateSet.Easting = UTMEasting; //CoordinateSet.Northing = UTMNorthing; //return CoordinateSet; return new System.Drawing.PointF((float)UTMEasting, (float)UTMNorthing); }
public static LatLongCoordinate UtmToLL(int referenceEllipsoid, UtmCoordinate position) { return(UtmToLL(referenceEllipsoid, position.Northing, position.Easting, position.Zone, position.ZoneIdentifier)); }
public static System.Drawing.PointF LLToUtm(double latitude, double longitude, double eqRadius, double eccSquared, double scaleFactor) { //converts latitude/long to UTM coords. Equations from USGS Bulletin 1532 //East Longitudes are positive, West longitudes are negative. //North latitudes are positive, South latitudes are negative //latitude and longitude are in decimal degrees //Written by Chuck Gantz- [email protected] UtmCoordinate CoordinateSet = new UtmCoordinate(); double UTMEasting, UTMNorthing; double a = eqRadius; //double eccSquared = EllipseCollection[referenceEllipsoid].EccentricitySquared; double k0 = scaleFactor;// 0.9996; double LongOrigin; double eccPrimeSquared; double N, T, C, A, M; //Make sure the longitude is between -180.00 .. 179.9 double LongTemp = (longitude + 180) - (int)((longitude + 180) / 360) * 360 - 180; // -180.00 .. 179.9; double LatRad = latitude * (Math.PI / 180.0); double LongRad = LongTemp * (Math.PI / 180.0); double LongOriginRad; int ZoneNumber; ZoneNumber = (int)((LongTemp + 180) / 6) + 1; if (latitude >= 56.0 && latitude < 64.0 && LongTemp >= 3.0 && LongTemp < 12.0) { ZoneNumber = 32; } // Special zones for Svalbard if (latitude >= 72.0 && latitude < 84.0) { if (LongTemp >= 0.0 && LongTemp < 9.0) { ZoneNumber = 31; } else if (LongTemp >= 9.0 && LongTemp < 21.0) { ZoneNumber = 33; } else if (LongTemp >= 21.0 && LongTemp < 33.0) { ZoneNumber = 35; } else if (LongTemp >= 33.0 && LongTemp < 42.0) { ZoneNumber = 37; } } LongOrigin = (ZoneNumber - 1) * 6 - 180 + 3; //+3 puts origin in middle of zone LongOriginRad = LongOrigin * (Math.PI / 180.0); //compute the UTM Zone from the latitude and longitude //sprintf(zone, "%d%c", ZoneNumber, UTMLetterDesignator(latitude)); CoordinateSet.Zone = ZoneNumber; CoordinateSet.ZoneIdentifier = UTMLetterDesignator(latitude); eccPrimeSquared = (eccSquared) / (1 - eccSquared); N = a / Math.Sqrt(1 - eccSquared * Math.Sin(LatRad) * Math.Sin(LatRad)); T = Math.Tan(LatRad) * Math.Tan(LatRad); C = eccPrimeSquared * Math.Cos(LatRad) * Math.Cos(LatRad); A = Math.Cos(LatRad) * (LongRad - LongOriginRad); M = a * ((1 - eccSquared / 4 - 3 * eccSquared * eccSquared / 64 - 5 * eccSquared * eccSquared * eccSquared / 256) * LatRad - (3 * eccSquared / 8 + 3 * eccSquared * eccSquared / 32 + 45 * eccSquared * eccSquared * eccSquared / 1024) * Math.Sin(2 * LatRad) + (15 * eccSquared * eccSquared / 256 + 45 * eccSquared * eccSquared * eccSquared / 1024) * Math.Sin(4 * LatRad) - (35 * eccSquared * eccSquared * eccSquared / 3072) * Math.Sin(6 * LatRad)); UTMEasting = (double)(k0 * N * (A + (1 - T + C) * A * A * A / 6 + (5 - 18 * T + T * T + 72 * C - 58 * eccPrimeSquared) * A * A * A * A * A / 120) + 500000.0); UTMNorthing = (double)(k0 * (M + N * Math.Tan(LatRad) * (A * A / 2 + (5 - T + 9 * C + 4 * C * C) * A * A * A * A / 24 + (61 - 58 * T + T * T + 600 * C - 330 * eccPrimeSquared) * A * A * A * A * A * A / 720))); if (latitude < 0) { UTMNorthing += 10000000.0; //10000000 meter offset for southern hemisphere } //CoordinateSet.Easting = UTMEasting; //CoordinateSet.Northing = UTMNorthing; //return CoordinateSet; return(new System.Drawing.PointF((float)UTMEasting, (float)UTMNorthing)); }