NationalSecurityAgency / qgis-shapetools-plugin

Shape Tools creates geodesic shapes and includes a number of geodesic tools for QGIS including the XY to Line tool, geodesic densify tool, geodesic line break, geodesic measure tool, geodesic measurement layer, geodesic scale, rotate and translate tool, and digitize points at an azimuth & distance tools.
GNU General Public License v2.0
157 stars 66 forks source link

XY-Lines tool produces cross-screen lines when "great-circle" lines cross international date line #17

Closed datadig2017 closed 6 years ago

datadig2017 commented 6 years ago

The XY-Line tool works great for creating "great-circle" flow map lines (those seen in air flight maps). However when the lines cross international date line, they seem to extend across the entire canvas. Anita Graser [Underdark] also noted this in her blog (https://anitagraser.com/2011/08/20/visualizing-global-connections/) but she didn't give an answer/solution. great circle cross intl date line

datadig2017 commented 6 years ago

Sorry I didn't specify my environment: Windows 7 Professional, 64 bit, QGIS 2.18; I will try to upgrade to QGIS 3.x to see if this would be corrected. Thanks!

hamiltoncj commented 6 years ago

This is an overall problem with how QGIS handles objects drawn across the international date line. It is not caused by shape tools. Several years ago I put in a bug fix request for this, but nothing ever happened. I think it is a hard problem to solve. The only way that I know of to fix this would be to break lines that cross the date line into two pieces. I don't know if the libraries I am using has a routine that tells when the line intersects the date line or not, but I will investigate it.

datadig2017 commented 6 years ago

Thanks for following up! I understand that this is a tough ball. I compile this kind of map for work and there is quite a few instances of connections between Fiji, Samoa, Tonga, Vanuatu, Australia, etc. Once I remove those, the lines look good. I wonder if the "great circle" mechanism within "Shape Tools" would first measure the distance and the direction for each line and decide if it crosses the IDL. If it does, the algorithm would implement a "complementary" arc. For example, the connection from Fiji to Samoa crosses the IDL, according to the current rendition. If using the reverse direction, it is just a tiny short distance. Anyway, no big deal. I can always manually flip those connections from my source CSV file before importing into QGIS. "Shape Tools" is a great tool! Many thanks!!

hamiltoncj commented 6 years ago

I'm working on a solution which will break the line at the -180, 180 boundary and continue drawing it. Unfortunately, geographiclib does not have a function to detect the intersection of a line crossing another line and it is quite complicated at least for me. There is one algorithm that I have found and am in the process of implementing it. It might take a few days before I complete the update and get it out.

datadig2017 commented 6 years ago

Happy to share my CSV file for your testing! Let me know. Thanks!

hamiltoncj commented 6 years ago

That would be helpful. Thanks.

datadig2017 commented 6 years ago

test.tools.github.xlsx

Here is the Excel file. Surprised that Github doesn't take CSV format. The column headings are self-explanatory. Pay attention to lines originating from FJI, WSM and/or ending in FJI WSM VUT. Those small islands are in the vicinity of IDL.

Again, many thanks for working on this great tool!

datadig2017 commented 6 years ago

test.tools.github.xlsx Hi I realized that the previous file shared doesn't have connections that cross the IDL. I have already removed them. I am sharing again with this version where there are connections that cross IDL. Sorry for the confusion.

hamiltoncj commented 6 years ago

@datadig2017 I just release Shape Tools 3.0.9 for QGIS 3. The XY to Line tool now has an option to "Break lines at -180, 180 boundary..." Be sure to enable it. It worked properly on the data set you sent me so give it a try and let me know how it goes.

datadig2017 commented 6 years ago

Thank you so much for updating the tool! Can't wait to test it. Let me update to QGIS 3 first. Will let you know the test results soon.

datadig2017 commented 6 years ago

@hamiltoncj Thanks again for updating the tool. The additional option of "Break lines at -180, 180..." works well in rendering long lines (regardless of crossing IDL or not). A few quick observations:

Let me know if you need screenshots. I don't want to overwhelm you with screenshots. Hopefully my description above is clear.

hamiltoncj commented 6 years ago

Item 1 - I don't understand why something is not right. Are you sure you don't have any that cross the IDL. You could also try it in QGIS 2. It can also look funny crossing over the poles depending on the projection you are using.

Item 2 - By making XY to Lines a processing routine I get a number of advantages; however, some things are not as flexible. By default it is using the CRS of the QGIS project which I suspect is 3857. I couldn't find a way to make it just use the Layer CRS. I could however have it default to 4326. Since I am often using 3857 it has been a little annoying for me as well. What do you think? Should the default be 4326?

Item 3 - If the CRS is not correct then the points will not be in the right place. They may be what is happening. Do you think the output point layer should be enabled by default as a temporary layer?

hamiltoncj commented 6 years ago

I see the problem for #3. I will fix it.

datadig2017 commented 6 years ago

Interesting... Item 1 - Enabling the "break lines" option works great anyway. I will always check it so there is no problem. Item 2 - Would be good to default to 4326 (or 3857) just for convenience. It doesn't matter though. I can always manually select 4326. Item 3 - Yes, please default the output point layer as temporary layer instead of [skip output], especially when "show starting point" and "show ending point" are by default selected. Previously the output point layer was fine and I saved it. Screenshot below shows it is CRS 4326, the same as specified output layer CRS. saved output point

Not sure what changed in this version that "blanked" the output point layer. Could you test?

datadig2017 commented 6 years ago

Our posts crossed each other. Great that you sorted out problem 3. Thanks as always!

hamiltoncj commented 6 years ago

I just released 3.0.10. It may take a few minutes for plugins.qgis.org to update their listing. Usually it is not more than about 15 minutes. I have made EPSG:4326 the default and the beginning and ending points output file enabled by default. Once you can update, let me know how it works out for you.

datadig2017 commented 6 years ago

Sure. Thanks!

hamiltoncj commented 6 years ago

I updated the QGIS 2 plugin with this fix. It is version 0.7.9

datadig2017 commented 6 years ago

Hi version 3.0.10 works great! The output point layer functions smoothly. Kudos! Many thanks!

hamiltoncj commented 6 years ago

@datadig2017 I am going to close this out, but wanted to make you aware that I found a bug XY to Line. It is fixed in 3.1.0. Also I created a separate routine to break the lines. If there are any other issues please let me know.

datadig2017 commented 6 years ago

Thx @hamiltoncj! I’m on leave now. Will test the new version when back in September! Cheers!