Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Geometry creation tutorial #151

Merged
merged 28 commits into from
Jun 14, 2024
Merged

Geometry creation tutorial #151

merged 28 commits into from
Jun 14, 2024

Conversation

asinghvi17
Copy link
Member

This PR adds a geometry creation tutorial plus some other doc improvements that sprang from there.

cc @alex-s-gardner

@asinghvi17 asinghvi17 marked this pull request as draft June 10, 2024 00:30
@asinghvi17 asinghvi17 marked this pull request as ready for review June 11, 2024 20:56
@asinghvi17
Copy link
Member Author

@asinghvi17 asinghvi17 requested review from rafaqz and skygering June 11, 2024 20:57
@alex-s-gardner
Copy link
Contributor

I tried to add an example where for plotting a polygon with a different CRS (EPSG:32611) on the same map as the tutorial by was unable to get it to work. I think this would be useful for showing how different CRS are interpreted

@alex-s-gardner
Copy link
Contributor

alex-s-gardner commented Jun 11, 2024

I tried to add an example where for plotting a polygon with a different CRS (EPSG:32611) on the same map as the tutorial by was unable to get it to work. I think this would be useful for showing how different CRS are interpreted

This was my attempt, following on from the first mapping example:

# OK, now what if we want to plot geomitires that are in a diffent Coordinate Reference System (CRS?)

# lets create a polygon in the WGS 84 / UTM zone 10N coodinate system [EPSG:32610](https://epsg.io/32610)
crs2 = GFT.EPSG(32610)
dest = "+proj=natearth2"

# create new points 
r = 200;
k = 1000;
ϴ = 0:0.01:2pi
x = r .* (k + 1) .* cos.(ϴ) .- r .* cos.((k + 1) .* ϴ)
y = r .* (k + 1) .* sin.(ϴ) .- r .* sin.((k + 1) .* ϴ)

# now a `LinearRing`
ring3 = GI.LinearRing(Point.(zip(x, y)))

# now lets make the LineRing into a Polygon with new `CRS``
polygon3 = GI.Polygon([ring1]; crs=crs2)

# create a new `GeoAccess` with a new source `CRS1`
ga = GeoAxis(
    fig[1, 1];
    source=crs2,
    dest=dest,
    xticklabelsvisible=false,
    yticklabelsvisible=false,
);

@asinghvi17
Copy link
Member Author

I don't see a definition for dest here - but there are a few examples in the GeoMakie docs that should help

@alex-s-gardner
Copy link
Contributor

but there are a few examples in the GeoMakie docs that should help
I can't seem to find any example with "linked axes" for plotting multiple source CRS data on the same figure. Maybe this is not possible yet.

@rafaqz
Copy link
Member

rafaqz commented Jun 12, 2024

Ok now I read it all this is awesome! Really is something we need.

Thanks @asinghvi17 I should have written this a year ago

@asinghvi17
Copy link
Member Author

asinghvi17 commented Jun 12, 2024

hmm, the whole idea is to set the source kwarg. Something like:

using CairoMakie, GeoMakie
import GeoFormatTypes as GFT
using Interpolations # for Streamplot on gridded data if necessary

f(x::Point2{T}) where T = Point2{T}(
    10 * (2 * cos(2 * deg2rad(x[1]) + 3 * deg2rad(x[2] + 30)) ^ 2),
    20 * cos(6 * deg2rad(x[1]))
)

pole_longitude=177.5
pole_latitude=37.5
fig, ax, plt = streamplot(
    f, 311.9..391.1, -23.6..24.8;
    arrow_size = 6,
    source = "+proj=ob_tran +o_proj=latlon +o_lon_p=0 +o_lat_p=$(pole_latitude) +lon_0=$(180+pole_longitude) +to_meter=$(deg2rad(1) * 6378137.0)",
    axis = (;
        type = GeoAxis,
        title = "Streamplot",
    )
)
lp = lines!(ax, GeoMakie.coastlines(); source = GFT.EPSG(4326), linewidth = 0.5, color = :black, xautolimits = false, yautolimits = false)
translate!(lp, 0, 0, -1)
fig

https://geo.makie.org/dev/examples/cartopy/streamplot

@alex-s-gardner
Copy link
Contributor

whole idea is to set the source kwarg

Got it, thanks!

@asinghvi17
Copy link
Member Author

I guess that wasn't made clear in the GeoMakie docs. I'll add a doc page about GeoAxis, and I guess the "multiple CRS" example doesn't show it off very well :D

@alex-s-gardner
Copy link
Contributor

Are there plans to have the source crs read directly from the geometries? It seems a bit silly that we keep associating crs info to the geometries but then they're not used by GeoMakie.

Copy link
Collaborator

@skygering skygering left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it!! I think the CRS part could use a little more polishing but I am happy we have such thorough documentation!

@alex-s-gardner
Copy link
Contributor

@asinghvi17 is there a function for adding crs info to an existing geometry ... I was looking for something line setcrs

@asinghvi17
Copy link
Member Author

asinghvi17 commented Jun 13, 2024

I don't think we have anything like that yet. Probably better to just create a new geometry with the CRS, or GO.tuples(geom; crs = ...).

@alex-s-gardner
Copy link
Contributor

Stupid codespace server crashed when I was about to submit my modification... off to meetings now. I will get you something in a few hours

@rafaqz
Copy link
Member

rafaqz commented Jun 13, 2024

It would be nice to be able to rebuild any geom with crs without needing to use the right constructor.

We could make rebuild here more public, or add setcrs like Rasters has

@alex-s-gardner
Copy link
Contributor

Is it by design that GeoMakie unable to plot a Line but it can plot a LineString?

@asinghvi17
Copy link
Member Author

asinghvi17 commented Jun 13, 2024

I'm pretty sure that there was just no convert_arguments added for that on the Makie end. We could add that I guess, at least for single Lines.

How would you treat a vector of lines? Would it be continuous (as a LineString) or discontinuous (as individual linesegments)?

@alex-s-gardner
Copy link
Contributor

add setcrs like Rasters

setcrs of addcrs is more intuitive than rebuild... I don't think most people will intuitively think of adding a crs as rebuilding a geometry

@alex-s-gardner
Copy link
Contributor

How would you treat a vector of lines? Would it be continuous (as a LineString) or discontinuous (as individual linesegments)?

This is a question for @rafaqz

@alex-s-gardner
Copy link
Contributor

Moving some additional thoughts from the PR back over to Slack

@rafaqz
Copy link
Member

rafaqz commented Jun 14, 2024

I imagine given a vector of lines we should plot each one separately.

@asinghvi17
Copy link
Member Author

I just pushed some Line conversion methods to my GeoMakie PR. It's a bit inefficient, but should be fine.

Copy link
Contributor

@alex-s-gardner alex-s-gardner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's merge this PR

docs/src/tutorials/creating_geometry.md Show resolved Hide resolved
docs/src/tutorials/creating_geometry.md Show resolved Hide resolved
We don't want to apply this config all through the docs, because there are times you want full printing.
@asinghvi17
Copy link
Member Author

One last thing - I was going through this and figured we needed some anchor points, so added headers. I will merge for now, but if the headers seem unreasonable we can always change them!

Thanks a lot for the effort @alex-s-gardner (and @JuliaGeo/geometryops for the reviews :D )

@asinghvi17 asinghvi17 merged commit 0d15e9c into main Jun 14, 2024
4 checks passed
@asinghvi17 asinghvi17 deleted the as/creation_tutorial branch June 16, 2024 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants