2

I have a polygon feature on map to which I need to transform the coordinates to local coordinate system with respect to new origin while keeping the same datum.

So far using the Proj4 library and by defining the custom map origin I could able to re-project/transform my global coordinates to local as follows

+proj=etmerc +lat_0=52.481392 +lon_0=13.355795 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs --Using this Proj4 definition

Here in the image you can see the marker with name "New Origin" is the one I want to keep at center and transform the coordinates of highlighted polygons to local coordinate system Here in the image you can see the marker with name "New Origin" is the one I want to keep at center and transform the coordinates of highlighted polygons to local coordinate system

These are the original coordinates of selected polygons These are the original coordinates

These are the transformed coordinates of same polygon w.r.t. new map origin enter image description here

What I am looking forward now is the case of rotated map origin, as of now the current map origin is facing northwards i.e. to north pole, which I need to be rotated by around 90 degrees. Ideally this rotation should effect coordinates of the polygon (as those -ve now may get positive and vice versa).

+proj=omerc +lat_0=52.481392 +lonc=13.355795 +alpha=90.0 +k=1.0 +x_0=0 +y_0=0 +no_uoff +gamma=90.0 +ellps=WGS84 +units=m +no_defs --New definition I am trying

Regarding the same, I found this question helpful and thought to try the Oblique Mercator projection, however the results are not changing when I did the 90 degree rotation for alpha and gamma

  • Try using only alpha or only gamma, not both. – mkennedy Jul 23 '18 at 16:44
  • @mkennedy I tried those combination, but the results are still the same i.e. I am still getting the same coordinates as if no rotation is applied. – Suraj Jul 24 '18 at 7:33
  • After setting +alpha to 90 degree I am getting following changes in coordinates [-7.6953274440020305, -34.018725226408954] [-2.501843264326451, -38.56306296658011] [12.448381118476393, -19.840427535785217] [5.318901741877199, -14.513489642501089] So the coordinates are changed but (noticeably on X axis), but it doesn't seems like it changed to the effect of 90 degree. – Suraj Jul 24 '18 at 15:05
  • Try omitting +no_uoff which should convert the definition from a natural origin case to a center version so the rotation may make more sense. – mkennedy Jul 24 '18 at 16:46
0

Finally achieved this by referring this answer which have the rotation method for passed coordinates with respect to the origin. So in above case I had to transform the map origin to local coordinate system, and then pass the respective polygon coordinates as follow,

let transformedOrigin = proj4(localProjection, [originY, originX]);
let rotatedLocalCoords = this.rotate(transformedOrigin[0], transformedOrigin[1], polygonCoord[x], polygonCoord[y], -90);

And the rotated method is as follows,

rotate: function (cx, cy, x, y, angle) {
  let radians = (Math.PI / 180) * angle;
  let cos = Math.cos(radians);
  let sin = Math.sin(radians);
  let nx = (cos * (x - cx)) + (sin * (y - cy)) + cx;
  let ny = (cos * (y - cy)) - (sin * (x - cx)) + cy;
  return [nx, ny];
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.