Rotate Scale Shear a grid
Configuration examples Rotate Scale Shear a grid
The script presents an example of how you can rotate, stretch and shear a raster domain.
example
container Geography
{
unit<fpoint> rdc_meter: range = "[xy(0; 300000), xy(280000; 625000))";
}
container parameters
{
unit<float32> meter := BaseUnit('meter', float32);
parameter<meter> gridsize := 1000[meter];
parameter<meter> NL_grid_X_min := 270000[meter];
parameter<meter> NL_grid_Y_min := 325000[meter];
parameter<meter> X_org := ( 0f + (NL_grid_Y_min / 2f))[meter];
parameter<meter> Y_org := (375000f - (NL_grid_X_min / 2f))[meter];
parameter<uint32> aantalkolommen := uint32(((NL_grid_Y_min + NL_grid_X_min)*(sqrt(2f) / 2f)) / gridsize);
parameter<uint32> aantalrijen := uint32(((NL_grid_Y_min + NL_grid_X_min)*(sqrt(2f) / 2f)) / gridsize);
parameter<float32> shear_factor := 0.5f;
parameter<float32> rotation_angle := (pi() / 4d)[float32]; // in radial=45 degrees;
parameter<float32> X_stretch_factor := gridsize;
parameter<float32> Y_stretch_factor := gridsize;
}
unit<fpoint> domain;
unit<spoint> rotated_grid_domain :=
range(domain, point_yx(0s, 0s), point_yx(parameters/aantalkolommen[int16], parameters/aantalrijen[int16]));
unit<spoint> conversion_matrix := range(spoint, point_yx(0s,0s), point_yx(2s,2s))
, Using = "parameters"
{
attribute<float32> A_stretch := union_data(., Y_stretch_factor, 0f, 0f, X_stretch_factor);
attribute<float32> B_shear := union_data(., 1f, shear_factor, 0f, 1f);
attribute<float32> C_rotation :=
union_data(., cos(rotation_angle), sin(rotation_angle), -sin(rotation_angle), cos(rotation_angle));
attribute<float32> AxB := matr_mul(A_stretch, B_shear,.);
attribute<float32> AxBxC := matr_mul(AxB, C_rotation,.);
attribute<float32> Result := AxBxC;
}
unit<upoint> grid_coords := range(upoint, point_yx(0,0), point_yx(2, #rotated_grid_domain))
{
attribute<rotated_grid_domain> cell := grid_domain/cell[pointcol(id(.))[grid_domain]];
attribute<float32> rotated_grid :=
pointrow(id(.)) == 0 ? pointcol(cell)[float32] : pointrow(cell)[float32];
attribute<float32> rd := matr_mul(conversion_matrix/Result, rotated_grid, .);
}
unit<uint32> grid_domain := range(uint32, 0, #rotated_grid_domain)
, Using = "parameters"
, DialogData = "rotated_grid_rd"
, DialogType = "map"
{
attribute<rotated_grid_domain> cell := union_data(., id(rotated_grid_domain));
attribute<Geography/rdc_meter> rotated_grid_rd :=
point_yx( first(grid_coords/rd, pointcol(id(grid_coords))[.]) + Y_org
, last(grid_coords/rd, pointcol(id(grid_coords))[.]) + X_org
, geography/rdc_meter);
}
Each column of the matrix domain grid_coords stands for one cell of rotated_grid_domain: the cell that grid_domain/cell gives for the element of grid_domain with the same number. Row 0 of rotated_grid holds the column number of that cell and row 1 its row number. After the multiplication by conversion_matrix/Result, row 0 of rd holds the Y and row 1 the X of the point, relative to Y_org and X_org.
rotated_grid looks up the cell of each element by its column, instead of filling the two rows with Union_data: union_data fills a domain in the order of its elements, and in a grid domain that is larger than one tile, such as grid_coords, that order runs tile by tile (see GeoDMS Default Tiling) and not row by row. The column numbers would then not end up in row 0 and the row numbers in row 1, where matr_mul takes them.