# How to map rectangular lat/lon region on non-rectangular projection with GeoMakie?

**URL:** <https://discourse.julialang.org/t/how-to-map-rectangular-lat-lon-region-on-non-rectangular-projection-with-geomakie/103140>\
**Category:** Geo\
**Tags:** question, makie, map\
**Created:** [August 24, 2023, 3:30am UTC](https://discourse.julialang.org/t/how-to-map-rectangular-lat-lon-region-on-non-rectangular-projection-with-geomakie/103140 "2023-08-24T03:30:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![haffner](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/haffner/32/35871_2.png) [@haffner](https://discourse.julialang.org/u/haffner)\
**Post date:** [August 24, 2023, 3:30am UTC](https://discourse.julialang.org/t/how-to-map-rectangular-lat-lon-region-on-non-rectangular-projection-with-geomakie/103140/1 "2023-08-24T03:30:24Z")

</div>

I’m trying to map a rectangular lat/lon polygon on a non-rectangular map projection using GeoMakie,

When I use four corner points to define the region, GeoMakie draws straight lines between them. The example below shows what I am getting. I would like the polygon to follow the curvature of the meridians instead.

 ![image](https://global.discourse-cdn.com/julialang/original/3X/c/d/cd99b544d1a22c88039e8ca95592f2524ded78a5.png)

```julia
using Makie, CairoMakie
using GeoMakie
using Makie, CairoMakie
using GeoMakie

fig = Figure()
ax = GeoAxis(fig[1, 1], title="poly = [(60, -30), (180, -30), (180, 30), (60, 30)]")
poly = [(60, -30), (180, -30), (180, 30), (60, 30)]
poly!(ax, poly, color=:red)
fig

```

The default projection for GeoMakie is Equal Earth as I understand it, and the source default is Plate Caree, so I thought this would work. The corner points are obviously projected properly on the map.

What am I missing? Is there some way to accomplish what I want?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [August 24, 2023, 6:11am UTC](https://discourse.julialang.org/t/how-to-map-rectangular-lat-lon-region-on-non-rectangular-projection-with-geomakie/103140/2 "2023-08-24T06:11:48Z")

</div>

The thing is just that Makie currently doesn’t subsample data when it encounters nonlinear projections. So the vertices of the poly are correct but the lines between them are straight in screen space. If you made a polygon with more points between the corners, it would look better. I’m not sure yet what a good general solution to this could be without making it slow for larger datasets

---

<div class="post-metadata">

**Author:** ![haffner](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/haffner/32/35871_2.png) [@haffner](https://discourse.julialang.org/u/haffner)\
**Post date:** [August 24, 2023, 9:57pm UTC](https://discourse.julialang.org/t/how-to-map-rectangular-lat-lon-region-on-non-rectangular-projection-with-geomakie/103140/3 "2023-08-24T21:57:15Z")

</div>

From the standpoint of Makie this makes sense.

For GeoMakie, I was thinking the dest keyword would set to plot a geodetic polygon. It would be nice to have plotting in GeoMake obey something like a transform keyword in cartopy. But maybe that’s not optimal or simple.

Might look at the GeoMakie code to see how it draws the graticules on non-rectangular projections, which curve as expected. That seems essentially the same problem.

---

<div class="post-metadata">

**Author:** ![kapple](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kapple/32/218915_2.png) [@kapple](https://discourse.julialang.org/u/kapple)\
**Post date:** [September 29, 2024, 4:39pm UTC](https://discourse.julialang.org/t/how-to-map-rectangular-lat-lon-region-on-non-rectangular-projection-with-geomakie/103140/4 "2024-09-29T16:39:42Z")

</div>

Does [GeometryOps.jl](https://juliageo.org/GeometryOps.jl/stable/tutorials/creating_geometry#plot-geometry) help you?

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [September 29, 2024, 7:54pm UTC](https://discourse.julialang.org/t/how-to-map-rectangular-lat-lon-region-on-non-rectangular-projection-with-geomakie/103140/5 "2024-09-29T19:54:07Z")

</div>

If you plot a Box with LatLon coords from Meshes.jl with viz it will automatically subsample the box. If you send the box to a Proj transform it will also subsample.

You can call the viz recipe on any axis, including the GeoAxis above.

---

<div class="post-metadata">

**Author:** ![asinghvi17](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/asinghvi17/32/8272_2.png) [@asinghvi17](https://discourse.julialang.org/u/asinghvi17)\
**Post date:** [September 30, 2024, 4:06pm UTC](https://discourse.julialang.org/t/how-to-map-rectangular-lat-lon-region-on-non-rectangular-projection-with-geomakie/103140/6 "2024-09-30T16:06:04Z")

</div>

You can always subsample manually, which will give you the correct polygon:

```julia
using Makie, CairoMakie
using GeoMakie

import GeometryOps as GO, GeoInterface as GI

fig = Figure()
ax = GeoAxis(fig[1, 1], title="poly = [(60, -30), (180, -30), (180, 30), (60, 30)]")
poly = GI.LineString([(60, -30), (180, -30), (180, 30), (60, 30)])
spoly = GO.segmentize(poly, max_distance = 1) # a point every degree of lon/lat
poly!(ax, spoly, color=:red)
fig

```

You can also use geodesic sampling:

```julia
poly!(ax, GO.segmentize(GO.GeodesicSegments(max_distance = 100_000), poly), color = (:orange, 0.5))
fig

```

I guess this sat in my drafts for a bit…
