private static bool TryGetTransformation(Coordinate c1, Coordinate c2, out ICoordinateTransformation transformation)
        {
            var result = false;

            transformation = null;

            int utmZone1 = GetUtmZone(c1.Longitude);
            int utmZone2 = GetUtmZone(c2.Longitude);

            bool isSouth1 = c1.Latitude < 0;
            bool isSouth2 = c2.Latitude < 0;

            result = (Math.Abs((utmZone1 - utmZone2))) < 2 && (isSouth1 == isSouth2);

            if (!result)
            {
                return(false);
            }

            var wgs = GeographicCoordinateSystem.WGS84;
            var utm = ProjectedCoordinateSystem.WGS84_UTM(utmZone1, !isSouth1);

            transformation = new CoordinateTransformationFactory().CreateFromCoordinateSystems(wgs, utm);

            return(result);
        }
        public Vector3 getOffsetFromLeader(MAVState leader, MAVState mav)
        {
            //convert Wgs84ConversionInfo to utm
            CoordinateTransformationFactory ctfac = new CoordinateTransformationFactory();

            IGeographicCoordinateSystem wgs84 = GeographicCoordinateSystem.WGS84;

            int utmzone = (int)((leader.cs.lng - -186.0) / 6.0);

            IProjectedCoordinateSystem utm = ProjectedCoordinateSystem.WGS84_UTM(utmzone,
                                                                                 leader.cs.lat < 0 ? false : true);

            ICoordinateTransformation trans = ctfac.CreateFromCoordinateSystems(wgs84, utm);

            double[] masterpll = { leader.cs.lng, leader.cs.lat };

            // get leader utm coords
            double[] masterutm = trans.MathTransform.Transform(masterpll);

            double[] mavpll = { mav.cs.lng, mav.cs.lat };

            //getLeader follower utm coords
            double[] mavutm = trans.MathTransform.Transform(mavpll);

            var heading = -leader.cs.yaw;

            var norotation = new Vector3(masterutm[1] - mavutm[1], masterutm[0] - mavutm[0], 0);

            norotation.x *= -1;
            norotation.y *= -1;

            return(new Vector3(norotation.x * Math.Cos(heading * MathHelper.deg2rad) - norotation.y * Math.Sin(heading * MathHelper.deg2rad), norotation.x * Math.Sin(heading * MathHelper.deg2rad) + norotation.y * Math.Cos(heading * MathHelper.deg2rad), 0));
        }
Пример #3
0
        public HIL.Vector3 getOffsetFromLeader(MAVLink leader, MAVLink mav)
        {
            //convert Wgs84ConversionInfo to utm
            CoordinateTransformationFactory ctfac = new CoordinateTransformationFactory();

            GeographicCoordinateSystem wgs84 = GeographicCoordinateSystem.WGS84;

            int utmzone = (int)((leader.MAV.cs.lng - -183.0) / 6.0);

            IProjectedCoordinateSystem utm = ProjectedCoordinateSystem.WGS84_UTM(utmzone, leader.MAV.cs.lat < 0 ? false : true);

            ICoordinateTransformation trans = ctfac.CreateFromCoordinateSystems(wgs84, utm);

            double[] masterpll = { leader.MAV.cs.lng, leader.MAV.cs.lat };

            // get leader utm coords
            double[] masterutm = trans.MathTransform.Transform(masterpll);

            double[] mavpll = { mav.MAV.cs.lng, mav.MAV.cs.lat };

            //getLeader follower utm coords
            double[] mavutm = trans.MathTransform.Transform(mavpll);

            return(new HIL.Vector3(masterutm[1] - mavutm[1], masterutm[0] - mavutm[0], 0));
        }
Пример #4
0
        /// <summary>
        /// Creates a coordinats transfomation from ITM to WGS84.
        /// </summary>
        /// <returns></returns>
        public static IMathTransform Create()
        {
            var coordinateTransformFactory = new CoordinateTransformationFactory();
            var coordinateSystemFactory    = new CoordinateSystemFactory();
            var itmParameters = new List <ProjectionParameter>
            {
                new ProjectionParameter("latitude_of_origin", 31.734393611111109123611111111111),
                new ProjectionParameter("central_meridian", 35.204516944444442572222222222222),
                new ProjectionParameter("false_northing", 626907.390),
                new ProjectionParameter("false_easting", 219529.584),
                new ProjectionParameter("scale_factor", 1.0000067)
            };

            var itmDatum = coordinateSystemFactory.CreateHorizontalDatum("Isreal 1993", DatumType.HD_Geocentric,
                                                                         Ellipsoid.GRS80, new Wgs84ConversionInfo(-24.0024, -17.1032, -17.8444, -0.33077, -1.85269, 1.66969, 5.4248));

            var itmGeo = coordinateSystemFactory.CreateGeographicCoordinateSystem("ITM", AngularUnit.Degrees, itmDatum,
                                                                                  PrimeMeridian.Greenwich, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North));

            var itmProjection = coordinateSystemFactory.CreateProjection("Transverse_Mercator", "Transverse_Mercator", itmParameters);
            var itm           = coordinateSystemFactory.CreateProjectedCoordinateSystem("ITM", itmGeo, itmProjection, LinearUnit.Metre,
                                                                                        new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North));

            var wgs84 = ProjectedCoordinateSystem.WGS84_UTM(36, true).GeographicCoordinateSystem;

            return(coordinateTransformFactory.CreateFromCoordinateSystems(itm, wgs84).MathTransform);
        }
Пример #5
0
        private void BtnCoord_Click(object sender, RoutedEventArgs e)
        {
            var ctfac  = new CoordinateTransformationFactory();
            var toCS   = GeographicCoordinateSystem.WGS84;
            var fromCS = ProjectedCoordinateSystem.WGS84_UTM(32, true);
            var trans  = ctfac.CreateFromCoordinateSystems(fromCS, toCS);

            double[] fromPoint = new double[] { 344354, 5676502 };
            double[] toPoint   = trans.MathTransform.Transform(fromPoint);

            var utmX = Convert.ToInt32(fromPoint[0]);
            var utmY = Convert.ToInt32(fromPoint[1]);

            var latDecimal = toPoint[1].ToString(new CultureInfo("en-US"));
            var lonDecimal = toPoint[0].ToString(new CultureInfo("en-US"));
            var url1       = $@"https://www.openstreetmap.de/karte.html?lat={latDecimal}&lon={lonDecimal}&zoom=17&layers=B000";
            var url2       = $@"https://maps.duesseldorf.de/stk/index.html?Zoom=6&UTM32={utmX},{utmY}";

            Log($"Coords: {toPoint[0]}, {toPoint[1]}");
            Log($"Url: {url2}");

            //webBrowser.Navigate(url2);

            Process.Start(url2);
        }
Пример #6
0
        public void TestMathTransformBug()
        {
            var coordinateTransformFactory = new CoordinateTransformationFactory();
            var coordinateSystemFactory    = new CoordinateSystemFactory();
            var itmParameters = new List <ProjectionParameter>
            {
                new ProjectionParameter("latitude_of_origin", 31.734393611111109123611111111111),
                new ProjectionParameter("central_meridian", 35.204516944444442572222222222222),
                new ProjectionParameter("false_northing", 626907.390),
                new ProjectionParameter("false_easting", 219529.584),
                new ProjectionParameter("scale_factor", 1.0000067)
            };

            var itmDatum = coordinateSystemFactory.CreateHorizontalDatum("Isreal 1993", DatumType.HD_Geocentric,
                                                                         Ellipsoid.GRS80, new Wgs84ConversionInfo(-24.0024, -17.1032, -17.8444, -0.33077, -1.85269, 1.66969, 5.4248));

            var itmGeo = coordinateSystemFactory.CreateGeographicCoordinateSystem("ITM", AngularUnit.Degrees, itmDatum,
                                                                                  PrimeMeridian.Greenwich, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North));

            var itmProjection = coordinateSystemFactory.CreateProjection("Transverse_Mercator", "Transverse_Mercator", itmParameters);
            var itm           = coordinateSystemFactory.CreateProjectedCoordinateSystem("ITM", itmGeo, itmProjection, LinearUnit.Metre,
                                                                                        new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North));

            var wgs84 = ProjectedCoordinateSystem.WGS84_UTM(36, true).GeographicCoordinateSystem;

            var ctFwd = _css.CreateTransformation(itm, wgs84).MathTransform;
            var pt1a  = (x : 200000.0, y : 600000.0);
            var pt2a  = ctFwd.Transform(pt1a.x, pt1a.y);
            var pt1b  = ctFwd.Inverse().Transform(pt2a.x, pt2a.y);
            var pt2b  = ctFwd.Transform(pt1a.x, pt1a.y);

            Assert.That(pt1a.x, Is.EqualTo(pt1b.x).Within(0.01));
            Assert.That(pt1a.y, Is.EqualTo(pt1b.y).Within(0.01));
            Assert.That(pt2a, Is.EqualTo(pt2b));
        }
Пример #7
0
        public void TestTransformListOfDoubleArray()
        {
            var csFact = new CoordinateSystemFactory();
            var ctFact = new CoordinateTransformationFactory();

            var utm35ETRS = csFact.CreateFromWkt(
                "PROJCS[\"ETRS89 / ETRS-TM35\",GEOGCS[\"ETRS89\",DATUM[\"D_ETRS_1989\",SPHEROID[\"GRS_1980\",6378137,298.257222101]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"latitude_of_origin\",0],PARAMETER[\"central_meridian\",27],PARAMETER[\"scale_factor\",0.9996],PARAMETER[\"false_easting\",500000],PARAMETER[\"false_northing\",0],UNIT[\"Meter\",1]]");

            var utm33 = ProjectedCoordinateSystem.WGS84_UTM(33, true);

            var trans = ctFact.CreateFromCoordinateSystems(utm35ETRS, utm33);

            var points = new List <double[]>
            {
                new[] { 290586.087, 6714000 }, new[] { 90586.392, 6713996.224 },
                new[] { 290590.133, 6713973.772 }, new[] { 290594.111, 6713957.416 },
                new[] { 290596.615, 6713943.567 }, new[] { 290596.701, 6713939.485 }
            };

            var tpoints = trans.MathTransform.TransformList(points).ToArray();

            for (var i = 0; i < points.Count; i++)
            {
                Assert.IsTrue(Equal(tpoints[i], trans.MathTransform.Transform(points[i])));
            }
        }
Пример #8
0
        public void TestTransformSequence()
        {
            var csFact = new CoordinateSystemFactory();
            var ctFact = new CoordinateTransformationFactory();

            var utm35ETRS = csFact.CreateFromWkt(
                "PROJCS[\"ETRS89 / ETRS-TM35\",GEOGCS[\"ETRS89\",DATUM[\"D_ETRS_1989\",SPHEROID[\"GRS_1980\",6378137,298.257222101]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"latitude_of_origin\",0],PARAMETER[\"central_meridian\",27],PARAMETER[\"scale_factor\",0.9996],PARAMETER[\"false_easting\",500000],PARAMETER[\"false_northing\",0],UNIT[\"Meter\",1]]");

            var utm33 = ProjectedCoordinateSystem.WGS84_UTM(33, true);

            var trans = ctFact.CreateFromCoordinateSystems(utm35ETRS, utm33);

            var points = new NetTopologySuite.Geometries.Implementation.CoordinateArraySequence(
                new []
            {
                new Coordinate(290586.087, 6714000), new Coordinate(290586.392, 6713996.224),
                new Coordinate(290590.133, 6713973.772), new Coordinate(290594.111, 6713957.416),
                new Coordinate(290596.615, 6713943.567), new Coordinate(290596.701, 6713939.485)
            });

            var tpoints = trans.MathTransform.Transform(points);

            for (var i = 0; i < points.Count; i++)
            {
                Assert.AreEqual(trans.MathTransform.Transform(points.GetCoordinate(i)), tpoints.GetCoordinate(i));
            }
        }
Пример #9
0
        public void MetersDistanceTaguaTest()
        {
            var brasiliaUtmZone        = 23;
            var originCoordinateSystem = GeographicCoordinateSystem.WGS84;
            var targetCoordinateSystem = ProjectedCoordinateSystem.WGS84_UTM(brasiliaUtmZone, false);

            var transform = new CoordinateTransformationFactory().CreateFromCoordinateSystems(
                originCoordinateSystem, targetCoordinateSystem);

            var catolica         = new GeoAPI.Geometries.Coordinate(-15.8674807, -48.0310518);
            var taguatingaCentro = new GeoAPI.Geometries.Coordinate(-15.8326894, -48.0547287);
            var taguaCenter      = new GeoAPI.Geometries.Coordinate(-15.8026851, -48.0685222);

            var catolicaCoordinate         = new GeoAPI.Geometries.Coordinate(catolica.X, catolica.Y);
            var taguatingaCentroCoordinate = new GeoAPI.Geometries.Coordinate(taguatingaCentro.X, taguatingaCentro.Y);
            var taguaCenterCoordinate      = new GeoAPI.Geometries.Coordinate(taguaCenter.X, taguaCenter.Y);

            var newcatolicaPoint         = transform.MathTransform.Transform(catolicaCoordinate);
            var newTaguatingaCentroPoint = transform.MathTransform.Transform(taguatingaCentroCoordinate);
            var newTaguaCenterPoint      = transform.MathTransform.Transform(taguaCenterCoordinate);

            var distanceTaguatingaCentro = newcatolicaPoint.Distance(newTaguatingaCentroPoint);
            var distanceTaguaCenter      = newcatolicaPoint.Distance(newTaguaCenterPoint);

            distanceTaguaCenter.ShouldBeGreaterThan(distanceTaguatingaCentro);

            //try in strait line, at least this works
        }
Пример #10
0
        public void MetersDistanceTest()
        {
            var brasiliaUtmZone        = 23;
            var originCoordinateSystem = GeographicCoordinateSystem.WGS84;
            var targetCoordinateSystem = ProjectedCoordinateSystem.WGS84_UTM(brasiliaUtmZone, false);

            var transform = new CoordinateTransformationFactory().CreateFromCoordinateSystems(
                originCoordinateSystem, targetCoordinateSystem);

            var southCampus = new GeoAPI.Geometries.Coordinate(-15.8136081, -47.8442208);
            var northCampus = new GeoAPI.Geometries.Coordinate(-15.7632746, -47.8779637);
            var epnbCampus  = new GeoAPI.Geometries.Coordinate(-15.87567632, -47.9929947);

            var southCoordinate = new GeoAPI.Geometries.Coordinate(southCampus.X, southCampus.Y);
            var northCoordinate = new GeoAPI.Geometries.Coordinate(northCampus.X, northCampus.Y);
            var epnbCoordinate  = new GeoAPI.Geometries.Coordinate(epnbCampus.X, epnbCampus.Y);

            var newSouthCampusPoint = transform.MathTransform.Transform(southCoordinate);
            var newNorthCampusPoint = transform.MathTransform.Transform(northCoordinate);
            var newEnpbCampusPoint  = transform.MathTransform.Transform(epnbCoordinate);

            var distanceSouthCampus = newEnpbCampusPoint.Distance(newSouthCampusPoint);
            var distanceNorthCampus = newEnpbCampusPoint.Distance(newNorthCampusPoint);

            distanceSouthCampus.ShouldBeGreaterThan(distanceNorthCampus);

            //result makes no sense for me, on google says other way
        }
Пример #11
0
        public ActionResult <IEnumerable <string> > Get()
        {
            try
            {
                CoordinateSystemFactory         csFact = new CoordinateSystemFactory();
                CoordinateTransformationFactory ctFact = new CoordinateTransformationFactory();

                ICoordinateSystem utm35ETRS = csFact.CreateFromWkt(
                    "PROJCS[\"ETRS89 / ETRS-TM35\",GEOGCS[\"ETRS89\",DATUM[\"D_ETRS_1989\",SPHEROID[\"GRS_1980\",6378137,298.257222101]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"latitude_of_origin\",0],PARAMETER[\"central_meridian\",27],PARAMETER[\"scale_factor\",0.9996],PARAMETER[\"false_easting\",500000],PARAMETER[\"false_northing\",0],UNIT[\"Meter\",1]]");

                IProjectedCoordinateSystem utm33 = ProjectedCoordinateSystem.WGS84_UTM(33, true);

                ICoordinateTransformation trans = ctFact.CreateFromCoordinateSystems(utm35ETRS, utm33);

                Coordinate[] points = new Coordinate[]
                {
                    new Coordinate(290586.087, 6714000), new Coordinate(290586.392, 6713996.224),
                    new Coordinate(290590.133, 6713973.772), new Coordinate(290594.111, 6713957.416),
                    new Coordinate(290596.615, 6713943.567), new Coordinate(290596.701, 6713939.485)
                };

                Coordinate[] tpoints = trans.MathTransform.TransformList(points).ToArray();
            }
            catch (Exception)
            {
                throw;
            }



            return(new string[] { "value1", "value2" });
        }
Пример #12
0
 public void TestConversion()
 {
     var point     = GeometryFactory.Default.CreatePoint(new Coordinate(492155.73, 6303867.82));
     var transform = new CoordinateTransformationFactory().CreateFromCoordinateSystems(
         ProjectedCoordinateSystem.WGS84_UTM(32, true), GeographicCoordinateSystem.WGS84);
     var transformedPoint = GeometryTransform.TransformGeometry(GeometryFactory.Default, point, transform.MathTransform);
 }
Пример #13
0
        public static void Main(string[] args)
        {
            var ctFact = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory();

            _trans = ctFact.CreateFromCoordinateSystems(ProjectedCoordinateSystem.WGS84_UTM(33, true), GeographicCoordinateSystem.WGS84);

            var naturområdeTyper           = ReadAll <NaturområdeType>("NaturområdeType");
            var beskrivelsesVariabler      = ReadAll <Beskrivelsesvariabel>("Beskrivelsesvariabel");
            var rødlistekategori           = ReadAll <Rødlistekategori>("Rødlistekategori");
            var kategoriSet                = ReadAll <KategoriSet>("KategoriSet");
            var rødlisteVurderingsenhetSet = ReadAll <RødlisteVurderingsenhetSet>("RødlisteVurderingsenhetSet");

            var geometries = ReadGeometries();

            var root = new root();

            var i = 0;

            Parallel.ForEach(geometries, naturområde =>
            {
                Interlocked.Increment(ref i);

                if (naturområdeTyper.All(n => n.Naturområde_id != naturområde.Id) &&
                    beskrivelsesVariabler.All(b => b.Naturområde_id != naturområde.Id))
                {
                    return;
                }

                try
                {
                    var flexible = GenerateFlexible(naturområde);

                    AddBeskrivelsesVariabler(beskrivelsesVariabler, flexible);

                    AddNaturområdeTyper(naturområdeTyper, flexible);

                    AddRødlistekategori(rødlisteVurderingsenhetSet, rødlistekategori, kategoriSet, flexible);

                    root.features.Add(flexible);
                }
                catch (Exception e)
                {
                    Console.Write("ERROR: Id " + naturområde.Id + ". " + e.Message);
                    Console.WriteLine();
                    return;
                }


                if (i % 100 == 0 && i != 0)
                {
                    Console.Write("\r{0}%   ", (int)(1.0 * i / geometries.Count * 100));
                }
            });

            var json = JsonConvert.SerializeObject(root);

            File.WriteAllText(@"c:\tmp\naturomrader9.json", json);
        }
Пример #14
0
        public UtmPosition TransformFromWGS(int pToZone)
        {
            var vDestinationUTM = ProjectedCoordinateSystem.WGS84_UTM(pToZone, true);
            CoordinateTransformationFactory vTransformerFactory = new CoordinateTransformationFactory();
            var vTransformer = vTransformerFactory.CreateFromCoordinateSystems(GeographicCoordinateSystem.WGS84, vDestinationUTM);

            double[] vTransformed = vTransformer.MathTransform.Transform(new double[] { this.Easting, this.Northing });
            return(new UtmPosition(pToZone, vTransformed[0], vTransformed[1]));
        }
Пример #15
0
        public UtmPosition TransformToWGS()
        {
            var vSourceUTM = ProjectedCoordinateSystem.WGS84_UTM(this.Zone, true);
            CoordinateTransformationFactory vTransformerFactory = new CoordinateTransformationFactory();
            var vTransformer = vTransformerFactory.CreateFromCoordinateSystems(vSourceUTM, GeographicCoordinateSystem.WGS84);

            double[] vTransformed = vTransformer.MathTransform.Transform(new double[] { this.Easting, this.Northing });
            return(new UtmPosition(0, vTransformed[0], vTransformed[1]));
        }
        public Wgs84UtmProjection(int zone, bool north)
        {
            if (zone < 1 || zone > 60)
            {
                throw new ArgumentException($"Invalid UTM zone {zone}.", nameof(zone));
            }

            CoordinateSystem = ProjectedCoordinateSystem.WGS84_UTM(zone, north);
        }
Пример #17
0
        private IMathTransform CreateTransformation(string utmZone)
        {
            bool isNorthHemisphere = utmZone[utmZone.Length - 1] >= 'N';
            var  zone = int.Parse(utmZone.Substring(0, utmZone.Length - 1));

            IProjectedCoordinateSystem pcsUTM = ProjectedCoordinateSystem.WGS84_UTM(zone, isNorthHemisphere);
            var transformation = this.coordinateTransformationFactory.CreateFromCoordinateSystems(this.gcsWGS84, pcsUTM);

            return(transformation.MathTransform);
        }
Пример #18
0
        public double[] ConvertToUTM(double lat, double lon)
        {
            CoordinateSystem wgs84 = GeographicCoordinateSystem.WGS84;
            CoordinateSystem utm33 = ProjectedCoordinateSystem.WGS84_UTM(33, true);
            var fact           = new CoordinateTransformationFactory();
            var transformation = fact.CreateFromCoordinateSystems(wgs84, utm33);

            double[] utm = transformation.MathTransform.Transform(new double[] { lon, lat });
            return(utm);
        }
Пример #19
0
        private double[] TransformToUTM(Coordinate p)
        {
            //For fun, let's use the SharpMap transformation library and display the position in UTM
            int zone   = (int)Math.Floor((p.X + 183) / 6.0);
            var proj   = ProjectedCoordinateSystem.WGS84_UTM(zone, (p.Y >= 0));
            var trans  = new CoordinateTransformationFactory().CreateFromCoordinateSystems(proj.GeographicCoordinateSystem, proj);
            var result = trans.MathTransform.Transform(new[] { p.X, p.Y });

            return(new[] { result[0], result[1], zone });
        }
Пример #20
0
        public static List <double[]> ToUTM(int utmzone, List <PointLatLngAlt> list)
        {
            IProjectedCoordinateSystem utm = ProjectedCoordinateSystem.WGS84_UTM(Math.Abs(utmzone), list[0].Lat < 0 ? false : true);

            ICoordinateTransformation trans = ctfac.CreateFromCoordinateSystems(wgs84, utm);

            List <double[]> data = new List <double[]>();

            list.ForEach(x => { data.Add((double[])x); });

            return(trans.MathTransform.TransformList(data));
        }
Пример #21
0
        // force a zone
        public double[] ToUTM(int utmzone)
        {
            IProjectedCoordinateSystem utm = ProjectedCoordinateSystem.WGS84_UTM(Math.Abs(utmzone), Lat < 0 ? false : true);

            ICoordinateTransformation trans = ctfac.CreateFromCoordinateSystems(wgs84, utm);

            double[] pll = { Lng, Lat };

            // get leader utm coords
            double[] utmxy = trans.MathTransform.Transform(pll);

            return(utmxy);
        }
Пример #22
0
        double calcpolygonarea(List <PointLatLng> polygon)
        {
            // should be a closed polygon
            // coords are in lat long
            // need utm to calc area

            if (polygon.Count == 0)
            {
                CustomMessageBox.Show("Please define a polygon!");
                return(0);
            }

            // close the polygon
            if (polygon[0] != polygon[polygon.Count - 1])
            {
                polygon.Add(polygon[0]); // make a full loop
            }
            CoordinateTransformationFactory ctfac = new CoordinateTransformationFactory();

            IGeographicCoordinateSystem wgs84 = GeographicCoordinateSystem.WGS84;

            int utmzone = (int)((polygon[0].Lng - -186.0) / 6.0);

            IProjectedCoordinateSystem utm = ProjectedCoordinateSystem.WGS84_UTM(utmzone, polygon[0].Lat < 0 ? false : true);

            ICoordinateTransformation trans = ctfac.CreateFromCoordinateSystems(wgs84, utm);

            double prod1 = 0;
            double prod2 = 0;

            for (int a = 0; a < (polygon.Count - 1); a++)
            {
                double[] pll1 = { polygon[a].Lng, polygon[a].Lat };
                double[] pll2 = { polygon[a + 1].Lng, polygon[a + 1].Lat };

                double[] p1 = trans.MathTransform.Transform(pll1);
                double[] p2 = trans.MathTransform.Transform(pll2);

                prod1 += p1[0] * p2[1];
                prod2 += p1[1] * p2[0];
            }

            double answer = (prod1 - prod2) / 2;

            if (polygon[0] == polygon[polygon.Count - 1])
            {
                polygon.RemoveAt(polygon.Count - 1); // unmake a full loop
            }
            return(Math.Abs(answer));
        }
Пример #23
0
        private static void ToLatLon(double utmX, double utmY, string utmZone, out double latitude, out double longitude)
        {
            ICoordinateSystem          gcs_WGS84  = GeographicCoordinateSystem.WGS84;
            IProjectedCoordinateSystem pcs_UTM31N = ProjectedCoordinateSystem.WGS84_UTM(23, false);

            CoordinateTransformationFactory ctfac = new CoordinateTransformationFactory();
            ICoordinateTransformation       trans = ctfac.CreateFromCoordinateSystems(pcs_UTM31N, gcs_WGS84);

            double[] fromPoint = new double[] { utmX, utmY };
            double[] toPoint   = trans.MathTransform.Transform(fromPoint);

            longitude = toPoint[0];
            latitude  = toPoint[1];
        }
Пример #24
0
        public void SetZone(int zoneNumber, bool north)
        {
            if (zoneNumber < 1 || zoneNumber > 61)
            {
                throw new ArgumentException("Invalid UTM zone number.");
            }

            var zoneName = zoneNumber.ToString() + (north ? "N" : "S");

            if (zone != zoneName)
            {
                zone = zoneName;
                CoordinateSystem = ProjectedCoordinateSystem.WGS84_UTM(zoneNumber, north);
            }
        }
Пример #25
0
    static GeoUtils()
    {
        _utmZone  = ConfigManager.ConfigFile.UtmZone;
        _utmNorth = ConfigManager.ConfigFile.IsUtmNorth;
        CoordinateTransformationFactory _ctf = new CoordinateTransformationFactory();

        _transformationFromWGS84ToUTM      = _ctf.CreateFromCoordinateSystems(GeographicCoordinateSystem.WGS84, ProjectedCoordinateSystem.WGS84_UTM(_utmZone, _utmNorth));
        _transformationFromWGS84ToMercator = _ctf.CreateFromCoordinateSystems(GeographicCoordinateSystem.WGS84, ProjectedCoordinateSystem.WebMercator);
        _transformationFromMercatorToWGS84 = _ctf.CreateFromCoordinateSystems(ProjectedCoordinateSystem.WebMercator, GeographicCoordinateSystem.WGS84);
        _transformationFromUTMToUGS84      = _ctf.CreateFromCoordinateSystems(ProjectedCoordinateSystem.WGS84_UTM(_utmZone, _utmNorth), GeographicCoordinateSystem.WGS84);
        _transformationFromUTMToMercator   = _ctf.CreateFromCoordinateSystems(ProjectedCoordinateSystem.WGS84_UTM(_utmZone, _utmNorth), ProjectedCoordinateSystem.WebMercator);
        _transformationFromMercatorToUTM   = _ctf.CreateFromCoordinateSystems(ProjectedCoordinateSystem.WebMercator, ProjectedCoordinateSystem.WGS84_UTM(_utmZone, _utmNorth));

        _utmOrigin = default(GeoPointUTM);
    }
Пример #26
0
        private static void ToUTM(double longitude, double latitude, out double x, out double y, out string zone)
        {
            ICoordinateSystem          gcs_WGS84  = GeographicCoordinateSystem.WGS84;
            IProjectedCoordinateSystem pcs_UTM31N = ProjectedCoordinateSystem.WGS84_UTM(23, false);

            CoordinateTransformationFactory ctfac = new CoordinateTransformationFactory();
            ICoordinateTransformation       trans = ctfac.CreateFromCoordinateSystems(gcs_WGS84, pcs_UTM31N);

            double[] fromPoint = new double[] { longitude, latitude };
            double[] toPoint   = trans.MathTransform.Transform(fromPoint);

            x    = toPoint[0];
            y    = toPoint[1];
            zone = "23S";
        }
Пример #27
0
        public void TestGitHubIssue53()
        {
            // arrange
            var csWgs84     = GeographicCoordinateSystem.WGS84;
            var csUtm35N    = ProjectedCoordinateSystem.WGS84_UTM(35, true);
            var csTrans     = CoordinateTransformationFactory.CreateFromCoordinateSystems(csWgs84, csUtm35N);
            var csTransBack = CoordinateTransformationFactory.CreateFromCoordinateSystems(csUtm35N, csWgs84);

            // act
            double[] point = { 42.5, 24.5 };
            double[] r     = csTrans.MathTransform.Transform(point);
            double[] rBack = csTransBack.MathTransform.Transform(r);

            // assert
            Assert.AreEqual(point[0], rBack[0], 1e-5);
            Assert.AreEqual(point[1], rBack[1], 1e-5);
        }
Пример #28
0
        public PointLatLngAlt ToLLA()
        {
            IProjectedCoordinateSystem utm = ProjectedCoordinateSystem.WGS84_UTM(Math.Abs(zone), zone < 0 ? false : true);

            ICoordinateTransformation trans = ctfac.CreateFromCoordinateSystems(wgs84, utm);

            // get leader utm coords
            double[] pll = trans.MathTransform.Inverse().Transform(this);

            PointLatLngAlt ans = new PointLatLngAlt(pll[1], pll[0]);

            if (this.Tag != null)
            {
                ans.Tag = this.Tag.ToString();
            }

            return(ans);
        }
Пример #29
0
        public void TestDiscussion361248_2()
        {
            var csSource = ProjectedCoordinateSystem.WGS84_UTM(18, true);

            var csTarget = CoordinateSystemFactory.CreateFromWkt(
                @"GEOGCS[""WGS 84"",
    DATUM[""WGS_1984"",
        SPHEROID[""WGS 84"",6378137,298.257223563,
            AUTHORITY[""EPSG"",""7030""]],
        AUTHORITY[""EPSG"",""6326""]],
    PRIMEM[""Greenwich"",0,
        AUTHORITY[""EPSG"",""8901""]],
    UNIT[""degree"",0.01745329251994328,
        AUTHORITY[""EPSG"",""9122""]],
    AUTHORITY[""EPSG"",""4326""]]");

            Test("WGS84_UTM(18,N) -> WGS84", csSource, csTarget, new[] { 307821.867, 4219306.387 }, new[] { -77.191769, 38.101147 }, 1e-6);
        }
Пример #30
0
        public static void TestGitHubIssue53()
        {
            // arrange
            CoordinateSystemFactory         csFact = new CoordinateSystemFactory();
            CoordinateTransformationFactory ctFact = new CoordinateTransformationFactory();
            ICoordinateSystem          csWgs84     = GeographicCoordinateSystem.WGS84;
            IProjectedCoordinateSystem csUtm35N    = ProjectedCoordinateSystem.WGS84_UTM(35, true);
            ICoordinateTransformation  csTrans     = ctFact.CreateFromCoordinateSystems(csWgs84, csUtm35N);
            ICoordinateTransformation  csTransBack = ctFact.CreateFromCoordinateSystems(csUtm35N, csWgs84);

            // act
            double[] point = new[] { 42.5, 24.5 };
            var      r     = csTrans.MathTransform.Transform(point);
            var      rBack = csTransBack.MathTransform.Transform(r);

            // assert
            Assert.AreEqual(point[0], rBack[0], 1e-5);
            Assert.AreEqual(point[1], rBack[1], 1e-5);
        }