/* * UTMXYToLatLon * * Converts x and y coordinates in the Universal Transverse Mercator * projection to a latitude/longitude pair. * * Inputs: * x - The easting of the point, in meters. * y - The northing of the point, in meters. * zone - The UTM zone in which the point lies. * southhemi - True if the point is in the southern hemisphere; * false otherwise. * * Outputs: * latlon - A 2-element array containing the latitude and * longitude of the point, in degrees. */ public static GeoLocation UTMXYToLatLon(GeoLocationXY xy, bool southhemi) { if (xy.Zone < 1 || xy.Zone > 60) { throw new ArgumentOutOfRangeException(nameof(xy.Zone)); } var x = xy.X - 500000.0; x /= UTMScaleFactor; var y = xy.Y; /* If in southern hemisphere, adjust y accordingly. */ if (southhemi) { y -= 10000000; } y /= UTMScaleFactor; var cmeridian = UTMCentralMeridian(xy.Zone); var rad = MapXyToLatLon(x, y, cmeridian); return(new GeoLocation(RadToDeg(rad.Item1), RadToDeg(rad.Item2), xy.Elevation)); }
private double CalculateAngleDeg(GeoLocationXY p1, GeoLocationXY p2) { var dx = p2.X - p1.X; var dy = p2.Y - p1.Y; var arctg = Math.Atan(dx / dy); double angle; if (dx > 0 && dy > 0) { angle = arctg; } else if (dx > 0 && dy < 0) { angle = Math.PI + arctg; } else if (dx < 0 && dy > 0) { angle = arctg; } else { angle = Math.PI + arctg; } return(angle * 180.0 / Math.PI); }
public static bool IsInsidePolygon(this GeoLocationXY p, List <GeoLocationXY> poly) { // отсюда // https://stackoverflow.com/questions/4243042/c-sharp-point-in-polygon bool inside = false; if (poly.Count < 3) { throw new ArgumentException("poly.Count < 3", nameof(poly)); } var oldPoint = new Point( poly[poly.Count - 1].X, poly[poly.Count - 1].Y); for (int i = 0; i < poly.Count; i++) { var newPoint = new Point(poly[i].X, poly[i].Y); Point p2; Point p1; if (newPoint.X > oldPoint.X) { p1 = oldPoint; p2 = newPoint; } else { p1 = newPoint; p2 = oldPoint; } if ((newPoint.X < p.X) == (p.X <= oldPoint.X) && (p.Y - (long)p1.Y) * (p2.X - p1.X) < (p2.Y - (long)p1.Y) * (p.X - p1.X)) { inside = !inside; } oldPoint = newPoint; } return(inside); }