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());
            }
        }
        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);
        }
        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);
        }
        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);
        }
Exemple #6
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 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])));
            }
        }
Exemple #8
0
 /// <summary>
 /// Gets a coordinate system from the SRID.csv file
 /// </summary>
 /// <param name="id">EPSG ID</param>
 /// <returns>Coordinate system, or null if SRID was not found.</returns>
 public static ICoordinateSystem GetCSbyID(int id)
 {
     ICoordinateSystemFactory factory = new CoordinateSystemFactory();
     foreach (var wkt in GetSrids(null))
         if (wkt.WktId == id)
             return factory.CreateFromWkt(wkt.Wkt);
     return null;
 }
        public void TestCentralMeridianParse()
        {
            const string strSouthPole = "PROJCS[\"South_Pole_Lambert_Azimuthal_Equal_Area\",GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]],PROJECTION[\"Lambert_Azimuthal_Equal_Area\"],PARAMETER[\"False_Easting\",0],PARAMETER[\"False_Northing\",0],PARAMETER[\"Central_Meridian\",-127],PARAMETER[\"Latitude_Of_Origin\",-90],UNIT[\"Meter\",1]]";

            CoordinateSystemFactory pCoordSysFactory = new CoordinateSystemFactory();
            ICoordinateSystem pSouthPole = pCoordSysFactory.CreateFromWkt(strSouthPole);
            NUnit.Framework.Assert.IsNotNull(pSouthPole);
        }
        public void ParseCoordSys()
        {
            string wkt = "PROJCS[\"NAD83(HARN) / Texas Central (ftUS)\", GEOGCS[\"NAD83(HARN)\", DATUM[\"NAD83_High_Accuracy_Regional_Network\", SPHEROID[\"GRS 1980\", 6378137, 298.257222101, AUTHORITY[\"EPSG\", \"7019\"]], TOWGS84[725, 685, 536, 0, 0, 0, 0], AUTHORITY[\"EPSG\", \"6152\"]], PRIMEM[\"Greenwich\", 0, AUTHORITY[\"EPSG\", \"8901\"]], UNIT[\"degree\", 0.0174532925199433, AUTHORITY[\"EPSG\", \"9122\"]], AUTHORITY[\"EPSG\", \"4152\"]], UNIT[\"US survey foot\", 0.304800609601219, AUTHORITY[\"EPSG\", \"9003\"]], PROJECTION[\"Lambert_Conformal_Conic_2SP\"], PARAMETER[\"standard_parallel_1\", 31.883333333333], PARAMETER[\"standard_parallel_2\", 30.1166666667], PARAMETER[\"latitude_of_origin\", 29.6666666667], PARAMETER[\"central_meridian\", -100.333333333333], PARAMETER[\"false_easting\", 2296583.333], PARAMETER[\"false_northing\", 9842500], AUTHORITY[\"EPSG\", \"2918\"]]";
            CoordinateSystemFactory fac = new CoordinateSystemFactory();
            ProjectedCoordinateSystem pcs = fac.CreateFromWkt(wkt) as ProjectedCoordinateSystem;
            Assert.IsNotNull(pcs, "Could not parse WKT: " + wkt);

            Assert.AreEqual("NAD83(HARN) / Texas Central (ftUS)", pcs.Name);
            Assert.AreEqual("NAD83(HARN)", pcs.GeographicCoordinateSystem.Name);
            Assert.AreEqual("NAD83_High_Accuracy_Regional_Network", pcs.GeographicCoordinateSystem.HorizontalDatum.Name);
            Assert.AreEqual("GRS 1980", pcs.GeographicCoordinateSystem.HorizontalDatum.Ellipsoid.Name);
            Assert.AreEqual(6378137, pcs.GeographicCoordinateSystem.HorizontalDatum.Ellipsoid.SemiMajorAxis);
            Assert.AreEqual(298.257222101, pcs.GeographicCoordinateSystem.HorizontalDatum.Ellipsoid.InverseFlattening);
            Assert.AreEqual("EPSG", pcs.GeographicCoordinateSystem.HorizontalDatum.Ellipsoid.Authority);
            Assert.AreEqual(7019, pcs.GeographicCoordinateSystem.HorizontalDatum.Ellipsoid.AuthorityCode);
            Assert.AreEqual("EPSG", pcs.GeographicCoordinateSystem.HorizontalDatum.Authority);
            Assert.AreEqual(6152, pcs.GeographicCoordinateSystem.HorizontalDatum.AuthorityCode);
            Assert.AreEqual(new Wgs84ConversionInfo(725, 685, 536, 0, 0, 0, 0), pcs.GeographicCoordinateSystem.HorizontalDatum.Wgs84Parameters);
            Assert.AreEqual("Greenwich", pcs.GeographicCoordinateSystem.PrimeMeridian.Name);
            Assert.AreEqual(0, pcs.GeographicCoordinateSystem.PrimeMeridian.Longitude);
            Assert.AreEqual("EPSG", pcs.GeographicCoordinateSystem.PrimeMeridian.Authority);
            Assert.AreEqual(8901, pcs.GeographicCoordinateSystem.PrimeMeridian.AuthorityCode, 8901);
            Assert.AreEqual("degree", pcs.GeographicCoordinateSystem.AngularUnit.Name);
            Assert.AreEqual(0.0174532925199433, pcs.GeographicCoordinateSystem.AngularUnit.RadiansPerUnit);
            Assert.AreEqual("EPSG", pcs.GeographicCoordinateSystem.AngularUnit.Authority);
            Assert.AreEqual(9122, pcs.GeographicCoordinateSystem.AngularUnit.AuthorityCode);
            Assert.AreEqual("EPSG", pcs.GeographicCoordinateSystem.Authority);
            Assert.AreEqual(4152, pcs.GeographicCoordinateSystem.AuthorityCode, 4152);
            Assert.AreEqual("Lambert_Conformal_Conic_2SP", pcs.Projection.ClassName, "Projection Classname");

            ProjectionParameter latitude_of_origin = pcs.Projection.GetParameter("latitude_of_origin");
            Assert.IsNotNull(latitude_of_origin);
            Assert.AreEqual(29.6666666667, latitude_of_origin.Value);
            ProjectionParameter central_meridian = pcs.Projection.GetParameter("central_meridian");
            Assert.IsNotNull(central_meridian);
            Assert.AreEqual(-100.333333333333, central_meridian.Value);
            ProjectionParameter standard_parallel_1 = pcs.Projection.GetParameter("standard_parallel_1");
            Assert.IsNotNull(standard_parallel_1);
            Assert.AreEqual(31.883333333333, standard_parallel_1.Value);
            ProjectionParameter standard_parallel_2 = pcs.Projection.GetParameter("standard_parallel_2");
            Assert.IsNotNull(standard_parallel_2);
            Assert.AreEqual(30.1166666667, standard_parallel_2.Value);
            ProjectionParameter false_easting = pcs.Projection.GetParameter("false_easting");
            Assert.IsNotNull(false_easting);
            Assert.AreEqual(2296583.333, false_easting.Value);
            ProjectionParameter false_northing = pcs.Projection.GetParameter("false_northing");
            Assert.IsNotNull(false_northing);
            Assert.AreEqual(9842500, false_northing.Value);

            Assert.AreEqual("US survey foot", pcs.LinearUnit.Name);
            Assert.AreEqual(0.304800609601219, pcs.LinearUnit.MetersPerUnit);
            Assert.AreEqual("EPSG", pcs.LinearUnit.Authority);
            Assert.AreEqual(9003, pcs.LinearUnit.AuthorityCode);
            Assert.AreEqual("EPSG", pcs.Authority);
            Assert.AreEqual(2918, pcs.AuthorityCode);
            Assert.AreEqual(wkt, pcs.WKT);
        }
        /**
         * Creates a new SRS from an ESRI-style WKT/PRJ string.
         *
         * @param wkt
         *      ESRI-style WKT (well-known text) SRS definition
         * @return
         *      A spatial reference. Caller is responsible for deleting
         *      the return object.
         */
        public SpatialReference createSRSfromESRI(string wkt)
        {
            SpatialReference result = null;

            //SetUp coordinate transformation
            ProjNet.CoordinateSystems.CoordinateSystemFactory csf = new ProjNet.CoordinateSystems.CoordinateSystemFactory();
            cs = csf.CreateFromWkt(wkt);
            throw new NotImplementedException();
        }
        private static void Initialize()
        {
            if (_fromCS == null)
            {
                string utmWkt = @"PROJCS[""ETRS89 / UTM zone 32N"",
    GEOGCS[""ETRS89"",
        DATUM[""European_Terrestrial_Reference_System_1989"",
            SPHEROID[""GRS 1980"",6378137,298.257222101,
                AUTHORITY[""EPSG"",""7019""]],
            AUTHORITY[""EPSG"",""6258""]],
        PRIMEM[""Greenwich"",0,
            AUTHORITY[""EPSG"",""8901""]],
        UNIT[""degree"",0.01745329251994328,
            AUTHORITY[""EPSG"",""9122""]],
        AUTHORITY[""EPSG"",""4258""]],
    UNIT[""metre"",1,
        AUTHORITY[""EPSG"",""9001""]],
    PROJECTION[""Transverse_Mercator""],
    PARAMETER[""latitude_of_origin"",0],
    PARAMETER[""central_meridian"",9],
    PARAMETER[""scale_factor"",0.9996],
    PARAMETER[""false_easting"",500000],
    PARAMETER[""false_northing"",0],
    AUTHORITY[""EPSG"",""25832""],
    AXIS[""Easting"",EAST],
    AXIS[""Northing"",NORTH]]";


                // WGS 84
                string wgsWkt = @"
                GEOGCS[""GCS_WGS_1984"",
                    DATUM[""D_WGS_1984"",SPHEROID[""WGS_1984"",6378137,298.257223563]],
                    PRIMEM[""Greenwich"",0],
                    UNIT[""Degree"",0.0174532925199433]
                ]";

                var cf = new ProjNet.CoordinateSystems.CoordinateSystemFactory();
                _fromCS = cf.CreateFromWkt(utmWkt);
                _toCS   = cf.CreateFromWkt(wgsWkt);

                _ctfac = new CoordinateTransformationFactory();
                _trans = _ctfac.CreateFromCoordinateSystems(_fromCS, _toCS);
            }
        }
        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);
        }
        public static void ConvertEPSG3857_to_SVY21(double lat, double lng, out double[] xy)
        {
            var gcs_WGS84      = GeographicCoordinateSystem.WGS84;
            var coordFactory   = new ProjNet.CoordinateSystems.CoordinateSystemFactory();
            var coordTransform = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory();
            var svy21          = coordFactory.CreateFromWkt(wkt_SVY21);

            var transformTo3857 = coordTransform.CreateFromCoordinateSystems(gcs_WGS84, svy21);

            double[] fromPoint = { lat, lng };
            xy = transformTo3857.MathTransform.Transform(fromPoint);
        }
        public static void ConvertSVY21_to_EPSG3857(double x, double y, out double[] lnglat)
        {
            var gcs_WGS84      = GeographicCoordinateSystem.WGS84;
            var coordFactory   = new ProjNet.CoordinateSystems.CoordinateSystemFactory();
            var coordTransform = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory();
            var svy21          = coordFactory.CreateFromWkt(wkt_SVY21);

            var transformTo3857 = coordTransform.CreateFromCoordinateSystems(svy21, gcs_WGS84);

            double[] fromPoint = { x, y };
            lnglat = transformTo3857.MathTransform.Transform(fromPoint);
        }
        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 static ProjNetCS.ICoordinateSystem Convert(ICoordinateSystem system)
        {
            if (system==null)
                return null;

            var cs=system as CoordinateSystem;
            if (cs==null)
            {
                var factory=new ProjNetCS.CoordinateSystemFactory();
                return factory.CreateFromWkt(system.ToString());
            }

            return cs.System;
        }
        /**
         * Creates a new SRS from an OSG WKT string.
         *
         * @param wkt
         *      OGC WKT (well-known text) SRS definition
         * @param reference_frame
         *      Reference frame to apply to points in this SRS
         * @return
         *      A spatial reference. Caller is responsible for deleting
         *      the return object.
         */
        public SpatialReference createSRSfromWKT(string wkt, Mogre.Matrix4 reference_frame)
        {
            //Implementar el MatrixTransform
            //rellenar el MatrixTransform usando el reference_frame
            //SetUp coordinate transformation
            ProjNet.CoordinateSystems.CoordinateSystemFactory csf      = new ProjNet.CoordinateSystems.CoordinateSystemFactory();
            ProjNet.CoordinateSystems.ICoordinateSystem       csSource = csf.CreateFromWkt(wkt);

            SharpMapSpatialReference sr = new SharpMapSpatialReference();

            sr.CoordinateSystem = csSource;
            sr.MathTransform    = new MatrixTransform(csSource.Dimension, reference_frame);
            return(sr);
        }
 private static bool TestParse(int srid, string srtext)
 {
     try
     {
         CoordinateSystemFactory factory = new CoordinateSystemFactory();
         factory.CreateFromWkt(srtext);
         //CoordinateSystemWktReader.Parse(srtext);
         return true;
     }
     catch (Exception ex)
     {
         Console.WriteLine("Test {0} failed:\n  {1}\n  {2}", srid, srtext, ex.Message);
         return false;
     }
 }
Exemple #20
0
        public static ProjNetCS.ICoordinateSystem Convert(ICoordinateSystem system)
        {
            if (system == null)
            {
                return(null);
            }

            var cs = system as CoordinateSystem;

            if (cs == null)
            {
                var factory = new ProjNetCS.CoordinateSystemFactory();
                return(factory.CreateFromWkt(system.ToString()));
            }

            return(cs.System);
        }
        private static ICoordinateSystem CreateCoordinateSystem(ISpatialReference spatialReference)
        {
            var pisr = spatialReference as ProjNetSpatialReference;
            if (pisr != null && pisr.CoordinateSystem != null)
                return pisr.CoordinateSystem;

            switch (spatialReference.DefinitionType)
            {
                case SpatialReferenceDefinitionType.WellKnownText:
                    var csFactory = new CoordinateSystemFactory();
                    return csFactory.CreateFromWkt(spatialReference.Definition);

                default:
                    throw new NotSupportedException();

            }
        }
        ICoordinateTransformation _ctFrom; //WGS84 to Custom

        public void LoadSourceWKT(string filepath)
        {
            //@"C:\DRC_Data\Arcview\USA\Townships\NYTOWNS_POLY.prj";

            ICoordinateSystemFactory csFac = new ProjNet.CoordinateSystems.CoordinateSystemFactory();
            string            file         = @"NYTOWNS_POLY.prj";
            string            wkt          = System.IO.File.ReadAllText(file);
            ICoordinateSystem csFrom       = csFac.CreateFromWkt(wkt);

            _ctFac = new CoordinateTransformationFactory();

            _ctTo = _ctFac.CreateFromCoordinateSystems(
                csFrom,
                GeographicCoordinateSystem.WGS84);

            _ctFrom = _ctFac.CreateFromCoordinateSystems(
                GeographicCoordinateSystem.WGS84,
                csFrom);
        }
        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])));
        }
 public void ParseAllWKTs()
 {
     CoordinateSystemFactory fac = new CoordinateSystemFactory();
     int parsecount = 0;
     foreach (SRIDReader.WktString wkt in SRIDReader.GetSrids())
     {
         ICoordinateSystem cs = fac.CreateFromWkt(wkt.Wkt);
         Assert.IsNotNull(cs, "Could not parse WKT: " + wkt);
         parsecount++;
     }
     Assert.AreEqual(parsecount, 2671, "Not all WKT was parsed");
 }
        // 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);
        }
        // get raster projection
        public ICoordinateSystem GetProjection()
        {
            var cFac = new CoordinateSystemFactory();

            try
            {
                if (Projection != "")
                    return cFac.CreateFromWkt(Projection);
            }
            catch (Exception)
            {
            }

            return null;
        }
 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();
 }
Exemple #28
0
        private static Map InitializeMapOsmWithXls(float angle)
        {
            Map map = new Map();

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

            //Get data from excel
            string xlsPath = string.Format(XlsConnectionString, Directory.GetCurrentDirectory(), "GeoData\\Cities.xls");
            DataSet ds = new DataSet("XLS");
            using (OleDbConnection cn = new OleDbConnection(xlsPath))
            {
                cn.Open();
                using (OleDbDataAdapter da = new OleDbDataAdapter(new 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
            CoordinateTransformationFactory ctf = new CoordinateTransformationFactory();
            CoordinateSystemFactory cf = new CoordinateSystemFactory();
            ICoordinateSystem 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\"]]");
            ICoordinateSystem epsg3857 = 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\",\"3857\"]]");
            ICoordinateTransformation ct = ctf.CreateFromCoordinateSystems(epsg4326, epsg3857);
            foreach (DataRow row in ds.Tables[0].Rows)
            {
                if (row["X"] == DBNull.Value || row["Y"] == DBNull.Value) continue;
                double[] coords = new[] { 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 epsg3857 = DotSpatial.Projections.ProjectionInfo.FromEsriString("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\",\"3857\"]]");
            foreach (System.Data.DataRow row in ds.Tables[0].Rows)
            {
                if (row["X"] == DBNull.Value || row["Y"] == DBNull.Value) continue;
                var coords = new[] { Convert.ToDouble(row["X"]), Convert.ToDouble(row["Y"])};
                DotSpatial.Projections.Reproject.ReprojectPoints(coords, null, epsg4326, epsg3857, 0, 1);
                row["X"] = coords[0];
                row["Y"] = coords[1];
            }

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

            //Set up provider
            DataTablePoint xlsProvider = new DataTablePoint(ds.Tables[0], "OID", "X", "Y");
            VectorLayer xlsLayer = new VectorLayer("XLS", xlsProvider)
                               {Style = {Symbol = VectorStyle.DefaultSymbol}};

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

            map.ZoomToBox(tileLayer.Envelope);

            return map;
        }
Exemple #29
0
        private static ICoordinateTransformation GetCoordinateTransformation()
        {

            //The SRS for this datasource is EPSG:4326, therefore we need to transfrom it to OSM projection
            CoordinateTransformationFactory ctf = new CoordinateTransformationFactory();
            CoordinateSystemFactory cf = new CoordinateSystemFactory();
            ICoordinateSystem 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\"]]");
            ICoordinateSystem epsg3857 = 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\",\"3857\"]]");
            return ctf.CreateFromCoordinateSystems(epsg4326, epsg3857);
 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 = fac.CreateFromWkt(wkt);
             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.GreaterOrEqual(parsecount, 2556, "Not all WKT was processed");
 }
        public void TestTransformOnFittedCoordinateSystem ()
        {

            //Local coordinate system MNAU (Kraftwerk Mäuserich) (based on Gau?Krüger using affine transformation)
            // affine transform
            // 1) Offset: X=-3454886,640m Y=-5479481,278m;
            // 2)Rotation: 332,0657, Rotation point  X=3456926,640m Y=5481071,278m;
            // 3) Scale: 1.0

            string ft_wkt = "FITTED_CS[\"Local coordinate system MNAU (based on Gauss-Krueger)\"," +
                                "PARAM_MT[\"Affine\"," +
                                   "PARAMETER[\"num_row\",3],PARAMETER[\"num_col\",3],PARAMETER[\"elt_0_0\", 0.883485346527455],PARAMETER[\"elt_0_1\", -0.468458794848877],PARAMETER[\"elt_0_2\", 3455869.17937689],PARAMETER[\"elt_1_0\", 0.468458794848877],PARAMETER[\"elt_1_1\", 0.883485346527455],PARAMETER[\"elt_1_2\", 5478710.88035753],PARAMETER[\"elt_2_2\", 1]]," +
                                "PROJCS[\"DHDN / Gauss-Kruger zone 3\"," +
                                   "GEOGCS[\"DHDN\"," +
                                      "DATUM[\"Deutsches_Hauptdreiecksnetz\"," +
                                         "SPHEROID[\"Bessel 1841\", 6377397.155, 299.1528128, AUTHORITY[\"EPSG\", \"7004\"]]," +
                                         "TOWGS84[612.4, 77, 440.2, -0.054, 0.057, -2.797, 0.525975255930096]," +
                                         "AUTHORITY[\"EPSG\", \"6314\"]]," +
                                       "PRIMEM[\"Greenwich\", 0, AUTHORITY[\"EPSG\", \"8901\"]]," +
                                       "UNIT[\"degree\", 0.0174532925199433, AUTHORITY[\"EPSG\", \"9122\"]]," +
                                       "AUTHORITY[\"EPSG\", \"4314\"]]," +
                                   "UNIT[\"metre\", 1, AUTHORITY[\"EPSG\", \"9001\"]]," +
                                   "PROJECTION[\"Transverse_Mercator\"]," +
                                   "PARAMETER[\"latitude_of_origin\", 0]," +
                                   "PARAMETER[\"central_meridian\", 9]," +
                                   "PARAMETER[\"scale_factor\", 1]," +
                                   "PARAMETER[\"false_easting\", 3500000]," +
                                   "PARAMETER[\"false_northing\", 0]," +
                                   "AUTHORITY[\"EPSG\", \"31467\"]]" +
                        "]";

            //string gk_wkt = "PROJCS[\"DHDN / Gauss-Kruger zone 3\",GEOGCS[\"DHDN\",DATUM[\"Deutsches_Hauptdreiecksnetz\",SPHEROID[\"Bessel 1841\",6377397.155,299.1528128,AUTHORITY[\"EPSG\",\"7004\"]],AUTHORITY[\"EPSG\",\"6314\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4314\"]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"latitude_of_origin\",0],PARAMETER[\"central_meridian\",9],PARAMETER[\"scale_factor\",1],PARAMETER[\"false_easting\",3500000],PARAMETER[\"false_northing\",0],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AUTHORITY[\"EPSG\",\"31467\"]]";

            CoordinateSystemFactory fac = new CoordinateSystemFactory ();
            IFittedCoordinateSystem fcs = fac.CreateFromWkt (ft_wkt) as IFittedCoordinateSystem;
            //ICoordinateSystem gkcs = fac.CreateFromWkt (gk_wkt);

            //Transformation example (MNAU -> GK)
            // Start point (MNAU) X=2040,000m Y=1590,000m]
            // Target point (GK): X=3456926,640m Y=5481071,278m;

            ICoordinateTransformation trans = CoordinateTransformationFactory.CreateFromCoordinateSystems (fcs, fcs.BaseCoordinateSystem);

            List<double[]> coords = new List<double[]>{
                new double[]{2040.0, 1590.0},
            };

            IList<double[]> transformedCoords = trans.MathTransform.TransformList (coords);
            Assert.AreEqual (3456926.640, transformedCoords[0][0], 0.00000001);
            Assert.AreEqual (5481071.278, transformedCoords[0][1], 0.00000001);
        }
 /**
  * Creates a new SRS from an ESRI-style WKT/PRJ string.
  *
  * @param wkt
  *      ESRI-style WKT (well-known text) SRS definition
  * @return
  *      A spatial reference. Caller is responsible for deleting
  *      the return object.
  */
 public SpatialReference createSRSfromESRI(string wkt)
 {
     SpatialReference result = null;
     //SetUp coordinate transformation
     ProjNet.CoordinateSystems.CoordinateSystemFactory csf = new ProjNet.CoordinateSystems.CoordinateSystemFactory();
     cs = csf.CreateFromWkt(wkt);
     throw new NotImplementedException();
 }
        // get raster projection
        public ICoordinateSystem GetProjection()
        {
            var cFac = new CoordinateSystemFactory();

            try
            {
                if (Projection != "")
                    return cFac.CreateFromWkt(Projection);
            }
            catch (Exception ee)
            {
                if (_logger.IsErrorEnabled)
                    _logger.Error("Error parsing projection", ee);
            }

            return null;
        }
        public void TestUnitBeforeProjection()
        {
            var fac = new CoordinateSystemFactory();
            var wkt = "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.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]]," +
                     "AUTHORITY[\"EPSG\",\"4277\"]]," +
                 "UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]]," +
                 "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]," +
                 "AUTHORITY[\"EPSG\",\"27700\"]," +
                 "AXIS[\"Easting\",EAST]," +
                 "AXIS[\"Northing\",NORTH]]";
            ProjectedCoordinateSystem pcs = fac.CreateFromWkt(wkt) as ProjectedCoordinateSystem;

            Assert.IsNotNull(pcs);

            Assert.AreEqual("OSGB 1936 / British National Grid", pcs.Name);
            Assert.AreEqual("OSGB 1936", pcs.GeographicCoordinateSystem.Name);
            Assert.AreEqual("OSGB_1936", pcs.GeographicCoordinateSystem.HorizontalDatum.Name);
            Assert.AreEqual("Airy 1830", pcs.GeographicCoordinateSystem.HorizontalDatum.Ellipsoid.Name);
            Assert.AreEqual(6377563.396, pcs.GeographicCoordinateSystem.HorizontalDatum.Ellipsoid.SemiMajorAxis);
            Assert.AreEqual(299.3249646, pcs.GeographicCoordinateSystem.HorizontalDatum.Ellipsoid.InverseFlattening);
            Assert.AreEqual("EPSG", pcs.GeographicCoordinateSystem.HorizontalDatum.Ellipsoid.Authority);
            Assert.AreEqual(7001, pcs.GeographicCoordinateSystem.HorizontalDatum.Ellipsoid.AuthorityCode);
            Assert.AreEqual("EPSG", pcs.GeographicCoordinateSystem.HorizontalDatum.Authority);
            Assert.AreEqual(6277, pcs.GeographicCoordinateSystem.HorizontalDatum.AuthorityCode);
            Assert.AreEqual("Greenwich", pcs.GeographicCoordinateSystem.PrimeMeridian.Name);
            Assert.AreEqual(0, pcs.GeographicCoordinateSystem.PrimeMeridian.Longitude);
            Assert.AreEqual("EPSG", pcs.GeographicCoordinateSystem.PrimeMeridian.Authority);
            Assert.AreEqual(8901, pcs.GeographicCoordinateSystem.PrimeMeridian.AuthorityCode, 8901);
            Assert.AreEqual("degree", pcs.GeographicCoordinateSystem.AngularUnit.Name);
            Assert.AreEqual(0.0174532925199433, pcs.GeographicCoordinateSystem.AngularUnit.RadiansPerUnit);
            Assert.AreEqual("EPSG", pcs.GeographicCoordinateSystem.AngularUnit.Authority);
            Assert.AreEqual(9122, pcs.GeographicCoordinateSystem.AngularUnit.AuthorityCode);
            Assert.AreEqual("EPSG", pcs.GeographicCoordinateSystem.Authority);
            Assert.AreEqual(4277, pcs.GeographicCoordinateSystem.AuthorityCode, 4277);

            Assert.AreEqual("Transverse_Mercator", pcs.Projection.ClassName, "Projection Classname");

            ProjectionParameter latitude_of_origin = pcs.Projection.GetParameter("latitude_of_origin");
            Assert.IsNotNull(latitude_of_origin);
            Assert.AreEqual(49, latitude_of_origin.Value);
            ProjectionParameter central_meridian = pcs.Projection.GetParameter("central_meridian");
            Assert.IsNotNull(central_meridian);
            Assert.AreEqual(-2, central_meridian.Value);
            ProjectionParameter scale_factor = pcs.Projection.GetParameter("scale_factor");
            Assert.IsNotNull(scale_factor);
            Assert.AreEqual(0.9996012717, scale_factor.Value);
            ProjectionParameter false_easting = pcs.Projection.GetParameter("false_easting");
            Assert.IsNotNull(false_easting);
            Assert.AreEqual(400000, false_easting.Value);
            ProjectionParameter false_northing = pcs.Projection.GetParameter("false_northing");
            Assert.IsNotNull(false_northing);
            Assert.AreEqual(-100000, false_northing.Value);

            Assert.AreEqual("metre", pcs.LinearUnit.Name);
            Assert.AreEqual(1, pcs.LinearUnit.MetersPerUnit);
            Assert.AreEqual("EPSG", pcs.LinearUnit.Authority);
            Assert.AreEqual(9001, pcs.LinearUnit.AuthorityCode);
            Assert.AreEqual("EPSG", pcs.Authority);
            Assert.AreEqual(27700, pcs.AuthorityCode);

            string newWkt = pcs.WKT.Replace(", ", ",");
            Assert.AreEqual(wkt, newWkt);
        }
        public void TestPolyconicTransforms()
        {
            ICoordinateSystemFactory csf = new CoordinateSystemFactory();
            ICoordinateSystem sad69 = csf.CreateFromWkt("PROJCS[\"SAD69 / Brazil Polyconic (deprecated)\",GEOGCS[\"SAD69\",DATUM[\"South_American_Datum_1969\",SPHEROID[\"GRS 1967\",6378160,298.247167427,AUTHORITY[\"EPSG\",\"7036\"]],AUTHORITY[\"EPSG\",\"6291\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9108\"]],AUTHORITY[\"EPSG\",\"4291\"]],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],PROJECTION[\"Polyconic\"],PARAMETER[\"latitude_of_origin\",0],PARAMETER[\"central_meridian\",-54],PARAMETER[\"false_easting\",5000000],PARAMETER[\"false_northing\",10000000],AUTHORITY[\"EPSG\",\"29100\"],AXIS[\"X\",EAST],AXIS[\"Y\",NORTH]]");
            ICoordinateSystem wgs84GCS = SRIDReader.GetCSbyID(4326); //GCS WGS84

            ICoordinateTransformation trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(wgs84GCS, sad69);

            double[] p0 = new double[] { -43.176377, -22.966494 };
            double[] expected = new double[] { 6108938.17208353, 7418275.67520224 };

            double[] p1 = trans.MathTransform.Transform(p0);
            trans.MathTransform.Invert();
            double[] p2 = trans.MathTransform.Transform(p1);

            Assert.IsTrue(ToleranceLessThan(p1, expected, 0.013), String.Format("Transformation outside tolerance, Expected [{0},{1}], got [{2},{3}]", expected[0], expected[1], p1[0], p1[1]));
            //WARNING: This accuracy is too poor!
            Assert.IsTrue(ToleranceLessThan(p0, p2, 0.0000001), String.Format("Transformation outside tolerance, Expected [{0},{1}], got [{2},{3}]", p0[0], p0[1], p2[0], p2[1]));
        }
Exemple #36
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DefaultSimpleTransform"/> class.
 /// </summary>
 /// <param name="sourceCsWkt">The source cs WKT.</param>
 /// <param name="targetCsWkt">The target cs WKT.</param>
 internal DefaultSimpleTransform(string sourceCsWkt, string targetCsWkt)
 {
     //Check for and replace the WGS84.PseudoMercator WKT
     string srcWkt = sourceCsWkt == CSMAP_WGS84_PSEUDO_MERCATOR ? POPULAR_VISUALISATION_CRS : sourceCsWkt;
     string dstWkt = targetCsWkt == CSMAP_WGS84_PSEUDO_MERCATOR ? POPULAR_VISUALISATION_CRS : targetCsWkt;
     var fact = new CoordinateSystemFactory();
     _source = fact.CreateFromWkt(srcWkt);
     _target = fact.CreateFromWkt(dstWkt);
     var tfact = new CoordinateTransformationFactory();
     _trans = tfact.CreateFromCoordinateSystems(_source, _target);
 }
        /**
         * Creates a new SRS from an OSG WKT string.
         *
         * @param wkt
         *      OGC WKT (well-known text) SRS definition
         * @param reference_frame
         *      Reference frame to apply to points in this SRS
         * @return
         *      A spatial reference. Caller is responsible for deleting
         *      the return object.
         */
        public SpatialReference createSRSfromWKT(string wkt, Mogre.Matrix4 reference_frame)
        {
            //Implementar el MatrixTransform
            //rellenar el MatrixTransform usando el reference_frame
            //SetUp coordinate transformation
            ProjNet.CoordinateSystems.CoordinateSystemFactory csf = new ProjNet.CoordinateSystems.CoordinateSystemFactory();
            ProjNet.CoordinateSystems.ICoordinateSystem csSource = csf.CreateFromWkt(wkt);

            SharpMapSpatialReference sr = new SharpMapSpatialReference();
            sr.CoordinateSystem = csSource;
            sr.MathTransform = new MatrixTransform(csSource.Dimension, reference_frame);
            return sr;
        }
        public void ParseFittedCoordinateSystemWkt ()
        {
            CoordinateSystemFactory fac = new CoordinateSystemFactory ();
            IFittedCoordinateSystem fcs = null;
            string wkt = "FITTED_CS[\"Local coordinate system MNAU (based on Gauss-Krueger)\"," + 
                                "PARAM_MT[\"Affine\"," + 
                                   "PARAMETER[\"num_row\",3],PARAMETER[\"num_col\",3],PARAMETER[\"elt_0_0\", 0.883485346527455],PARAMETER[\"elt_0_1\", -0.468458794848877],PARAMETER[\"elt_0_2\", 3455869.17937689],PARAMETER[\"elt_1_0\", 0.468458794848877],PARAMETER[\"elt_1_1\", 0.883485346527455],PARAMETER[\"elt_1_2\", 5478710.88035753],PARAMETER[\"elt_2_2\", 1]]," + 
                                "PROJCS[\"DHDN / Gauss-Kruger zone 3\"," +
                                   "GEOGCS[\"DHDN\"," + 
                                      "DATUM[\"Deutsches_Hauptdreiecksnetz\"," + 
                                         "SPHEROID[\"Bessel 1841\", 6377397.155, 299.1528128, AUTHORITY[\"EPSG\", \"7004\"]]," + 
                                         "TOWGS84[612.4, 77, 440.2, -0.054, 0.057, -2.797, 0.525975255930096]," + 
                                         "AUTHORITY[\"EPSG\", \"6314\"]]," + 
                                       "PRIMEM[\"Greenwich\", 0, AUTHORITY[\"EPSG\", \"8901\"]]," + 
                                       "UNIT[\"degree\", 0.0174532925199433, AUTHORITY[\"EPSG\", \"9122\"]]," + 
                                       "AUTHORITY[\"EPSG\", \"4314\"]]," + 
                                   "UNIT[\"metre\", 1, AUTHORITY[\"EPSG\", \"9001\"]]," + 
                                   "PROJECTION[\"Transverse_Mercator\"]," + 
                                   "PARAMETER[\"latitude_of_origin\", 0]," + 
                                   "PARAMETER[\"central_meridian\", 9]," + 
                                   "PARAMETER[\"scale_factor\", 1]," + 
                                   "PARAMETER[\"false_easting\", 3500000]," +
                                   "PARAMETER[\"false_northing\", 0]," + 
                                   "AUTHORITY[\"EPSG\", \"31467\"]]" + 
                        "]";

            try
            { 
                fcs = fac.CreateFromWkt (wkt) as IFittedCoordinateSystem;
            }
            catch (Exception ex)
            {
                Assert.Fail ("Could not create fitted coordinate system from:\r\n" + wkt + "\r\n" + ex.Message);
            }

            Assert.IsNotNull (fcs);
            Assert.IsNotNullOrEmpty (fcs.ToBase ());
            Assert.IsNotNull (fcs.BaseCoordinateSystem);

            Assert.AreEqual ("Local coordinate system MNAU (based on Gauss-Krueger)", fcs.Name);
            //Assert.AreEqual ("CUSTOM", fcs.Authority);
            //Assert.AreEqual (123456, fcs.AuthorityCode);

            Assert.AreEqual ("EPSG", fcs.BaseCoordinateSystem.Authority);
            Assert.AreEqual (31467, fcs.BaseCoordinateSystem.AuthorityCode);
        }
 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;
 }