Problem with ReprojectPoints

May 6, 2014 at 2:29 PM
I have problems using the ReprojectPoints and unsure if this is a bug or a misunderstanding.
I do the following:
double[] xy = new double[2];
xy[0] = e.Position.Longitude.ToRadians().Value;
xy[1] = e.Position.Latitude.ToRadians().Value;
double[] z = new double[1];
z[0] = 100.0; // Altitude assumed at 100m

ProjectionInfo src = ProjectionInfo.FromEpsgCode(4326); // WGS 84
ProjectionInfo dst = ProjectionInfo.FromEpsgCode(2056); // CH1903+ / LV95

Reproject.ReprojectPoints(xy, z, src, dst, 0, 1);
which returns the wrong coordinates. I checked that with my own verified projection.
I had closer look to ReprojectPoints. What I observed is that the input data is always converted to latitude/longitude even if the xy is already latitude/longitude, see Reproject.cs, Line 138:
// Transform source points to lam/phi if they are not already
ConvertToLatLon(source, xy, z, srcZtoMeter, startIndex, numPoints);
If I comment out this line, the reprojection works as expected.

Is this indeed a bug or do I wrongly apply the ReprojectPoints function?
May 7, 2014 at 6:11 AM
Can somebody confirm, if this is a bug or simply the wrong way to apply ReprojectPoints? Or put it differently, what should be the input arguments?
May 7, 2014 at 8:08 AM
Hi, you are using ReprojectPoints in correct way. But you need to be sure that values you are passing in xy array are really WGS84 coords.
May 7, 2014 at 8:43 AM
Thanks for replying. The position is acquired with a GNSS receiver (PositionChanged event of NmeaInterpreter). Thus, I expect the position to be latitude/longitude as WGS84 coordinates. I checked the receiver configuration and it should be so. Furthermore, I did the reprojection manually with these coordinates and I obtained the correct coordinates, but not then I applied ReprojectPoints. If I comment out ConvertToLatLon in ReprojectPoints, then it the reprojection is correct. Thus, I am wondering why ConvertToLatLon is applied, even though the input coordinates are already latitude/longitude. But I am not expert in this field...
May 7, 2014 at 9:38 AM
ConvertToLatLon() is correct beacause ReprojectPoints used in many places\applications.
Could you show input points and expected result in epsg2056?
May 7, 2014 at 10:35 AM
If I'm not mistaken, your input coordinates should not be in radians but degrees.
Marked as answer by mogikanin on 5/7/2014 at 6:48 AM
May 7, 2014 at 11:00 AM
Oh, yes, should be degree... sorry for making a fuzz.