-
Notifications
You must be signed in to change notification settings - Fork 10
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
Add method for finding neighoring points and lines #15
Comments
The provided code runs nicely on my computer and gives reasonable output as far as I can see. I have some code that I use to find points near lines that do not need the One thing to discuss is whether the coordinates should be provided as latitude/longitude or as a in a projected coordinate in a reference grid? |
That is a good point. With Because of that, I would suggest to enforce projecting to length-preserving (or something that comes close) local coordinates. We could also enforce/suggest tot store these as The user should of course be able to choose which projection to use, but we could provide some sane defaults. Naming and storing the projected coordinates needs to be synchronized with the WG1 data format conventions. We could also add the functionality that the distance calculations always project the data before doing the actual calculation. We have to be careful to not hide too much magic with our functions. Maybe something like this could be a compromise: def get_gauge_distance_per_cml(ds_cmls, ds_gauges, project_coordinates_to=None):
# Check if ds_cmls.site_0_x etc... and ds_gauges.x and y exist
# If not check if project_coordinates_to is a valid EPSG string
# If not, raise Error
# If yes, project data
# If yes, proceed
# calculate distance using x and y cooridnates But then we have to handle the case where one of Maybe it is easier to do something like ds_cmls = add_projected_coordinates_from_lon_lat(ds_cmls, projection=`some_EPSG_string`)
get_gauge_distance_per_cml(...) # This raises an error if x and y are not there We would need to check if |
Note that See:
For very large number of sensors, above 10,000, the distance matrix calculation gets pretty slow (something like 30 sec for 10,000 sensors against themselfs, if I recall correctly) and this scales quadratically (I guess...). Hence we might also want to provide the option to calculat nearest neighbors with |
There are several ways to calculate the distance between points and points and lines available. I tested some of them and here are the findings. I tested the distance calculation between the following DWD stations available here. Abenberg_4 10.9667 49.2346
From this first testing I think |
Thanks @maxmargraf for doing this comparison and for the summary. Even though In general, I think, our main limitation is that we need Or did you test something else than |
No, please note that |
Okay. So for point-to-line or line-to-line we have the two options
If so, I prefer 2. |
Based on discussion on site, it might more important to focus on functions that get the nearest neighbors instead of a full distance matrix (even if it is a sparse distance matrix, see #37). |
UPDATE of status of implementation:
Is your feature request related to a problem? Please describe.
We need a unified way of finding neighboring sensors, both from points and lines, and a mixture of both.
Describe the solution you'd like
There is an implementation for line-to-point neighbor lookup using
shapely
here in the prototype that I built some time ago. For line-to-line this is IMO the most solid implementation. It can also be used for line-to-line distance calculations.For point-to-point we could use functions from
scipy.spatial
, but since we already haveshapely
as dependency, this might not be needed. Most likely thescipy
functions will be much faster since they are limited to one specific use case, point-to-point distance calculation, whereasshapely
works with all its supported geometries.Hence, currently I would prefer using
shapely
for line-to-line and line-to-point distance calculation and probablyscipy
for point-to-point.There could/should (?) be a general interface to do these calculations. Maybe a good solutions would be a. ABC class, but maybe the added complexity is not worth it and it is better to use separate functions, e.g.
calc_line_to_point_distances(ds_lines, ds_points)
.Describe alternatives you've considered
There might be code for line-to-point distance calculations because several people (maybe from @eoydvin or @maxmargraf ?) have used that to find gauges close to CMLs. Hence, we can collect and discuss these implementations and see if we do not need
shapely
for the line-to-point distances. However, we will needshapely
as a dependency if we stick with the fast and tested grid intersection code frompycomlink
to be implemented in #5.The text was updated successfully, but these errors were encountered: