ProjectionInfo.ToProj4String

Developer
Dec 4, 2010 at 4:17 PM

I'm having trouble figuring out how the ProjectionInfo.ToProj4String() method works. It's giving me inconsistent results for the same ProjectionInfo object depending on the creation method:

ProjectionInfo proj1 = KnownCoordinateSystems.Geographic.World.WGS1984;
            
string esri = "GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137,298.257223562997]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.0174532925199433]]";
ProjectionInfo proj2 = new ProjectionInfo();
proj2.ReadEsriString(esri);

In the sample code I have created two ProjectionInfo object which both represent the same projection (Geographic WGS1984). The first object was created from KnownCoordinateSystems.Geographic.World.WGS1984 and the second object was created by reading the EsriString. When I call the ToProj4String() method, results are inconsistent:

proj1.ToProj4String() returns:  +proj=longlat +ellps=WGS84 +datum=WGS84 +k=1 +no_defs

proj2.ToProj4String() returns:  +k=1 +proj=longlat

The +ellps=WGS84, +datum=WGS84 and +no_defs parameter are missing from the proj2.ToProj4String(). Also the order of the parameters in the Proj4string is different. This creates an issue when adding a shapefile with a .prj file to the map. proj1.Equals(proj2) returns false, because the 'proj4' strings are different. It should return true.

Developer
Dec 11, 2010 at 6:54 AM

This seems to be a bug in DotSpatial.Projection. I have posted it as the issue: http://dotspatial.codeplex.com/workitem/188

We should fix this issue in the ProjectionInfo.ToProj4String() method and / or use a more clever way to compare two projections than the current method of comparing two Proj4 strings.