-
Notifications
You must be signed in to change notification settings - Fork 404
Let gmtspatial -W extend segments from one of both ends #6255
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
Conversation
This PR follows the comments on the forum post and adds a new -W option that is used to extend existing lines in one or both directions by a given amount. A test has been added and the documentation has been updated.
Esteban82
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Many thanks Paul!!
|
Just a doubt. I add a header in |
|
OK, will have a look. |
|
Hm, I added both a header ( Usually headers are not preserved on output. Adding -h gives What is it that is not working for you? |
|
Ok, sorry. Perfect. |
| } | ||
| #endif | ||
|
|
||
| if (Ctrl->W.active) { /* Calculate centroid and polygon areas or line lengths and place in segment headers */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this comment correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hope not!
|
Would be better to slow down a bit the merging step. A couple of things.
|
|
Those are good points, @joa-quim . I think @Esteban82 was eager to try this for his work. I guess a good general guideline is to let the one who opened the PR get to close it since that person may discover minor stuff that should be added to the PR before merging. |
|
I have fixed the dumb copy/paste comment and added explanation to the docs that the geographic calculations are spherical. I could code up Karney 2012 but this is already in proj and/or GDAL so we could add this as needed. It makes no difference for short extensions but will show up for long extensions. As for the azimuthal options. If these are sensible and useful they can be added. I did think of azimuths but best fit on a sphere is what fitcircle does for instance, but it does not report azimuths so we would have to add some coding here. And again this is pseudo-elliptical (authalic parameters for a sphere). For discussion, I can imagine the new modifier +a[azim[/azim2]] where +a (no args) means determine azimuth from best fit great/small circle (or least-squares line for Cartesian), +aazim means use that azimuth at either end (of the ends selected if +f|l is used) and +aazimf/asiml for separate azimuths. Note that for long lines and lines close to poles the single azimuth option would give very different results at either end. Might it be useful to have modifiers for adding a deviation to the selected azimuth? E.g., +a+d10/5 would add 10 degrees to the azimuth at start and 5 at the end? |
Seems adding too much complexity to syntax for very little optional gain.
Yes, it's in proj and that's what I used in my Julia example. I think using proj would have been better as it gives ellipsoidal instead of spherical. And about this I made a little test this morning that shows that you are using the azimuth at the start instead of end point. I'm 100% clear on this but I think we should use the azimuth at the end point. and the GMT solution |
|
Yet another useful option would be +nndists to turn the dist into an increment and thus compute points along the line ... which at the end corresponds to compute a chunk of a great circle, so perhaps there are better ways to do that. |
|
Perhaps let that happen in project -G instead. I will check the azimuths, the intent was to get the azimuth at the end points pointing outwards. |
|
Here is the result for geodesic (Vicenty): So for the end point this differs from your Kerney solution by 1.6e-13 in longitude and 2e-14 in latitude, i.e., ~9 nm. However, at the first point I get 25 meters difference, so we need to resolve this. I am doing this:
Code says: I think this is right, no? Note that my row indices above is after I have added the blank rows and start and end, so the two input points are at index 1 and 2, and also n-3 and n-2 (since n = 4). |
|
What I do is to use So it seems the same procedure. But 20-40 differences is what I found when comparing the effect of using Note, you can use the |
|
Note that usually the azimuths at one end + 180 is not the same as at the other end: -142.501966107 ~= -142.618253299 |
|
Note: As the two points converge this difference goes to zero of course, but since the line segment is finite and a small section of the great circle (or geodesic), the azimuth is a continuous function along the geodesic and cannot be the same at two different points. |
|
I know. I'm adding 180 when it gives the |
|
So I think my implementation is correct. The |
|
In fact I'm not adding any 180 when using Julia because what the |
|
OK, take that example. What I do is |
|
Please do the case for the line (0,60) - (30,85) [two points with 100k extension at either ends so it is easier to check for crazy results. I can then compare |
|
You are right - I need to flip the calls in gmtspatial. The az_backaz function is OK but I was using it wrong and the extend.sh test was too tiny distances to tell. |
|
Ok but since I did (in Julia because the geod cli (you also have it) is very boring) |
This PR follows the comments on the forum post and adds a new -W option that is used to extend existing lines in one or both directions by a given amount(s). A test has been added to show how it works for geographic and Cartesian settings, and the documentation has been updated. Here is the test output: