-
Notifications
You must be signed in to change notification settings - Fork 203
Closest Point of Approach #457
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
* main: remove debugging print statement (movingpandas#452)
* main: Add sphinx conf path for movingpandas#451 Up version to 0.21.3 Ensure CRS of split is correct, fixes movingpandas#455 Check if conversion is None, fixes movingpandas#454
Codecov ReportAttention: Patch coverage is
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #457 +/- ##
==========================================
+ Coverage 96.35% 96.92% +0.56%
==========================================
Files 35 37 +2
Lines 4257 5131 +874
==========================================
+ Hits 4102 4973 +871
- Misses 155 158 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Note that the coverage report says 1 line is not covered, but it is covered in the test |
movingpandas/tests/test_cpa.py
Outdated
cpa = CPACalculator(traj_a, traj_b) | ||
result = cpa.min() | ||
|
||
# we should have NaT and NaN (postgis returns time of -2) |
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.
Let's clean up the PostGIS-related comments before we finalize
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.
Thanks for the comments! I'll update the PR later this week.
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.
Removed the leftover postgis code that I used to make sure I was in line with their tests. I kept a reference at the top of the source code, for proper attribution.
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.
We'll have to ask Sandro and Paul's permission. Their code is GPL and the license would require any derivative to also be GPL https://github.com/postgis/postgis/blob/1141db62ef435f7b7d2bb4cc13766daff4fe880f/liblwgeom/lwlinearreferencing.c#L1138
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.
I suggest that I ask them the following:
Dear Sandro, Paul,
I am working on a Closest Point of Approach calculation in the python movingpandas library, a python library for moving features / trajectory calculations, by Anita Graser (cc). I have prepared an implementation based on the lwgeom's code and tests (recoded in python).
Is it ok with you if we release our code under the current BSD 3-Clause license of movingpandas?
For reference, please see the corresponding
https://github.com/movingpandas/movingpandas/issues/31
https://github.com/SiggyF/movingpandas/tree/feature/tcpa
We attribute your work as follows. Happy to adapt if requested.
In the cpa module:
# we follow the implementation of postgis
# In partical the function segments_tcpa in
# https://github.com/postgis/postgis/blob/master/liblwgeom/lwlinearreferencing.c
In the tests:
# Many tests here are based on the tests in lwgeom, cu_measures / test_lwgeom_tcpa:
# https://github.com/postgis/postgis/blob/master/liblwgeom/cunit/cu_measures.c
Kind regards,
Fedor Baart
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.
Yes, let's give it a try. Please go ahead.
(What we can definitely do, is add this functionality to Trajectools, since that is already GPL.)
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.
We discussed that we will move this code to the trajectools repository, so that it is complient with GPL license. I'll move the code there and provide the corresponding QGIS code.
I'll wrap up this PR by processing the last comments. After that I'll close it and move the code to trajectools.
A possible reuse of this branch could be from a different module as an optional dependency, like in geopandas.
Thanks for your comments. I have updated the code / documentation accordingly. I noticed that the documentation only includes the Trajectory (hardcoded in docs / api / api.rst). I'd be happy to add a few notes on this implementation in the documentation. |
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.
What do you think about adding a function to the Trajectory class that uses the CPACalculator? Similar to the existing distance functions, something like
Trajectory.get_cpa_distance(another_trajectory, units=None)
... returns the value of CPA(traj_a, traj_b).min()
Should also accept a units parameter for distance unit conversion.
Regarding documentation: yes, please add CPACalculator to the documentation Update: I've added the documentation. |
And CPACalculator should be added to https://github.com/movingpandas/movingpandas/blob/main/movingpandas/__init__.py so it can be imported like the other classes |
I would not expect the somewhat domain specific function on the general trajectory, but I'm happy to add it. I would either return
|
I added this. |
This PR will be moved to trajectools:
|
Closest Point of Approach calculator, as discussed in #31.
Code and testcases are based on the implementation from lwgeom in postgis.
A corresponding notebook in movingpandas-examples will be also prepared as PR.