Creates coordinate transformations.
Inheritance: ICoordinateTransformationFactory
示例#1
1
        internal ActualCoordinateSystem(ICoordinateSystem coordinateSystem)
        {
            if (coordinateSystem == null)
                throw new ArgumentNullException("coordinateSystem"); //NOXLATE

            CoordinateTransformationFactory f = new CoordinateTransformationFactory();
            CoordinateSystemFactory cf = new CoordinateSystemFactory();

            m_transform = f.CreateFromCoordinateSystems(coordinateSystem, cf.CreateFromWkt(XY_M));
        }
        public void TestNAD27toWGS84()
        {
            CoordinateSystemFactory csFact = new CoordinateSystemFactory();
            CoordinateTransformationFactory ctFact = new CoordinateTransformationFactory();

            ICoordinateSystem ESPG32054 = csFact.CreateFromWkt(
                    "PROJCS[\"NAD27 / Wisconsin South\",GEOGCS[\"NAD27\",DATUM[\"North_American_Datum_1927\",SPHEROID[\"Clarke 1866\",6378206.4,294.9786982138982,AUTHORITY[\"EPSG\",\"7008\"]],AUTHORITY[\"EPSG\",\"6267\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4267\"]],PROJECTION[\"Lambert_Conformal_Conic_2SP\"],PARAMETER[\"standard_parallel_1\",42.73333333333333],PARAMETER[\"standard_parallel_2\",44.06666666666667],PARAMETER[\"latitude_of_origin\",42],PARAMETER[\"central_meridian\",-90],PARAMETER[\"false_easting\",2000000],PARAMETER[\"false_northing\",0],UNIT[\"US survey foot\",0.3048006096012192,AUTHORITY[\"EPSG\",\"9003\"]],AUTHORITY[\"EPSG\",\"32054\"]]");
            
            GeographicCoordinateSystem WGS84 = (ProjNet.CoordinateSystems.GeographicCoordinateSystem)GeographicCoordinateSystem.WGS84;

            ICoordinateTransformation trans = ctFact.CreateFromCoordinateSystems(ESPG32054, WGS84);

            List<double[]> points = new List<double[]>
            {
                new[] { 2555658.00, 388644.00},
                new[] { 2557740.000, 387024.000}
            };
            
            for (int i = 0; i < points.Count; i++)
            {
                double[] rst = trans.MathTransform.Transform(points[i]);
                Console.WriteLine(rst[0].ToString()+" \t"+ rst[1].ToString());
            }
        }
示例#3
0
 static ProjHelper()
 {
     CoordinateTransformationFactory factory = new CoordinateTransformationFactory();
     IGeographicCoordinateSystem wgs84 = GeographicCoordinateSystem.WGS84;
     IProjectedCoordinateSystem mercator = ProjectedCoordinateSystem.WebMercator;
     Transformation = factory.CreateFromCoordinateSystems(wgs84, mercator);
 }
        public void TestTransform()
        {
            CoordinateSystemFactory csFactory = new CoordinateSystemFactory();
            const string sourceCsWkt = "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\"]]";                                    
            ICoordinateSystem sourceCs = csFactory.CreateFromWkt(sourceCsWkt);
            Assert.That(sourceCs, Is.Not.Null);
            const string targetCsWkt = "PROJCS[\"WGS 84 / Australian Antarctic Lambert\",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\"]],PROJECTION[\"Lambert_Conformal_Conic_2SP\"],PARAMETER[\"standard_parallel_1\",-68.5],PARAMETER[\"standard_parallel_2\",-74.5],PARAMETER[\"latitude_of_origin\",-50],PARAMETER[\"central_meridian\",70],PARAMETER[\"false_easting\",6000000],PARAMETER[\"false_northing\",6000000],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AUTHORITY[\"EPSG\",\"3033\"]]";
            ICoordinateSystem targetCs = csFactory.CreateFromWkt(targetCsWkt);
            Assert.That(targetCs, Is.Not.Null);
            CoordinateTransformationFactory ctFactory = new CoordinateTransformationFactory();
            ICoordinateTransformation coordTransformation = ctFactory.CreateFromCoordinateSystems(sourceCs, targetCs);

            IGeometryFactory gf = GeometryFactory.Default;            
            const string geomWkt = "MULTIPOINT (152.83949210500001 -42.14413555,152.83910355899999 -42.129844618)";
            WKTReader reader = new WKTReader(gf);
            IGeometry geom = reader.Read(geomWkt);
            Assert.That(geom, Is.Not.Null);
            Assert.That(geom.IsValid, Is.True);
            Assert.That(geom, Is.InstanceOf<IMultiPoint>());

            IMultiPoint mp = (IMultiPoint)geom;
            foreach (IPoint pt in mp.Geometries)
            {
                IGeometry tp = GeometryTransform.TransformGeometry(gf, pt, coordTransformation.MathTransform);
                Assert.That(tp, Is.Not.Null);
                Assert.That(tp.IsValid, Is.True);
            }

            IGeometry transformed = GeometryTransform.TransformGeometry(gf, mp, coordTransformation.MathTransform);
            Assert.That(transformed, Is.Not.Null);
            Assert.That(transformed.IsValid, Is.True);
        }
示例#5
0
        private void EmbeddedMap_MouseMove(object sender, MouseEventArgs e)
        {
            if (image.IsMouseCaptured)
            {
                Debug.WriteLine("Capture Move");
                var tt = (TranslateTransform) ((TransformGroup) image.RenderTransform)
                                                  .Children.First(tr => tr is TranslateTransform);
                Vector v = start - e.GetPosition(border);
                tt.X = origin.X - v.X;
                tt.Y = origin.Y - v.Y;
            }
            else
            {
                Debug.WriteLine("Normal Move");
                Point p = e.GetPosition(image);
                double scale = 360/image.ActualWidth;
                Point pGeo = new Point(p.X*scale - 180, 90 - p.Y*scale);
                locationLong.Text = string.Format("{0}", pGeo.X);
                locationLat.Text = string.Format("{0}", pGeo.Y);

                //Transform to UTM
                CoordinateTransformationFactory ctfac = new CoordinateTransformationFactory();
                ICoordinateSystem wgs84geo = ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84;
                int zone = (int) Math.Ceiling((pGeo.X + 180)/6);
                //ICoordinateSystem utm = ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WGS84_UTM(zone, pGeo.Y > 0);
                //ICoordinateTransformation trans = ctfac.CreateFromCoordinateSystems(wgs84geo, utm);
                //Point pUtm = trans.MathTransform.Transform(pGeo);
                //locationX.Text = string.Format("N{0}", pUtm.Y);
                //locationY.Text = string.Format("E{0}", pUtm.X);
                locationZone.Text = string.Format("Zone {0}{1}", zone, pGeo.Y > 0 ? 'N' : 'S');
            }
        }
示例#6
0
        public static ICoordinateTransformation LatLonToGoogle()
        {
            CoordinateSystemFactory csFac = new CoordinateSystemFactory();
            CoordinateTransformationFactory ctFac = new CoordinateTransformationFactory();
            IGeographicCoordinateSystem sourceCs = csFac.CreateGeographicCoordinateSystem(
                "WGS 84",
                AngularUnit.Degrees,
                HorizontalDatum.WGS84,
                PrimeMeridian.Greenwich,
                new AxisInfo("north", AxisOrientationEnum.North),
                new AxisInfo("east", AxisOrientationEnum.East));

            List<ProjectionParameter> parameters = new List<ProjectionParameter>
                {
                    new ProjectionParameter("semi_major", 6378137.0),
                    new ProjectionParameter("semi_minor", 6378137.0),
                    new ProjectionParameter("latitude_of_origin", 0.0),
                    new ProjectionParameter("central_meridian", 0.0),
                    new ProjectionParameter("scale_factor", 1.0),
                    new ProjectionParameter("false_easting", 0.0),
                    new ProjectionParameter("false_northing", 0.0)
                };
            IProjection projection = csFac.CreateProjection("Google Mercator", "mercator_1sp", parameters);
            IProjectedCoordinateSystem targetCs = csFac.CreateProjectedCoordinateSystem(
                "Google Mercator",
                sourceCs,
                projection,
                LinearUnit.Metre,
                new AxisInfo("East", AxisOrientationEnum.East),
                new AxisInfo("North", AxisOrientationEnum.North));
            return ctFac.CreateFromCoordinateSystems(sourceCs, targetCs);
        }
        public HIL.Vector3 getOffsetFromLeader(MAVLinkInterface leader, MAVLinkInterface mav)
        {
            //convert Wgs84ConversionInfo to utm
            CoordinateTransformationFactory ctfac = new CoordinateTransformationFactory();

            GeographicCoordinateSystem wgs84 = GeographicCoordinateSystem.WGS84;

            int utmzone = (int)((leader.MAV.cs.lng - -186.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);
        }
 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);
 }
        public void TestAlbersProjectionFeet()
        {
            CoordinateSystemFactory cFac = new CoordinateSystemFactory();

            IEllipsoid ellipsoid = cFac.CreateFlattenedSphere("Clarke 1866", 6378206.4, 294.9786982138982, LinearUnit.USSurveyFoot);

            IHorizontalDatum datum = cFac.CreateHorizontalDatum("Clarke 1866", DatumType.HD_Geocentric, ellipsoid, null);
            IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem("Clarke 1866", AngularUnit.Degrees, datum,
                PrimeMeridian.Greenwich, new AxisInfo("Lon", AxisOrientationEnum.East),
                new AxisInfo("Lat", AxisOrientationEnum.North));
            List<ProjectionParameter> parameters = new List<ProjectionParameter>(5);
            parameters.Add(new ProjectionParameter("central_meridian", -96));
            parameters.Add(new ProjectionParameter("latitude_of_center", 23));
            parameters.Add(new ProjectionParameter("standard_parallel_1", 29.5));
            parameters.Add(new ProjectionParameter("standard_parallel_2", 45.5));
            parameters.Add(new ProjectionParameter("false_easting", 0));
            parameters.Add(new ProjectionParameter("false_northing", 0));
            IProjection projection = cFac.CreateProjection("Albers Conical Equal Area", "albers", parameters);

            IProjectedCoordinateSystem coordsys = cFac.CreateProjectedCoordinateSystem("Albers Conical Equal Area", gcs, projection, LinearUnit.Foot, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North));

            ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs, coordsys);

            double[] pGeo = new double[] { -75, 35 };
            double[] pUtm = trans.MathTransform.Transform(pGeo);
            double[] pGeo2 = trans.MathTransform.Inverse().Transform(pUtm);

            double[] expected = new double[] { 1885472.7 / LinearUnit.Foot.MetersPerUnit, 1535925 / LinearUnit.Foot.MetersPerUnit };
            Assert.IsTrue(ToleranceLessThan(pUtm, expected, 0.1), String.Format("Albers forward transformation outside tolerance, Expected [{0},{1}], got [{2},{3}]", expected[0], expected[1], pUtm[0], pUtm[1]));
            Assert.IsTrue(ToleranceLessThan(pGeo, pGeo2, 0.0000001), String.Format("Albers reverse transformation outside tolerance, Expected [{0},{1}], got [{2},{3}]", pGeo[0], pGeo[1], pGeo2[0], pGeo2[1]));
        }
        public void TestTransformListOfDoubleArray()
        {
            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);

            List<double[]> 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}
            };

            double[][] tpoints = trans.MathTransform.TransformList(points).ToArray();
            for (int i = 0; i < points.Count; i++)
            {
                Console.WriteLine(tpoints[i]);
                NUnit.Framework.Assert.IsTrue(Equal(tpoints[i], trans.MathTransform.Transform(points[i])));
            }
        }
示例#11
0
        private static ICoordinateTransformation GetCoordinateTransformation()
        {
            //The SRS for this datasource is EPSG:4326, therefore we need to transfrom it to OSM projection
            var ctf      = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory();
            var cf       = new ProjNet.CoordinateSystems.CoordinateSystemFactory();
            var epsg4326 = cf.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\"]]");
            var epsg3785 = cf.CreateFromWkt("PROJCS[\"Popular Visualisation CRS / Mercator\", GEOGCS[\"Popular Visualisation CRS\", DATUM[\"Popular Visualisation Datum\", SPHEROID[\"Popular Visualisation Sphere\", 6378137, 0, AUTHORITY[\"EPSG\",\"7059\"]], TOWGS84[0, 0, 0, 0, 0, 0, 0], AUTHORITY[\"EPSG\",\"6055\"]],PRIMEM[\"Greenwich\", 0, AUTHORITY[\"EPSG\", \"8901\"]], UNIT[\"degree\", 0.0174532925199433, AUTHORITY[\"EPSG\", \"9102\"]], AXIS[\"E\", EAST], AXIS[\"N\", NORTH], AUTHORITY[\"EPSG\",\"4055\"]], PROJECTION[\"Mercator\"], PARAMETER[\"False_Easting\", 0], PARAMETER[\"False_Northing\", 0], PARAMETER[\"Central_Meridian\", 0], PARAMETER[\"Latitude_of_origin\", 0], UNIT[\"metre\", 1, AUTHORITY[\"EPSG\", \"9001\"]], AXIS[\"East\", EAST], AXIS[\"North\", NORTH], AUTHORITY[\"EPSG\",\"3785\"]]");

            return(ctf.CreateFromCoordinateSystems(epsg4326, epsg3785));
示例#12
0
        public override void SendCommand()
        {
            if (masterpos.Lat == 0 || masterpos.Lng == 0)
                return;

            Console.WriteLine(DateTime.Now);
            Console.WriteLine("Leader {0} {1} {2}",masterpos.Lat,masterpos.Lng,masterpos.Alt);

            int a = 0;
            foreach (var port in MainV2.Comports)
            {
                if (port == Leader)
                    continue;

                PointLatLngAlt target = new PointLatLngAlt(masterpos);

                try
                {
                    //convert Wgs84ConversionInfo to utm
                    CoordinateTransformationFactory ctfac = new CoordinateTransformationFactory();

                    GeographicCoordinateSystem wgs84 = GeographicCoordinateSystem.WGS84;

                    int utmzone = (int)((masterpos.Lng - -186.0) / 6.0);

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

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

                    double[] pll1 = { target.Lng, target.Lat };

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

                    // add offsets to utm
                    p1[0] += ((HIL.Vector3)offsets[port]).x;
                    p1[1] += ((HIL.Vector3)offsets[port]).y;

                    // convert back to wgs84
                    IMathTransform inversedTransform = trans.MathTransform.Inverse();
                    double[] point = inversedTransform.Transform(p1);

                    target.Lat = point[1];
                    target.Lng = point[0];
                    target.Alt += ((HIL.Vector3)offsets[port]).z;

                    port.setGuidedModeWP(new Locationwp() { alt = (float)target.Alt, lat = target.Lat, lng = target.Lng, id = (byte)MAVLink.MAV_CMD.WAYPOINT });

                    Console.WriteLine("{0} {1} {2} {3}", port.ToString(), target.Lat, target.Lng, target.Alt);

                }
                catch (Exception ex) { Console.WriteLine("Failed to send command " + port.ToString() + "\n" + ex.ToString()); }

                a++;
            }


        }
示例#13
0
        public Projections()
        {
            CoordinateSystemFactory c = new CoordinateSystemFactory();
            ICoordinateSystem osgb = c.CreateFromWkt("PROJCS[\"OSGB 1936 / British National Grid\",GEOGCS[\"OSGB 1936\",DATUM[\"OSGB_1936\",SPHEROID[\"Airy 1830\",6377563.396,299.3249646,AUTHORITY[\"EPSG\",\"7001\"]],AUTHORITY[\"EPSG\",\"6277\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4277\"]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"latitude_of_origin\",49],PARAMETER[\"central_meridian\",-2],PARAMETER[\"scale_factor\",0.9996012717],PARAMETER[\"false_easting\",400000],PARAMETER[\"false_northing\",-100000],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AUTHORITY[\"EPSG\",\"27700\"]]");
            ICoordinateSystem wgs = c.CreateFromWkt("GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.0174532925199433]]");

            CoordinateTransformationFactory trf = new CoordinateTransformationFactory();
            this.OsgbToWgs = trf.CreateFromCoordinateSystems(osgb, wgs);
            this.WgsToOsgb = trf.CreateFromCoordinateSystems(wgs, osgb);
        }
示例#14
0
        public void WebMercatorCanBeTranformed(int srid)
        {
            var wkt = SharpMap.Converters.WellKnownText.SpatialReference.SridToWkt(srid);

            var csf = new CoordinateSystemFactory();
            var cs = csf.CreateFromWkt(wkt);
            
            var ctf = new CoordinateTransformationFactory();
            Assert.DoesNotThrow(() => ctf.CreateFromCoordinateSystems(cs, GeographicCoordinateSystem.WGS84),
                "Could not reproject SRID:" + srid);
        }
示例#15
0
    public void TestMethod1()
    {
      var UTMSystem = ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WGS84_UTM(32, true);
      ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84, UTMSystem);
      double[] p1 = trans.MathTransform.Transform(new double[] { 12.45693, 55.65322 });
      double utmy = p1[1];
      double utmx = p1[0];

      var t = DateTime.Now.Subtract(new DateTime(2012, 7, 1));


    }
 public override SpatialReference getGeographicSRS()
 {
     if (isGeographic())
     {
         return this;
     }
     else
     {
         ICoordinateTransformationFactory ctf = new CoordinateTransformationFactory ();
        // mt = ctf.
     }
     throw new NotImplementedException();
 }
示例#17
0
        //获取shp投影方式
        public ICoordinateTransformation getmapTransform(config.ProjPara proj)
        {
            CoordinateTransformationFactory ctFac = new CoordinateTransformationFactory();
            CoordinateSystemFactory cFac = new CoordinateSystemFactory();
            ICoordinateTransformation transform = null;

            //等经纬,shp数据原始投影
            var epsg4326 = cFac.CreateFromWkt("GEOGCS[\"GCS_WGS_1984\",DATUM[\"WGS_1984\",SPHEROID[\"WGS_84\",6378137.0,298.257223563]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]]");
            //目标坐标系
            var epsg3857 = cFac.CreateFromWkt(getSrcCoordinate(proj));
            transform = ctFac.CreateFromCoordinateSystems(epsg4326, epsg3857);

            return transform;
        }
        public static Coordinate ConvertDegreesToUTM(ICoordinate coordinate)
        {
            var ctfac = new CoordinateTransformationFactory();
            ProjNet.CoordinateSystems.ICoordinateSystem wgs84geo = ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84;
            int zone = (int)System.Math.Ceiling((coordinate.X + 180) / 6);
            ProjNet.CoordinateSystems.ICoordinateSystem utm = ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WGS84_UTM(zone, coordinate.Y > 0);
            var trans = ctfac.CreateFromCoordinateSystems(wgs84geo, utm);

            double[] pUtm = trans.MathTransform.Transform(new[] { coordinate.X, coordinate.Y });

            return new Coordinate
            {
                X = pUtm[0],
                Y = pUtm[1],
            };
        }
        private static ICoordinateTransformation Proj2Proj(IProjectedCoordinateSystem source, IProjectedCoordinateSystem target)
        {
            ConcatenatedTransform           ct    = new ConcatenatedTransform();
            CoordinateTransformationFactory ctFac = new CoordinateTransformationFactory();

            //First transform from projection to geographic
            ct.CoordinateTransformationList.Add(ctFac.CreateFromCoordinateSystems(source, source.GeographicCoordinateSystem));
            //Transform geographic to geographic:
            ct.CoordinateTransformationList.Add(ctFac.CreateFromCoordinateSystems(source.GeographicCoordinateSystem, target.GeographicCoordinateSystem));
            //Transform to new projection
            ct.CoordinateTransformationList.Add(ctFac.CreateFromCoordinateSystems(target.GeographicCoordinateSystem, target));

            return(new CoordinateTransformation(source,
                                                target, TransformType.Transformation, ct,
                                                String.Empty, String.Empty, -1, String.Empty, String.Empty));
        }
示例#20
0
        public SpatialReference(KinectReader kinectReader, PositionReader positionReader)
        {
            this.kinectReader = kinectReader;
            this.positionReader = positionReader;

            string wkt = "GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.0174532925199433]]";
            this.wgs84 = (ICoordinateSystem)ProjNet.Converters.WellKnownText.CoordinateSystemWktReader.Parse(wkt);

            //hardcoded UTM 55S - should parameterize
            string toWKT = "PROJCS[\"WGS 72BE / UTM zone 55S\",GEOGCS[\"WGS 72BE\",DATUM[\"WGS_1972_Transit_Broadcast_Ephemeris\",SPHEROID[\"WGS 72\",6378135,298.26,AUTHORITY[\"EPSG\",\"7043\"]],TOWGS84[0,0,1.9,0,0,0.814,-0.38],AUTHORITY[\"EPSG\",\"6324\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4324\"]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"latitude_of_origin\",0],PARAMETER[\"central_meridian\",147],PARAMETER[\"scale_factor\",0.9996],PARAMETER[\"false_easting\",500000],PARAMETER[\"false_northing\",10000000],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AUTHORITY[\"EPSG\",\"32555\"]]";

            this.toCs = (ICoordinateSystem)ProjNet.Converters.WellKnownText.CoordinateSystemWktReader.Parse(toWKT);

            CoordinateTransformationFactory ctfac = new CoordinateTransformationFactory();

            this.toGridtrans = ctfac.CreateFromCoordinateSystems(wgs84, toCs);
        }
 private static ICoordinateTransformation Proj2Geog(IProjectedCoordinateSystem source, IGeographicCoordinateSystem target)
 {
     if (source.GeographicCoordinateSystem.EqualParams(target))
     {
         IMathTransform mathTransform = CreateCoordinateOperation(source.Projection, source.GeographicCoordinateSystem.HorizontalDatum.Ellipsoid, source.LinearUnit).Inverse();
         return(new CoordinateTransformation(source, target, TransformType.Transformation, mathTransform,
                                             String.Empty, String.Empty, -1, String.Empty, String.Empty));
     }
     else
     {   // Geographic coordinatesystems differ - Create concatenated transform
         ConcatenatedTransform           ct    = new ConcatenatedTransform();
         CoordinateTransformationFactory ctFac = new CoordinateTransformationFactory();
         ct.CoordinateTransformationList.Add(ctFac.CreateFromCoordinateSystems(source, source.GeographicCoordinateSystem));
         ct.CoordinateTransformationList.Add(ctFac.CreateFromCoordinateSystems(source.GeographicCoordinateSystem, target));
         return(new CoordinateTransformation(source,
                                             target, TransformType.Transformation, ct,
                                             String.Empty, String.Empty, -1, String.Empty, String.Empty));
     }
 }
示例#22
0
    private void TestMercator_1SP()
    {
        CoordinateSystemFactory cFac = new CoordinateSystemFactory();

        IEllipsoid ellipsoid = cFac.CreateFlattenedSphere("Bessel 1840", 6377397.155, 299.15281, LinearUnit.Metre);

        IHorizontalDatum datum = cFac.CreateHorizontalDatum("Bessel 1840", DatumType.HD_Geocentric, ellipsoid, null);
        IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem("Bessel 1840", AngularUnit.Degrees,
                                                                                datum,
                                                                                PrimeMeridian.Greenwich,
                                                                                new AxisInfo("Lon",
                                                                                             AxisOrientationEnum.East),
                                                                                new AxisInfo("Lat",
                                                                                             AxisOrientationEnum.North));
        List<ProjectionParameter> parameters = new List<ProjectionParameter>();
        parameters.Add(new ProjectionParameter("latitude_of_origin", 0));
        parameters.Add(new ProjectionParameter("central_meridian", 110));
        parameters.Add(new ProjectionParameter("scale_factor", 0.997));
        parameters.Add(new ProjectionParameter("false_easting", 3900000));
        parameters.Add(new ProjectionParameter("false_northing", 900000));
        IProjection projection = cFac.CreateProjection("Mercator_1SP", "Mercator_1SP", parameters);

        IProjectedCoordinateSystem coordsys = cFac.CreateProjectedCoordinateSystem("Makassar / NEIEZ", gcs, projection,
                                                                                   LinearUnit.Metre,
                                                                                   new AxisInfo("East",
                                                                                                AxisOrientationEnum.East),
                                                                                   new AxisInfo("North",
                                                                                                AxisOrientationEnum.
                                                                                                    North));

        ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs,
                                                                                                            coordsys);

        var pGeo = new Coordinate(120, -3);
        var pUtm = Transform(trans.MathTransform, pGeo);
        trans.MathTransform.Invert();
        var pGeo2 = Transform(trans.MathTransform, pUtm);
        trans.MathTransform.Invert();

        result.Text += PrintResultTable(gcs, coordsys, pGeo, pUtm, new Coordinate(5009726.58, 569150.82), pGeo2,
                                        "Mercator_1SP test");
    }
        private static CoordinateTransformation Geog2Proj(GeographicCoordinateSystem source, ProjectedCoordinateSystem target)
        {
            if (source.EqualParams(target.GeographicCoordinateSystem))
            {
                var mathTransform = CreateCoordinateOperation(target.Projection,
                                                              target.GeographicCoordinateSystem.HorizontalDatum.Ellipsoid, target.LinearUnit);
                return(new CoordinateTransformation(source, target, TransformType.Transformation, mathTransform,
                                                    string.Empty, string.Empty, -1, string.Empty, string.Empty));
            }

            // Geographic coordinatesystems differ - Create concatenated transform
            var ct    = new ConcatenatedTransform();
            var ctFac = new CoordinateTransformationFactory();

            ct.CoordinateTransformationList.Add(ctFac.CreateFromCoordinateSystems(source, target.GeographicCoordinateSystem));
            ct.CoordinateTransformationList.Add(ctFac.CreateFromCoordinateSystems(target.GeographicCoordinateSystem, target));
            return(new CoordinateTransformation(source,
                                                target, TransformType.Transformation, ct,
                                                string.Empty, string.Empty, -1, string.Empty, string.Empty));
        }
        private static CoordinateTransformation Proj2Proj(ProjectedCoordinateSystem source, ProjectedCoordinateSystem target)
        {
            var ct    = new ConcatenatedTransform();
            var ctFac = new CoordinateTransformationFactory();

            //First transform from projection to geographic
            ct.CoordinateTransformationList.Add(ctFac.CreateFromCoordinateSystems(source, source.GeographicCoordinateSystem));
            //Transform geographic to geographic:
            var geogToGeog = ctFac.CreateFromCoordinateSystems(source.GeographicCoordinateSystem,
                                                               target.GeographicCoordinateSystem);

            if (geogToGeog != null)
            {
                ct.CoordinateTransformationList.Add(geogToGeog);
            }
            //Transform to new projection
            ct.CoordinateTransformationList.Add(ctFac.CreateFromCoordinateSystems(target.GeographicCoordinateSystem, target));

            return(new CoordinateTransformation(source,
                                                target, TransformType.Transformation, ct,
                                                string.Empty, string.Empty, -1, string.Empty, string.Empty));
        }
        public void TestTransformListOfCoordinates()
        {
            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();
            for (int i = 0; i < points.Length; i++)
                Assert.That(tpoints[i].Equals(trans.MathTransform.Transform(points[i])));
        }
        /// <summary>
        /// Creates transformation from source coordinate system to specified target system which is the fitted one
        /// </summary>
        /// <param name="source"></param>
        /// <param name="target"></param>
        /// <returns></returns>
        private static ICoordinateTransformation Any2Fitt(ICoordinateSystem source, IFittedCoordinateSystem target)
        {
            //Transform form base system of fitted to target coordinate system - use invered math transform
            IMathTransform invMt = CreateFittedTransform(target).Inverse();

            //case when source system is equal to base system of the fitted
            if (target.BaseCoordinateSystem.EqualParams(source))
            {
                //Transform form base system of fitted to target coordinate system
                return(CreateTransform(source, target, TransformType.Transformation, invMt));
            }

            ConcatenatedTransform ct = new ConcatenatedTransform();
            //First transform from source to base system of fitted
            CoordinateTransformationFactory ctFac = new CoordinateTransformationFactory();

            ct.CoordinateTransformationList.Add(ctFac.CreateFromCoordinateSystems(source, target.BaseCoordinateSystem));

            //Transform form base system of fitted to target coordinate system - use invered math transform
            ct.CoordinateTransformationList.Add(CreateTransform(target.BaseCoordinateSystem, target, TransformType.Transformation, invMt));

            return(CreateTransform(source, target, TransformType.Transformation, ct));
        }
示例#27
0
        static void Main(string[] args)
        {
            var wktWGS84 = "GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.0174532925199433]]";
            var wgs84 = CoordinateSystemWktReader.Parse(wktWGS84) as ICoordinateSystem;
            var wktMercator = "PROJCS[\"World_Mercator\",GEOGCS[\"GCS_WGS_1984\",DATUM[\"WGS_1984\",SPHEROID[\"WGS_1984\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]],PROJECTION[\"Mercator_1SP\"],PARAMETER[\"False_Easting\",0],PARAMETER[\"False_Northing\",0],PARAMETER[\"Central_Meridian\",0],PARAMETER[\"latitude_of_origin\",0],UNIT[\"Meter\",1]]";
            var mercator = CoordinateSystemWktReader.Parse(wktMercator) as ICoordinateSystem;

            var transFactory = new CoordinateTransformationFactory();
            var trans = transFactory.CreateFromCoordinateSystems(wgs84, mercator);

            var fromPoints = new List<double[]>();
            using (var sr = new StreamReader("32332.dat"))
            {
                while (!sr.EndOfStream)
                {
                    var val = sr.ReadLine().Split("".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                    if (val[0].Contains("nan") || val[1].Contains("nan"))
                    {
                        continue;
                    }

                    var x = double.Parse(val[0]);
                    var y = double.Parse(val[1]);
                    fromPoints.Add(new double[] { x, y });
                }
            }

            var toPoints = trans.MathTransform.TransformList(fromPoints);

            using (var sw = new StreamWriter("result.dat"))
            {
                foreach (var toPoint in toPoints)
                {
                    sw.WriteLine("{0} {1}", toPoint[0], toPoint[1]);
                }
            }
        }      
 /// <summary>
 /// 地理坐标转换为投影坐标
 /// </summary>
 /// <param name="source"></param>
 /// <param name="target"></param>
 /// <returns></returns>
 private static ICoordinateTransformation Geog2Proj(IGeographicCoordinateSystem source, IProjectedCoordinateSystem target)
 {
     //目标的地理坐标系和源的地理坐标系相同,则直接采用投影变换
     if (source.EqualParams(target.GeographicCoordinateSystem))
     {
         IMathTransform mathTransform = CreateCoordinateOperation(target.Projection, target.GeographicCoordinateSystem.HorizontalDatum.Ellipsoid, target.LinearUnit);
         return(new CoordinateTransformation(source, target, TransformType.Transformation, mathTransform,
                                             String.Empty, String.Empty, -1, String.Empty, String.Empty));
     }
     else
     {
         // 目标的地理坐标系和源的地理坐标系不相同,则采用一系列变换
         // Geographic coordinatesystems differ - Create concatenated transform
         ConcatenatedTransform           ct    = new ConcatenatedTransform();
         CoordinateTransformationFactory ctFac = new CoordinateTransformationFactory();
         //创建从源地理坐标系到目标地理坐标系的转换
         ct.CoordinateTransformationList.Add(ctFac.CreateFromCoordinateSystems(source, target.GeographicCoordinateSystem));
         //创建从目标地理坐标系到目标投影坐标系的转换
         ct.CoordinateTransformationList.Add(ctFac.CreateFromCoordinateSystems(target.GeographicCoordinateSystem, target));
         return(new CoordinateTransformation(source,
                                             target, TransformType.Transformation, ct,
                                             String.Empty, String.Empty, -1, String.Empty, String.Empty));
     }
 }
        /// <summary>
        /// Creates transformation from fitted coordinate system to the target one
        /// </summary>
        /// <param name="source"></param>
        /// <param name="target"></param>
        /// <returns></returns>
        private static ICoordinateTransformation Fitt2Any(IFittedCoordinateSystem source, ICoordinateSystem target)
        {
            //transform from fitted to base system of fitted (which is equal to target)
            IMathTransform mt = CreateFittedTransform(source);

            //case when target system is equal to base system of the fitted
            if (source.BaseCoordinateSystem.EqualParams(target))
            {
                //Transform form base system of fitted to target coordinate system
                return(CreateTransform(source, target, TransformType.Transformation, mt));
            }

            //Transform form base system of fitted to target coordinate system
            ConcatenatedTransform ct = new ConcatenatedTransform();

            ct.CoordinateTransformationList.Add(CreateTransform(source, source.BaseCoordinateSystem, TransformType.Transformation, mt));

            //Transform form base system of fitted to target coordinate system
            CoordinateTransformationFactory ctFac = new CoordinateTransformationFactory();

            ct.CoordinateTransformationList.Add(ctFac.CreateFromCoordinateSystems(source.BaseCoordinateSystem, target));

            return(CreateTransform(source, target, TransformType.Transformation, ct));
        }
示例#30
0
 /// <summary>
 /// Creates a transformation between two coordinate systems.
 /// </summary>
 /// <param name="factory">The coordinate transformation factory.</param>
 /// <param name="sourceCS">Source coordinate system.</param>
 /// <param name="targetCS">Target coordinate system.</param>
 /// <param name="gridFile">The grid file path.</param>
 /// <param name="inverse">Indicates whether to use the inverse grid transform.</param>
 /// <returns></returns>
 public static ICoordinateTransformation CreateFromCoordinateSystems(this CoordinateTransformationFactory factory,
                                                                     CoordinateSystem sourceCS, CoordinateSystem targetCS, string gridFile, bool inverse)
 {
     return(CreateFromCoordinateSystems(factory, sourceCS, targetCS, GridFile.Open(gridFile), inverse));
 }
示例#31
0
        private static Map InitializeMapOsmWithXls(float angle)
        {
            Map map = new Map();

            TileLayer tileLayer = new TileLayer(new OsmTileSource(), "TileLayer - OSM with XLS");
            map.Layers.Add(tileLayer);

            //Get data from excel
            var xlsPath = string.Format(XlsConnectionString, System.IO.Directory.GetCurrentDirectory(), "GeoData\\Cities.xls");
            var ds = new System.Data.DataSet("XLS");
            using (var cn = new System.Data.OleDb.OleDbConnection(xlsPath))
            {
                cn.Open();
                using (var da = new System.Data.OleDb.OleDbDataAdapter(new System.Data.OleDb.OleDbCommand("SELECT * FROM [Cities$]", cn)))
                    da.Fill(ds);
            }

#if !DotSpatialProjections

            //The SRS for this datasource is EPSG:4326, therefore we need to transfrom it to OSM projection
            var ctf = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory();
            var cf = new ProjNet.CoordinateSystems.CoordinateSystemFactory();
            var epsg4326 = cf.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\"]]");
            var epsg3785 = cf.CreateFromWkt("PROJCS[\"Popular Visualisation CRS / Mercator\", GEOGCS[\"Popular Visualisation CRS\", DATUM[\"Popular Visualisation Datum\", SPHEROID[\"Popular Visualisation Sphere\", 6378137, 0, AUTHORITY[\"EPSG\",\"7059\"]], TOWGS84[0, 0, 0, 0, 0, 0, 0], AUTHORITY[\"EPSG\",\"6055\"]],PRIMEM[\"Greenwich\", 0, AUTHORITY[\"EPSG\", \"8901\"]], UNIT[\"degree\", 0.0174532925199433, AUTHORITY[\"EPSG\", \"9102\"]], AXIS[\"E\", EAST], AXIS[\"N\", NORTH], AUTHORITY[\"EPSG\",\"4055\"]], PROJECTION[\"Mercator\"], PARAMETER[\"False_Easting\", 0], PARAMETER[\"False_Northing\", 0], PARAMETER[\"Central_Meridian\", 0], PARAMETER[\"Latitude_of_origin\", 0], UNIT[\"metre\", 1, AUTHORITY[\"EPSG\", \"9001\"]], AXIS[\"East\", EAST], AXIS[\"North\", NORTH], AUTHORITY[\"EPSG\",\"3785\"]]");
            var ct = ctf.CreateFromCoordinateSystems(epsg4326, epsg3785);
            foreach (System.Data.DataRow row in ds.Tables[0].Rows)
            {
                if (row["X"] == DBNull.Value || row["Y"] == DBNull.Value) continue;
                double[] coords = new double[] { Convert.ToDouble(row["X"]), Convert.ToDouble(row["Y"])};
                coords = ct.MathTransform.Transform(coords);
                row["X"] = coords[0];
                row["Y"] = coords[1];
            }

#else
            var epsg4326 = DotSpatial.Projections.KnownCoordinateSystems.Geographic.World.WGS1984;
            var epsg3785 = new DotSpatial.Projections.ProjectionInfo();
            epsg3785.ReadEsriString("PROJCS[\"Popular Visualisation CRS / Mercator\", GEOGCS[\"Popular Visualisation CRS\", DATUM[\"Popular Visualisation Datum\", SPHEROID[\"Popular Visualisation Sphere\", 6378137, 0, AUTHORITY[\"EPSG\",\"7059\"]], TOWGS84[0, 0, 0, 0, 0, 0, 0], AUTHORITY[\"EPSG\",\"6055\"]],PRIMEM[\"Greenwich\", 0, AUTHORITY[\"EPSG\", \"8901\"]], UNIT[\"degree\", 0.0174532925199433, AUTHORITY[\"EPSG\", \"9102\"]], AXIS[\"E\", EAST], AXIS[\"N\", NORTH], AUTHORITY[\"EPSG\",\"4055\"]], PROJECTION[\"Mercator\"], PARAMETER[\"False_Easting\", 0], PARAMETER[\"False_Northing\", 0], PARAMETER[\"Central_Meridian\", 0], PARAMETER[\"Latitude_of_origin\", 0], UNIT[\"metre\", 1, AUTHORITY[\"EPSG\", \"9001\"]], AXIS[\"East\", EAST], AXIS[\"North\", NORTH], AUTHORITY[\"EPSG\",\"3785\"]]");
            foreach (System.Data.DataRow row in ds.Tables[0].Rows)
            {
                if (row["X"] == DBNull.Value || row["Y"] == DBNull.Value) continue;
                double[] coords = new double[] { Convert.ToDouble(row["X"]), Convert.ToDouble(row["Y"])};
                DotSpatial.Projections.Reproject.ReprojectPoints(coords, null, epsg4326, epsg3785, 0, 1);
                row["X"] = coords[0];
                row["Y"] = coords[1];
            }

#endif
            //Add Rotation Column
            ds.Tables[0].Columns.Add("Rotation", typeof (float));
            foreach (System.Data.DataRow row in ds.Tables[0].Rows)
                row["Rotation"] = -angle;

            //Set up provider
            var xlsProvider = new SharpMap.Data.Providers.DataTablePoint(ds.Tables[0], "OID", "X", "Y");
            var xlsLayer = new SharpMap.Layers.VectorLayer("XLS", xlsProvider);
            xlsLayer.Style.Symbol = SharpMap.Styles.VectorStyle.DefaultSymbol;
            
            //Add layer to map
            map.Layers.Add(xlsLayer);
            var xlsLabelLayer = new SharpMap.Layers.LabelLayer("XLSLabel");
            xlsLabelLayer.DataSource = xlsProvider;
            xlsLabelLayer.LabelColumn = "Name";
            xlsLabelLayer.PriorityColumn = "Population";
            xlsLabelLayer.Style.CollisionBuffer = new System.Drawing.SizeF(2f, 2f);
            xlsLabelLayer.Style.CollisionDetection = true;
            xlsLabelLayer.LabelFilter = SharpMap.Rendering.LabelCollisionDetection.ThoroughCollisionDetection;
            map.Layers.Add(xlsLabelLayer);

            map.ZoomToBox(tileLayer.Envelope);

            return map;
        }
示例#32
0
        private static ICoordinateTransformation GetCoordinateTransformation()
        {

            //The SRS for this datasource is EPSG:4326, therefore we need to transfrom it to OSM projection
            var ctf = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory();
            var cf = new ProjNet.CoordinateSystems.CoordinateSystemFactory();
            var epsg4326 = cf.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\"]]");
            var epsg3785 = cf.CreateFromWkt("PROJCS[\"Popular Visualisation CRS / Mercator\", GEOGCS[\"Popular Visualisation CRS\", DATUM[\"Popular Visualisation Datum\", SPHEROID[\"Popular Visualisation Sphere\", 6378137, 0, AUTHORITY[\"EPSG\",\"7059\"]], TOWGS84[0, 0, 0, 0, 0, 0, 0], AUTHORITY[\"EPSG\",\"6055\"]],PRIMEM[\"Greenwich\", 0, AUTHORITY[\"EPSG\", \"8901\"]], UNIT[\"degree\", 0.0174532925199433, AUTHORITY[\"EPSG\", \"9102\"]], AXIS[\"E\", EAST], AXIS[\"N\", NORTH], AUTHORITY[\"EPSG\",\"4055\"]], PROJECTION[\"Mercator\"], PARAMETER[\"False_Easting\", 0], PARAMETER[\"False_Northing\", 0], PARAMETER[\"Central_Meridian\", 0], PARAMETER[\"Latitude_of_origin\", 0], UNIT[\"metre\", 1, AUTHORITY[\"EPSG\", \"9001\"]], AXIS[\"East\", EAST], AXIS[\"North\", NORTH], AUTHORITY[\"EPSG\",\"3785\"]]");
            return ctf.CreateFromCoordinateSystems(epsg4326, epsg3785);
示例#33
0
        // gets transform between raster's native projection and the map projection
        private void GetTransform(ICoordinateSystem mapProjection)
        {
            if (mapProjection == null || Projection == "")
            {
                Transform = null;
                return;
            }

            CoordinateSystemFactory cFac = new CoordinateSystemFactory();

            // get our two projections
            ICoordinateSystem srcCoord = cFac.CreateFromWkt(Projection);
            ICoordinateSystem tgtCoord = mapProjection;

            // raster and map are in same projection, no need to transform
            if (srcCoord.WKT == tgtCoord.WKT)
            {
                Transform = null;
                return;
            }

            // create transform
            Transform = new CoordinateTransformationFactory().CreateFromCoordinateSystems(srcCoord, tgtCoord);
        }
示例#34
0
 public void SetUTM(ProjectedCoordinateSystem UTMSystem)
 {
   ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84, UTMSystem);
   double[] p1 = trans.MathTransform.Transform(new double[] { Longitude, Latitude });
   Y = p1[1];
   X = p1[0];
 }
示例#35
0
 public void SetLatLong(ProjectedCoordinateSystem UTMSystem)
 {
   ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(UTMSystem, ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84);
   double[] p1 = trans.MathTransform.Transform(new double[] { X, Y });
   Latitude = p1[1];
   Longitude = p1[0];
 }
        //Este para que hace falta??
        public SpatialReference createSRSfromWKT(string wkt, IMathTransform transf)
        {
            ProjNet.CoordinateSystems.CoordinateSystemFactory csf = new ProjNet.CoordinateSystems.CoordinateSystemFactory();

            ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory ctf = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory();
            throw new NotImplementedException();
        }
        public SpatialReference createSRSfromWKT(string wkt, ICoordinateSystem source)
        {
            SpatialReference result = null;

            //SetUp coordinate transformation
            ProjNet.CoordinateSystems.CoordinateSystemFactory csf = new ProjNet.CoordinateSystems.CoordinateSystemFactory();
            cs = csf.CreateFromWkt(wkt);
            ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory ctf = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory();
            ctf.CreateFromCoordinateSystems(source, cs);
            ProjNet.CoordinateSystems.Transformations.ICoordinateTransformation ct = ctf.CreateFromCoordinateSystems(cs, source);
            //crear SharpMapSpatialReference usando el coordinateTranformation.
            throw new NotImplementedException();
        }
 public void TestTransformAllWKTs()
 {
     //GeographicCoordinateSystem.WGS84
     CoordinateTransformationFactory fact = new CoordinateTransformationFactory();
     CoordinateSystemFactory fac = new CoordinateSystemFactory();
     int parsecount = 0;
     StreamReader sr = File.OpenText(@"..\..\SRID.csv");
     string line = "";
     while (!sr.EndOfStream)
     {
         line = sr.ReadLine();
         int split = line.IndexOf(';');
         if (split > -1)
         {
             string srid = line.Substring(0, split);
             string wkt = line.Substring(split + 1);
             ICoordinateSystem cs = CoordinateSystemWktReader.Parse(wkt) as ICoordinateSystem;
             if (cs == null) continue; //We check this in another test.
             if (cs is IProjectedCoordinateSystem)
             {
                 switch ((cs as IProjectedCoordinateSystem).Projection.ClassName)
                 {
                     //Skip not supported projections
                     case "Oblique_Stereographic":
                     case "Transverse_Mercator_South_Orientated":
                     case "Hotine_Oblique_Mercator":
                     case "Lambert_Conformal_Conic_1SP":
                     case "Krovak":
                     case "Cassini_Soldner":
                     case "Lambert_Azimuthal_Equal_Area":
                     case "Tunisia_Mining_Grid":
                     case "New_Zealand_Map_Grid":
                     case "Polyconic":
                     case "Lambert_Conformal_Conic_2SP_Belgium":
                     case "Polar_Stereographic":
                         continue;
                     default: break;
                 }
             }
             try
             {
                 ICoordinateTransformation trans = fact.CreateFromCoordinateSystems(GeographicCoordinateSystem.WGS84, cs);
             }
             catch (Exception ex)
             {
                 if (cs is IProjectedCoordinateSystem)
                     Assert.Fail("Could not create transformation from:\r\n" + wkt + "\r\n" + ex.Message + "\r\nClass name:" + (cs as IProjectedCoordinateSystem).Projection.ClassName);
                 else
                     Assert.Fail("Could not create transformation from:\r\n" + wkt + "\r\n" + ex.Message);
             }
             parsecount++;
         }
     }
     sr.Close();
     Assert.AreEqual(parsecount, 2536, "Not all WKT was processed");
 }
示例#39
0
    private void TestMercator_2SP()
    {
        CoordinateSystemFactory cFac = new CoordinateSystemFactory();

        IEllipsoid ellipsoid = cFac.CreateFlattenedSphere("Krassowski 1940", 6378245.0, 298.3, LinearUnit.Metre);

        IHorizontalDatum datum = cFac.CreateHorizontalDatum("Krassowski 1940", DatumType.HD_Geocentric, ellipsoid, null);
        IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem("Krassowski 1940", AngularUnit.Degrees,
                                                                                datum,
                                                                                PrimeMeridian.Greenwich,
                                                                                new AxisInfo("Lon",
                                                                                             AxisOrientationEnum.East),
                                                                                new AxisInfo("Lat",
                                                                                             AxisOrientationEnum.North));
        List<ProjectionParameter> parameters = new List<ProjectionParameter>();
        parameters.Add(new ProjectionParameter("latitude_of_origin", 42));
        parameters.Add(new ProjectionParameter("central_meridian", 51));
        parameters.Add(new ProjectionParameter("false_easting", 0));
        parameters.Add(new ProjectionParameter("false_northing", 0));
        IProjection projection = cFac.CreateProjection("Mercator_2SP", "Mercator_2SP", parameters);

        IProjectedCoordinateSystem coordsys = cFac.CreateProjectedCoordinateSystem(
            "Pulkovo 1942 / Mercator Caspian Sea", gcs, projection, LinearUnit.Metre,
            new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North));

        ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs,
                                                                                                            coordsys);

        var pGeo = new Coordinate(53, 53);
        var pUtm = Transform(trans.MathTransform, pGeo);
        trans.MathTransform.Invert();
        var pGeo2 = Transform(trans.MathTransform, pUtm);
        trans.MathTransform.Invert();

        result.Text += PrintResultTable(gcs, coordsys, pGeo, pUtm, new Coordinate(165704.29, 5171848.07), pGeo2,
                                        "Mercator_2SP test");
    }
示例#40
0
    private void TestGeocentric()
    {
        CoordinateSystemFactory cFac = new CoordinateSystemFactory();

        IGeographicCoordinateSystem gcs = cFac.CreateGeographicCoordinateSystem("WGS84", AngularUnit.Degrees,
                                                                                HorizontalDatum.WGS84,
                                                                                PrimeMeridian.Greenwich,
                                                                                new AxisInfo("Lon",
                                                                                             AxisOrientationEnum.East),
                                                                                new AxisInfo("Lat",
                                                                                             AxisOrientationEnum.North));
        IGeocentricCoordinateSystem geoccs = cFac.CreateGeocentricCoordinateSystem("WGS84 geocentric",
                                                                                   gcs.HorizontalDatum, LinearUnit.Metre,
                                                                                   PrimeMeridian.Greenwich);

        ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(gcs, geoccs);

        var pGeo = new Coordinate(2.12955, 53.80939444, 73);
        var pGc = Transform(trans.MathTransform, pGeo);
        trans.MathTransform.Invert();
        var pGeo2 = Transform(trans.MathTransform, pGc);
        trans.MathTransform.Invert();

        result.Text += PrintResultTable(gcs, geoccs, pGeo, pGc, new Coordinate(3771793.97, 140253.34, 5124304.35), pGeo2,
                                        "Geocentric test");

        return;
    }
示例#41
0
        private static Map InitializeMapOsmWithXls(float angle)
        {
            Map map = new Map();

            TileLayer tileLayer = new TileLayer(new OsmTileSource(), "TileLayer - OSM with XLS");

            map.Layers.Add(tileLayer);

            //Get data from excel
            var xlsPath = string.Format(XlsConnectionString, System.IO.Directory.GetCurrentDirectory(), "GeoData\\Cities.xls");
            var ds      = new System.Data.DataSet("XLS");

            using (var cn = new System.Data.OleDb.OleDbConnection(xlsPath))
            {
                cn.Open();
                using (var da = new System.Data.OleDb.OleDbDataAdapter(new System.Data.OleDb.OleDbCommand("SELECT * FROM [Cities$]", cn)))
                    da.Fill(ds);
            }

#if !DotSpatialProjections
            //The SRS for this datasource is EPSG:4326, therefore we need to transfrom it to OSM projection
            var ctf      = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory();
            var cf       = new ProjNet.CoordinateSystems.CoordinateSystemFactory();
            var epsg4326 = cf.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\"]]");
            var epsg3785 = cf.CreateFromWkt("PROJCS[\"Popular Visualisation CRS / Mercator\", GEOGCS[\"Popular Visualisation CRS\", DATUM[\"Popular Visualisation Datum\", SPHEROID[\"Popular Visualisation Sphere\", 6378137, 0, AUTHORITY[\"EPSG\",\"7059\"]], TOWGS84[0, 0, 0, 0, 0, 0, 0], AUTHORITY[\"EPSG\",\"6055\"]],PRIMEM[\"Greenwich\", 0, AUTHORITY[\"EPSG\", \"8901\"]], UNIT[\"degree\", 0.0174532925199433, AUTHORITY[\"EPSG\", \"9102\"]], AXIS[\"E\", EAST], AXIS[\"N\", NORTH], AUTHORITY[\"EPSG\",\"4055\"]], PROJECTION[\"Mercator\"], PARAMETER[\"False_Easting\", 0], PARAMETER[\"False_Northing\", 0], PARAMETER[\"Central_Meridian\", 0], PARAMETER[\"Latitude_of_origin\", 0], UNIT[\"metre\", 1, AUTHORITY[\"EPSG\", \"9001\"]], AXIS[\"East\", EAST], AXIS[\"North\", NORTH], AUTHORITY[\"EPSG\",\"3785\"]]");
            var ct       = ctf.CreateFromCoordinateSystems(epsg4326, epsg3785);
            foreach (System.Data.DataRow row in ds.Tables[0].Rows)
            {
                if (row["X"] == DBNull.Value || row["Y"] == DBNull.Value)
                {
                    continue;
                }
                double[] coords = new double[] { Convert.ToDouble(row["X"]), Convert.ToDouble(row["Y"]) };
                coords   = ct.MathTransform.Transform(coords);
                row["X"] = coords[0];
                row["Y"] = coords[1];
            }
#else
            var epsg4326 = DotSpatial.Projections.KnownCoordinateSystems.Geographic.World.WGS1984;
            var epsg3785 = new DotSpatial.Projections.ProjectionInfo();
            epsg3785.ReadEsriString("PROJCS[\"Popular Visualisation CRS / Mercator\", GEOGCS[\"Popular Visualisation CRS\", DATUM[\"Popular Visualisation Datum\", SPHEROID[\"Popular Visualisation Sphere\", 6378137, 0, AUTHORITY[\"EPSG\",\"7059\"]], TOWGS84[0, 0, 0, 0, 0, 0, 0], AUTHORITY[\"EPSG\",\"6055\"]],PRIMEM[\"Greenwich\", 0, AUTHORITY[\"EPSG\", \"8901\"]], UNIT[\"degree\", 0.0174532925199433, AUTHORITY[\"EPSG\", \"9102\"]], AXIS[\"E\", EAST], AXIS[\"N\", NORTH], AUTHORITY[\"EPSG\",\"4055\"]], PROJECTION[\"Mercator\"], PARAMETER[\"False_Easting\", 0], PARAMETER[\"False_Northing\", 0], PARAMETER[\"Central_Meridian\", 0], PARAMETER[\"Latitude_of_origin\", 0], UNIT[\"metre\", 1, AUTHORITY[\"EPSG\", \"9001\"]], AXIS[\"East\", EAST], AXIS[\"North\", NORTH], AUTHORITY[\"EPSG\",\"3785\"]]");
            foreach (System.Data.DataRow row in ds.Tables[0].Rows)
            {
                if (row["X"] == DBNull.Value || row["Y"] == DBNull.Value)
                {
                    continue;
                }
                double[] coords = new double[] { Convert.ToDouble(row["X"]), Convert.ToDouble(row["Y"]) };
                DotSpatial.Projections.Reproject.ReprojectPoints(coords, null, epsg4326, epsg3785, 0, 1);
                row["X"] = coords[0];
                row["Y"] = coords[1];
            }
#endif
            //Add Rotation Column
            ds.Tables[0].Columns.Add("Rotation", typeof(float));
            foreach (System.Data.DataRow row in ds.Tables[0].Rows)
            {
                row["Rotation"] = -angle;
            }

            //Set up provider
            var xlsProvider = new SharpMap.Data.Providers.DataTablePoint(ds.Tables[0], "OID", "X", "Y");
            var xlsLayer    = new SharpMap.Layers.VectorLayer("XLS", xlsProvider);
            xlsLayer.Style.Symbol = SharpMap.Styles.VectorStyle.DefaultSymbol;

            //Add layer to map
            map.Layers.Add(xlsLayer);
            var xlsLabelLayer = new SharpMap.Layers.LabelLayer("XLSLabel");
            xlsLabelLayer.DataSource               = xlsProvider;
            xlsLabelLayer.LabelColumn              = "Name";
            xlsLabelLayer.PriorityColumn           = "Population";
            xlsLabelLayer.Style.CollisionBuffer    = new System.Drawing.SizeF(2f, 2f);
            xlsLabelLayer.Style.CollisionDetection = true;
            xlsLabelLayer.LabelFilter              = SharpMap.Rendering.LabelCollisionDetection.ThoroughCollisionDetection;
            map.Layers.Add(xlsLabelLayer);

            map.ZoomToBox(tileLayer.Envelope);

            return(map);
        }
示例#42
0
        double calcpolygonarea(List<PointLatLngAlt> 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();

            GeographicCoordinateSystem 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);
        }
        public SpatialReference createSRSfromWKT(string wkttarget, string wktsource)
        {
            ProjNet.CoordinateSystems.CoordinateSystemFactory csf      = new ProjNet.CoordinateSystems.CoordinateSystemFactory();
            ProjNet.CoordinateSystems.ICoordinateSystem       csSource = csf.CreateFromWkt(wktsource);
            ProjNet.CoordinateSystems.ICoordinateSystem       csTarget = csf.CreateFromWkt(wkttarget);
            ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory ctf = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory();
            ProjNet.CoordinateSystems.Transformations.ICoordinateTransformation       ct  = ctf.CreateFromCoordinateSystems(csSource, csTarget);
            SharpMapSpatialReference sr = new SharpMapSpatialReference();

            sr.CoordinateSystem = csSource;
            sr.MathTransform    = ct.MathTransform;
            return(sr);
        }