/// <summary>
        /// Converts fieldAttributes DotSpatial ProjectionInfo object to an OGR SpatialReference object
        /// </summary>
        /// <param name="pProjection">DotSpatial ProjectionInfo</param>
        /// <returns>An OGR SpatialReference</returns>
        public static SpatialReference DSProjection2OGRSpatialReference(ProjectionInfo pProjection)
        {
            Debug.WriteLine(pProjection.ToProj4String());
            SpatialReference mSpatialReference = new SpatialReference(null);

            mSpatialReference.ImportFromProj4(pProjection.ToProj4String());
            return(mSpatialReference);
        }
Exemple #2
0
 private void frmProjPoint_Load(object sender, EventArgs e)
 {
     _fromProj        = KnownCoordinateSystems.Geographic.World.WGS1984;
     _toProj          = frmMain.CurrentWin.MapDocument.ActiveMapFrame.MapView.Projection.ProjInfo;
     TB_FromProj.Text = _fromProj.ToProj4String();
     TB_ToProj.Text   = _toProj.ToProj4String();
 }
        public void ProjectionInfoConstructorTest()
        {
            var proj4String = string.Empty;
            var actual      = ProjectionInfo.FromProj4String(proj4String);
            var expected    = new ProjectionInfo();

            Assert.AreEqual(expected.ToProj4String(), actual.ToProj4String());
        }
        public void ToProj4StringTestDoesReadMatchToString()
        {
            string proj4String = "+proj=longlat +ellps=WGS84 +no_defs ";

            ProjectionInfo target = ProjectionInfo.FromProj4String(proj4String);

            Assert.AreEqual(proj4String.Trim(), target.ToProj4String().Trim());
        }
        public void ProjectionInfoConstructorTest2()
        {
            string         proj4String = null;
            ProjectionInfo actual      = ProjectionInfo.FromProj4String(proj4String);
            ProjectionInfo expected    = new ProjectionInfo();

            Assert.AreEqual(expected.ToProj4String(), actual.ToProj4String());
        }
        public void ProjectionInfoConstructorTest2()
        {
            string proj4String = null;
            var actual = ProjectionInfo.FromProj4String(proj4String);
            var expected = new ProjectionInfo();

            Assert.AreEqual(expected.ToProj4String(), actual.ToProj4String());
        }
Exemple #7
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var SKCode = TB_SKName.Text;
            int Zone;

            if (int.TryParse(TB_Zone.Text, out Zone))
            {
                SelectProjection         = Projections.GetProjectionInfo(SKCode, Zone);
                TB_SelectProjection.Text = SelectProjection.ToProj4String();
            }
        }
        public void Proj4EsriComparisonTest()
        {
            ProjectionInfo infoBuiltIn = KnownCoordinateSystems.Geographic.World.WGS1984;

            const string   esri         = "GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137,298.257223562997]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.0174532925199433]]";
            ProjectionInfo infoFromEsri = ProjectionInfo.FromEsriString(esri);

            string expected = infoFromEsri.ToProj4String();
            string actual   = infoBuiltIn.ToProj4String();

            Assert.AreEqual(expected, actual);
        }
        public void ProjectionInfoConstructorTest1()
        {
            string         proj4String = "+proj=longlat +ellps=WGS84 +no_defs ";
            ProjectionInfo expected    = ProjectionInfo.FromProj4String(proj4String);

            ProjectionInfo actual = new ProjectionInfo();

            actual.GeographicInfo.Datum.Spheroid = new Spheroid("WGS84");
            actual.NoDefs   = true;
            actual.IsLatLon = true;

            Assert.AreEqual(expected.ToProj4String(), actual.ToProj4String());
        }
Exemple #10
0
        /// <summary>
        /// The code that actually tests an input projection
        /// </summary>
        public static void TestProjection(ProjectionInfo pStart)
        {
            ProjectionInfo pEnd = KnownCoordinateSystems.Geographic.World.WGS1984;

            double[] xy = new double[2];
            double   x  = 0;

            if (pStart.FalseEasting != null)
            {
                x     = pStart.FalseEasting.Value;
                xy[0] = pStart.FalseEasting.Value;
            }
            double[] z = new double[1];
            Reproject.ReprojectPoints(xy, z, pStart, pEnd, 0, 1);

            double y      = 0;
            string source = pStart.ToProj4String();

            Proj4.ProjectPoint(ref x, ref y, source, pEnd.ToProj4String());
            if (Math.Abs(x - xy[0]) > 0.00000001)
            {
                Assert.Fail(String.Format("The longitude was off by {0} decimal degrees from proj4", (x - xy[0])));
            }
            if (Math.Abs(y - xy[1]) > 0.00000001)
            {
                Assert.Fail(String.Format("The latitude was off by {0} decimal degrees from proj4", (y - xy[1])));
            }
            z[0] = 0;
            Reproject.ReprojectPoints(xy, z, pEnd, pStart, 0, 1);
            Proj4.ProjectPoint(ref x, ref y, pEnd.ToProj4String(), source);
            if (Math.Abs(x - xy[0]) > 1 / pStart.Unit.Meters)
            {
                Assert.Fail(String.Format("The X coordinate was off by {0} {1}", (x - xy[0]), pStart.GetUnitText(xy[0])));
            }
            if (Math.Abs(y - xy[1]) > 1 / pStart.Unit.Meters)
            {
                Assert.Fail(String.Format("The Y coordinate was off by {0} {1}", (y - xy[1]), pStart.GetUnitText(xy[1])));
            }
        }
Exemple #11
0
        public static ProjectionInfo CreateProjection(ICrsGeographic crsGeographic)
        {
            if (crsGeographic == null)
            {
                throw new ArgumentNullException("crsGeographic");
            }
            Contract.Ensures(Contract.Result <ProjectionInfo>() != null);

            var geographic = CreateGeographic(crsGeographic);

            var result = new ProjectionInfo {
                GeographicInfo = geographic,
                IsLatLon       = true,
                Transform      = new DotSpatial.Projections.Transforms.LongLat()
            };

            var finalResult = ProjectionInfo.FromProj4String(result.ToProj4String()); // TODO: fix this hack

            return(finalResult);
        }
Exemple #12
0
        /// <summary>
        /// The code that actually tests an input projection
        /// </summary>
        public static void TestProjection(ProjectionInfo pStart)
        {
            var    xy = new double[2];
            double x  = 0;

            if (pStart.FalseEasting != null)
            {
                x     = pStart.FalseEasting.Value;
                xy[0] = pStart.FalseEasting.Value;
            }
            var z = new double[1];

            Reproject.ReprojectPoints(xy, z, pStart, _pEnd, 0, 1);

            double y      = 0;
            var    source = pStart.ToProj4String();
            var    prj    = new Proj4();

            prj.ProjectPoint(ref x, ref y, source, pEndProj4);
            if (Math.Abs(x - xy[0]) > 0.00000001)
            {
                Assert.Fail("The longitude was off by {0} decimal degrees from proj4", (x - xy[0]));
            }
            if (Math.Abs(y - xy[1]) > 0.00000001)
            {
                Assert.Fail("The latitude was off by {0} decimal degrees from proj4", (y - xy[1]));
            }
            z[0] = 0;
            Reproject.ReprojectPoints(xy, z, _pEnd, pStart, 0, 1);
            prj.ProjectPoint(ref x, ref y, pEndProj4, source);
            if (Math.Abs(x - xy[0]) > 1 / pStart.Unit.Meters)
            {
                Assert.Fail("The X coordinate was off by {0} {1}", (x - xy[0]), pStart.GetUnitText(xy[0]));
            }
            if (Math.Abs(y - xy[1]) > 1 / pStart.Unit.Meters)
            {
                Assert.Fail("The Y coordinate was off by {0} {1}", (y - xy[1]), pStart.GetUnitText(xy[1]));
            }
        }
Exemple #13
0
        /// <summary>
        /// The code that actually tests an input projection
        /// </summary>
        public static void TestProjection(ProjectionInfo pStart)
        {
            var pEnd = KnownCoordinateSystems.Geographic.World.WGS1984;
            var xy = new double[2];
            double x = 0;
            if (pStart.FalseEasting != null)
            {
                x = pStart.FalseEasting.Value;
                xy[0] = pStart.FalseEasting.Value;
            }
            var z = new double[1];
            Reproject.ReprojectPoints(xy, z, pStart, pEnd, 0, 1);

            double y = 0;
            var source = pStart.ToProj4String();
            var prj = new Proj4();
            prj.ProjectPoint(ref x, ref y, source, pEnd.ToProj4String());
            if (Math.Abs(x - xy[0]) > 0.00000001)
            {
                Assert.Fail("The longitude was off by {0} decimal degrees from proj4", (x - xy[0]));
            }
            if (Math.Abs(y - xy[1]) > 0.00000001)
            {
                Assert.Fail("The latitude was off by {0} decimal degrees from proj4", (y - xy[1]));
            }
            z[0] = 0;
            Reproject.ReprojectPoints(xy, z, pEnd, pStart, 0, 1);
            prj.ProjectPoint(ref x, ref y, pEnd.ToProj4String(), source);
            if (Math.Abs(x - xy[0]) > 1 / pStart.Unit.Meters)
            {
                Assert.Fail("The X coordinate was off by {0} {1}", (x - xy[0]), pStart.GetUnitText(xy[0]));
            }
            if (Math.Abs(y - xy[1]) > 1 / pStart.Unit.Meters)
            {
                Assert.Fail("The Y coordinate was off by {0} {1}", (y - xy[1]), pStart.GetUnitText(xy[1]));
            }
        }
 private void UpdateProjectionStrings()
 {
     txtEsriString.Text  = _projection.ToEsriString();
     txtProj4String.Text = _projection.ToProj4String();
 }
Exemple #15
0
 public string ToProj4String()
 {
     return(Projection.ToProj4String().Trim());
 }
 /// <summary>
 /// Creates an instance of this class
 /// </summary>
 public DotSpatialSpatialReference(ProjectionInfo projectionInfo)
 {
     _oid           = projectionInfo.ToProj4String();
     Definition     = projectionInfo.ToProj4String();
     ProjectionInfo = projectionInfo;
 }
        public void ProjectionInfoConstructorTest1()
        {
            var proj4String = "+proj=longlat +ellps=WGS84 +no_defs ";
            var expected = ProjectionInfo.FromProj4String(proj4String);

            var actual = new ProjectionInfo();
            actual.GeographicInfo.Datum.Spheroid = new Spheroid("WGS84");
            actual.NoDefs = true;
            actual.IsLatLon = true;

            Assert.AreEqual(expected.ToProj4String(), actual.ToProj4String());
        }