rotate utm grid in matlab

To rotate a UTM (Universal Transverse Mercator) grid in Matlab, you can use the affine2d and imwarp functions. Here is an example of rotating a UTM grid by 45 degrees:

main.m
% Define the UTM grid parameters
utmZone = '31T';
xMin = 624885.6475;
yMin = 6041614.5332;
cellSize = 25;

% Create a grid of points
[X, Y] = meshgrid(xMin:cellSize:xMin+100*cellSize, yMin:cellSize:yMin+100*cellSize);

% Define the rotation angle
theta = 45; % Rotation angle in degrees

% Create an affine transformation matrix for rotation
tform = affine2d([cosd(theta) -sind(theta) 0; sind(theta) cosd(theta) 0; 0 0 1]);

% Rotate the grid
[Xr, Yr] = transformPointsForward(tform, X, Y);

% Display the original and rotated grids
subplot(1,2,1);
plot(X, Y, 'bo');
title('Original UTM grid');
axis equal;

subplot(1,2,2);
plot(Xr, Yr, 'ro');
title('Rotated UTM grid');
axis equal;
683 chars
29 lines

This script defines a UTM grid in zone 31T, creates a grid of points, rotates the grid by 45 degrees using an affine transformation matrix, and then displays the original and rotated grids using plot.

gistlibby LogSnag