I have about 30,000 pairs of longitude and latitude data (lon1 and lon2). My goal is to check if they will fall into a polygon defined by (lonW and latW).
In Matlab, I can do this as below. It is blazing fast. It literally takes no time to finish. in = inpolygon(lon1, lat1, lonW, latW);
Below is how I’m doing it in Julia.
using PolygonOps
using StaticArrays
polygon = SVector.(lonW, latW);
in = [inpolygon((x, y), polygon; in=true, on=false, out=false) for x in lon1, y in lat1];
It will take forever to finish. In fact I’m never able to wait long enough for it to complete.It will make my computer to run very hot and noisy. As you know, this is not normal. Julia is supposed to be faster than Matlab. Anyone knows a faster way to process this in Julia? Many thanks.
I mean, by analyzing the points separately, you can maybe reduce the problem?
Also, if the polygon is convex you can exclude many, many points (convex hull, etc.)
Point in polygons is actually a pretty old and famous problem so I wouldn’t wonder if Matlab has sophisticated algorithms for that.