{"action":"closed","issue":{"url":"https://api.github.com/repos/DotSpatial/DotSpatial/issues/182","repository_url":"https://api.github.com/repos/DotSpatial/DotSpatial","labels_url":"https://api.github.com/repos/DotSpatial/DotSpatial/issues/182/labels{/name}","comments_url":"https://api.github.com/repos/DotSpatial/DotSpatial/issues/182/comments","events_url":"https://api.github.com/repos/DotSpatial/DotSpatial/issues/182/events","html_url":"https://github.com/DotSpatial/DotSpatial/issues/182","id":153407376,"number":182,"title":"ProjectionInfo.ToProj4String - Inconsistent results for WGS84","user":{"login":"mogikanin","id":840681,"avatar_url":"https://avatars.githubusercontent.com/u/840681?v=3","gravatar_id":"","url":"https://api.github.com/users/mogikanin","html_url":"https://github.com/mogikanin","followers_url":"https://api.github.com/users/mogikanin/followers","following_url":"https://api.github.com/users/mogikanin/following{/other_user}","gists_url":"https://api.github.com/users/mogikanin/gists{/gist_id}","starred_url":"https://api.github.com/users/mogikanin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mogikanin/subscriptions","organizations_url":"https://api.github.com/users/mogikanin/orgs","repos_url":"https://api.github.com/users/mogikanin/repos","events_url":"https://api.github.com/users/mogikanin/events{/privacy}","received_events_url":"https://api.github.com/users/mogikanin/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/DotSpatial/DotSpatial/labels/bug","name":"bug","color":"ee0701"},{"url":"https://api.github.com/repos/DotSpatial/DotSpatial/labels/CodePlex","name":"CodePlex","color":"ededed"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-05-06T08:50:47Z","updated_at":"2016-05-06T08:50:48Z","closed_at":"2016-05-06T08:50:48Z","body":"**This issue was imported from [CodePlex](http://dotspatial.codeplex.com/workitem/188)**\r\n\r\n**[jirikadlec2](http://www.codeplex.com/site/users/view/jirikadlec2)** wrote 2010-12-11 at 09:47\r\nI have two ProjectionInfo objects representing the \"WGS1984\" spatial reference system. Depending on how the object was created, ToProj4String() gives inconsistent results. This is a major issue, because the ProjectionInfo.Equals() method in DotSpatial\r\n relies on the Proj4String to compare whether two ProjectionInfo objects represent the same projection. Sample code to demonstrate the issue:\r\n\r\n\r\n\r\n\r\nProjectionInfo proj1 = KnownCoordinateSystems.Geographic.World.WGS1984; \r\n\r\n\r\n\r\nstring esri = \"GEOGCS[\\\"GCS_WGS_1984\\\",DATUM[\\\"D_WGS_1984\\\",SPHEROID[\\\"WGS_1984\\\",6378137,298.257223562997]],PRIMEM[\\\"Greenwich\\\",0],UNIT[\\\"Degree\\\",0.0174532925199433]]\";\r\n\r\n\r\nProjectionInfo proj2 = new ProjectionInfo(); \r\n\r\nproj2.ReadEsriString(esri); \r\n\r\n\r\n\r\nproj1.ToProj4String() returns: +proj=longlat +ellps=WGS84 +datum=WGS84 +k=1 +no_defs\r\n\r\n\r\n\r\n\r\nproj2.ToProj4String() returns: +k=1 +proj=longlat \r\n\r\n\r\n\r\nThe +ellps=WGS84, +datum=WGS84 and +no_defs parameter are missing from the proj2.ToProj4String(). When investigating the code, I noticed that: (1) After calling the ReadEsriString() method the Parameters dictionary is still empty (When using KnownCoordinateSystems.Geographic.World.WGS84\r\n it contains the ellps, datum and proj parameters), (2) The UpdateParam() methods in ToProj4String don't read the GeographicInfo.Datum and GeographicInfo.Datum.Spheroid properties and (3) The order of the +proj and +k parameters in the resulting Proj4String\r\n is different. \r\n\r\n\r\n\r\nSuggested fix: \r\n\r\nIn ToProj4String(), check the GeographicInfo object. If GeographicInfo.Datum.Name and GeographicInfo.Datum.Spheroid are set, add the +ellps and +datum parameters to the Proj4String.\r\n\r\n**[mudnug](http://www.codeplex.com/site/users/view/mudnug)** wrote 2011-01-03 at 23:30\r\nIssue verified.\r\n\r\n<pre><code>    /// <summary>\n    ///A test for ToProj4String http://dotspatial.codeplex.com/workitem/188\n    ///</summary>\n    [TestMethod()]\n    public void ToProj4StringTest()\n    {\n        ProjectionInfo p1 = KnownCoordinateSystems.Geographic.World.WGS1984;\n\n        const string esri = \"GEOGCS[\\\"GCS_WGS_1984\\\",DATUM[\\\"D_WGS_1984\\\",SPHEROID[\\\"WGS_1984\\\",6378137,298.257223562997]],PRIMEM[\\\"Greenwich\\\",0],UNIT[\\\"Degree\\\",0.0174532925199433]]\";\n        ProjectionInfo p2 = new ProjectionInfo();\n        p2.ReadEsriString(esri);\n\n        string expected = p2.ToProj4String();\n        string actual = p1.ToProj4String();\n\n        Assert.AreEqual(expected, actual);\n    }</code></pre>\r\n\r\n**[mudnug](http://www.codeplex.com/site/users/view/mudnug)** wrote 2011-01-03 at 23:55\r\nI reproduced the issue by writing a unit test and then wrote some code that fixes the first part of the issue:\r\n\r\n<pre><code>            if (!String.IsNullOrEmpty(GeographicInfo.Datum.Name))\n            {\n                UpdateParam(\"datum\", GeographicInfo.Datum.Name);\n            }\n</code></pre>\r\nIn what order to you want the parameters to be output?\r\n\r\n**[mudnug](http://www.codeplex.com/site/users/view/mudnug)** wrote 2011-01-10 at 18:44\r\nJiri says the two strings should have the same parameters (perhaps in different orders) and the two strings should be considered equavalent by the Equals() if they have the same parameters.\r\n\r\n**[Shade1974](http://www.codeplex.com/site/users/view/Shade1974)** wrote 2011-01-10 at 19:27\r\nThat's a start on the process anyway, But you've already seen that you can dimension something by specifying the \"datum=GRS80\" which basically does the same thing as setting three parameters or whatever explicitly like \"ellps=\"GRS80\",\r\n which is still shorthand for \"a=##### b=######\". Spheroids can also be described using an \"a\" parameter and an inverse flattening etc. So in other words, the proj4 strings have done everything in their power to make it less convenient to\r\n compare the strings themselves than it is to just use your data objects. Simply cycle though the parameters on the ProjectionInfo class parameters and look at them, rather than writing a lot of duplicate code that basically replicates all that parsing code\r\n so that you can correctly compare the strings.\r\n\r\n\r\n\r\nTed\r\n\r\n**[mudnug](http://www.codeplex.com/site/users/view/mudnug)** wrote 2011-01-10 at 22:42\r\nTo me that means the real issue is that we use Proj4 Strings in the equality method and should instead use Esri Strings.\r\n\r\n\r\n\r\nI've fixed this. Please close this issue after testing the fix. See ToEsriStringTest()."}}