I have a shapefile with several links that I open in matlab, that produce a structure with geometries for each line containing a cell of Xs and a cell of Ys described as follows:
geo(1,1).X = [X1 X2 ... Xn NaN]
geo(1,1).Y = [Y1 Y2 ... Yn NaN]
Then, I have some points described by (X,Y)
pairs (matrix myPoints
) for each one of which I would like to create a candidate array cand
that is simply described by a boolean, indicating that if distance from one of my points to the random line i
is less that R
then cand(i)= 1
. And of course if cand(i)== 1
then geo(i,1)
is a candidate line.
An illustrative example is presented in the following picture. As illustrated L2 can be considered as a candidate line for point with coordinates (x0,y0)
In order to define this array (or matrix in case of many points), what I do is that I use the polyxpoly
function, and I check for intersection of each line to the circle.
ii=zeros(size(Geo,1),size(myPoints,1))';
for i =1:size(myPoints,1)
[latc, lonc] = scircle1(myPoints(i,1), myPoints(i,2), km2deg(rad));
parfor j = 1:size(Geo,1)
[~, ~, index] = polyxpoly(lonc, latc, ...
Geo(j,1).X', Geo(j,1).Y');
if isempty(index)~=1
ii(i,j) =1;
end
end
end
However this take too much time even with a parfor loop; ~9 seconds for 200 points and 94 lines, which is too much only for this candidate links array, given the fact that I need to apply this for thousands of points (~5000 points per 15 minutes) and for thousands of lines (160,000 lines).
Is there any idea on what to do so that I could speed this up?
Other functions or approaches are welcomed.
Thanks