Skip to content

Rotate a set of coordinates within a PCS #82

Open
@TimThaler

Description

@TimThaler

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions