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

Accuracy issue with nearestPoints method #202

Open
chamikabm opened this issue Mar 5, 2024 · 2 comments
Open

Accuracy issue with nearestPoints method #202

chamikabm opened this issue Mar 5, 2024 · 2 comments

Comments

@chamikabm
Copy link

chamikabm commented Mar 5, 2024

I have a line string as follows, consisting of a few points (longitude/latitude) coordinates in Paris. I tried to find the closest snapped point on the given line and from a give-point

line_string = [
			[
				145.0296835,
				-37.8089915
			],
			[
				145.0297712,
				-37.809002
			],
			[
				145.0298903,
				-37.8090163
			],
			[
				145.0303226,
				-37.8090682
			],
			[
				145.0304063,
				-37.8090783
			],
			[
				145.0313321,
				-37.8091894
			],
			[
				145.0322665,
				-37.8093016
			],
			[
				145.032952,
				-37.8093839
			],
			[
				145.033411,
				-37.809439
			],
			[
				145.0336591,
				-37.8094688
			],
			[
				145.0337068,
				-37.8094745
			],
			[
				145.0348664,
				-37.8096137
			],
			[
				145.0349955,
				-37.8096292
			]
		]

given_point = [
   145.03317585555192,
    -37.809289649922064
]

I’m using the LibGEOS library to do this as follows, but here’s the thing: visually, it looks like the point is snapping to the closest spot, but when I check with the intersect method using the same library, it turns out it’s not lining up with the provided line:

geos_point = LibGEOS.Point(given_point[1], given_point[2])
geos_line_string = LibGEOS.LineString(line_string)
point_on_linestring, point_on_point = LibGEOS.nearestPoints(geos_line_string, geos_point)
nearest_point = [ LibGEOS.getGeomX(point_on_linestring), LibGEOS.getGeomY(point_on_linestring) ]

But when I check the nearest point:

LibGEOS.intersects(nearest_point, geos_line_string) ==> False

Output of the above function gives as false, but If I input a point in the line_string separately, then it gives me true as follows:

point_in_the_line_string = LibGEOS.Point(145.0349955,-37.8096292)

LibGEOS.intersects(point_in_the_line_string, geos_line_string) ==> True

image

@jaakkor2
Copy link
Contributor

As points are Float64, I would buffer the line a bit

LibGEOS.intersects(nearest_point, buffer(geos_line_string,1e-12))  # true

@chamikabm
Copy link
Author

@jaakkor2 , Checking with a buffer would work, but what I wanna know, is what would be the most accurate way to create such a snapped point?

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

No branches or pull requests

2 participants