1

I have a dataframe from which I created a Multipoint object:

points = MultiPoint(list(zip(dfxT['x'], dfxT['y'])))

The dfxT looks like this:

x | y | xT
2   3    1
2   15   5
2   28   6

And this is the Multipoint output:

enter image description here

And now I have a new tuple of coordinates and I want to check if they lie inside the Multipoint object and then get the x and y and retrieve the correspondant xT from the dataframe.

So basically I did this:

p = Point(10, 42)
a = points.intersection(p)

which returns nothing. I guess I am trying to see if the point is inside the multipoint and to get what I want I think I should get the closest point and .loc it on my dataframe.

So the question is: How do I get the x and y coordinates from the closest Point inside a Multipoint ?

Georgy
  • 12,464
  • 7
  • 65
  • 73
vftw
  • 1,547
  • 3
  • 22
  • 51
  • 1
    Does this answer your question? [Coordinates of the closest points of two geometries in Shapely](https://stackoverflow.com/questions/24415806/coordinates-of-the-closest-points-of-two-geometries-in-shapely) – Georgy May 16 '20 at 20:28
  • Updated with the solution! Thank you :) – vftw May 16 '20 at 22:27

1 Answers1

0

Thanks to @Georgy I was able to find a solution! Here goes:

p = Point(10, 42)
nps = nearest_points(points, p)[0]

xt_pts = np.array(nps).tolist()

Thank you!

vftw
  • 1,547
  • 3
  • 22
  • 51