Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rotate a set of coordinates within a PCS #82

Open
TimThaler opened this issue Oct 23, 2020 · 0 comments
Open

Rotate a set of coordinates within a PCS #82

TimThaler opened this issue Oct 23, 2020 · 0 comments

Comments

@TimThaler
Copy link

TimThaler commented Oct 23, 2020

Hello,

i am looking for a way to rotate a set of coordinates. The underlying coordinate system is the Web-Mercator projected coordinate system. As all length and angles are constant on the two dimensions on a PCS it should be possible to rotate coordinates.

So far i am constructing the Web Mercator PCS like this:

var params = new List<ProjectionParameter>
    {
      new ProjectionParameter("semi_major", 6378137.0),
      new ProjectionParameter("semi_minor", 6378137.0),
      new ProjectionParameter("latitude_of_origin", 0.0),
      new ProjectionParameter("central_meridian", 0.0),
      new ProjectionParameter("false_easting", 0.0),
      new ProjectionParameter("false_northing", 0.0),
      new ProjectionParameter("scale_factor", 1),
    };

  var proj = new CoordinateSystemFactory().CreateProjection("WebMercator", "mercator_1sp", params);

  var wgs84       = new CoordinateSystemFactory().CreateGeographicCoordinateSystem("WGS84", AngularUnit.Degrees, HorizontalDatum.WGS84, PrimeMeridian.Greenwich, 
                                                                               new AxisInfo("north", AxisOrientationEnum.North), new AxisInfo("east", AxisOrientationEnum.East));
  var webMercator = new CoordinateSystemFactory().CreateProjectedCoordinateSystem("WM",  wgs84, proj, LinearUnit.Metre,
                                                                               new AxisInfo("North", AxisOrientationEnum.North), new AxisInfo("East", AxisOrientationEnum.East));

On the Proj Wiki Page i read that it is possible doing that with an AffineTransformation but i am struggling setting it up correctly.

Rotating about the origin without offset should be done with the following matrix following wiki but when transforming the coordinate, the result is way off. (Only for an angle of 90 the resulting coordinate is correct)

var angle = 60.0;
var c1 = new Coordinate(0, 1000000);  
double[,] matrix =  {
            {Math.Cos(angle), -Math.Sin(angle), 0.0},
            {Math.Sin(angle), Math.Cos(angle), 0.0},
            {0.0 , 0.0, 1}
        };
var c2 = new AffineTransformation(matrix).Transform(c1); // => {(4985871.3833798366, -1972620.6026179455, NaN)}

However looking at the constructor signals that the TranslateX/Y values maybe should be used different. The Test-Method AffineTransformationTest() is also using some values, where i am not sure where they come from.

    /// <param name="m00">Value for row 0, column 0 - AKA ScaleX</param>
    /// <param name="m01">Value for row 0, column 1 - AKA ShearX</param>
    /// <param name="m02">Value for row 0, column 2 - AKA Translate X</param>
    /// <param name="m10">Value for row 1, column 0 - AKA Shear Y</param>
    /// <param name="m11">Value for row 1, column 1 - AKA Scale Y</param>
    /// <param name="m12">Value for row 1, column 2 - AKA Translate Y</param>

What do i have to change to rotate a coordinate about and angle within a PCS?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant