7
$\begingroup$

This question already has an answer here:

I would like to draw a rectangular map, but the sides are not aligned with the usual geographic grid. For example, the southern New Zealand island is stretched approximately along a diagonal in the usual map. So I would like MMA to produce a map inside the tilted rectangle in the figure below.

p1 = GeoGraphics[GeoRange -> CountryData["NewZealand"], 
  GeoBackground -> "ReliefMap"]
p2 = Graphics[
   Line[{{174, -39}, {176, -43}, {168, -47}, {166, -43}, {174, -39}}]];
Show[p1, p2]

New Zealand southern main island enrectangulated

Is there an elegant way to do this, or do I have to clip the parts I don't need manually?

$\endgroup$

marked as duplicate by MarcoB, m_goldberg, C. E., happy fish, Öskå Dec 10 '16 at 11:02

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • $\begingroup$ The solutions works, but it would be nice to be able to give just 4 latitude-longitude coordinates and get the map as output. I know that this is a new question, but maybe someone can comment? For the example above the coords are 40°03'59.3"S 171°48'33.5"E, 41°52'34.1"S 175°23'03.4"E, 47°27'22.0"S 169°35'56.0"E, 45°17'47.6"S 165°08'44.9"E. $\endgroup$ – Rainer Glüge Dec 5 '16 at 7:46
9
$\begingroup$

If, instead of manipulating an image, you would like to directly generate a rotated geographical projection, you can use the techniques outlined by @Jose in his answer to this question (Rotate Geographic map).

In your case, for instance, you could try:

GeoGraphics[
 GeoRange -> {{-46, -40}, {165.5, 173}}, GeoRangePadding -> Full,
 GeoProjection -> {"ObliqueMercator", "Centering" -> {{-43, 170}, 40}},
 GeoBackground -> "ReliefMap",
 GeoGridLines -> Automatic
]

Mathematica graphics

$\endgroup$
2
$\begingroup$

If you want it horizontal,

ImageTake[ImageRotate[p1, -0.8], {250, 350}, {50, 300}]

enter image description here

Or you can rotate it back to its original angle if desired.

$\endgroup$
2
$\begingroup$
p1 = GeoGraphics[GeoRange -> CountryData["NewZealand"], GeoBackground -> "ReliefMap"]

enter image description here

gr = AbsoluteOptions[p1, GeoRange][[1]]

GeoRange -> {{-47.2892, -33.7793}, {165.82, 179.157}}

pr = AbsoluteOptions[p1, PlotRange][[1]]

PlotRange -> {{165.82, 179.157}, {-53.8038, -35.9255}}

Note the differences between gr and pr.

p2 = Graphics[
      {White, Polygon[{{174, -39}, {176, -43}, {168, -47}, {166, -43}, {174, -39}}]},
       Background -> Black, PlotRange -> Reverse@gr[[2]], ImageSize -> ImageDimensions@p1];

p3 = Show[p1, p2]; (* Only for illustration *)

{p2, p3}

enter image description here

ImageCrop @ ImageAdd[ImageMultiply[p1, p2], ColorNegate @ p2]

enter image description here

$\endgroup$

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