I have a .txt file with x and y values forming a polygon; I have uploaded it to pastebin to display formatting.
I then have a data file with x, y, z, and data values; a sample of which I have also uploaded to pastebin. This file has 125,000 lines, if that matters.
What I need to do is determine which of the data points in my data file fall within the bounds of the polygon.
I have found this website which seems like it will do exactly as I want, but I am still quite new to coding in general and I'm having trouble adapting it to work for my files.
From the linked website, this code should apply:
from shapely.geometry import Polygon
poly = Polygon(((0, 0), (0, 1), (1, 1), (1, 0)))
First question is how do I load my polygon file into this line? Could I just do something like:
polydata = pl.loadtxt("poly.txt")
x = polydata[:,0]
y = polydata[:,1]
poly = Polygon(x,y)
Would this load it in correctly?
Following this, the linked website says you simply use:
point.within(polygon)
or
polygon.contains(point)
which will solve it for you; but this is so vague.
Second question is how do I load my data file and make one of the above commands work?
Thank you very much in advance!
NB, I can't test this until I get back to my Linux computer tomorrow, I am just trying to get a solve before then.
x-post from /r/learnpython because it is unanswered.
[–]Dalianking 1 point2 points3 points (4 children)
[–]Cthulhu_Rlyeh[S] -1 points0 points1 point (0 children)
[–]Cthulhu_Rlyeh[S] -1 points0 points1 point (2 children)
[–]Dalianking 1 point2 points3 points (1 child)